• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/codegen/code-reference.h"
6 
7 #include "src/codegen/code-desc.h"
8 #include "src/common/globals.h"
9 #include "src/handles/handles-inl.h"
10 #include "src/objects/objects-inl.h"
11 #include "src/wasm/wasm-code-manager.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 namespace {
17 struct JSOps {
18   Handle<Code> code;
19 
constant_poolv8::internal::__anon5ea5deff0111::JSOps20   Address constant_pool() const { return code->constant_pool(); }
instruction_startv8::internal::__anon5ea5deff0111::JSOps21   Address instruction_start() const { return code->InstructionStart(); }
instruction_endv8::internal::__anon5ea5deff0111::JSOps22   Address instruction_end() const { return code->InstructionEnd(); }
instruction_sizev8::internal::__anon5ea5deff0111::JSOps23   int instruction_size() const { return code->InstructionSize(); }
relocation_startv8::internal::__anon5ea5deff0111::JSOps24   const byte* relocation_start() const { return code->relocation_start(); }
relocation_endv8::internal::__anon5ea5deff0111::JSOps25   const byte* relocation_end() const { return code->relocation_end(); }
relocation_sizev8::internal::__anon5ea5deff0111::JSOps26   int relocation_size() const { return code->relocation_size(); }
code_commentsv8::internal::__anon5ea5deff0111::JSOps27   Address code_comments() const { return code->code_comments(); }
code_comments_sizev8::internal::__anon5ea5deff0111::JSOps28   int code_comments_size() const { return code->code_comments_size(); }
29 };
30 
31 struct WasmOps {
32   const wasm::WasmCode* code;
33 
constant_poolv8::internal::__anon5ea5deff0111::WasmOps34   Address constant_pool() const { return code->constant_pool(); }
instruction_startv8::internal::__anon5ea5deff0111::WasmOps35   Address instruction_start() const {
36     return reinterpret_cast<Address>(code->instructions().begin());
37   }
instruction_endv8::internal::__anon5ea5deff0111::WasmOps38   Address instruction_end() const {
39     return reinterpret_cast<Address>(code->instructions().begin() +
40                                      code->instructions().size());
41   }
instruction_sizev8::internal::__anon5ea5deff0111::WasmOps42   int instruction_size() const { return code->instructions().length(); }
relocation_startv8::internal::__anon5ea5deff0111::WasmOps43   const byte* relocation_start() const { return code->reloc_info().begin(); }
relocation_endv8::internal::__anon5ea5deff0111::WasmOps44   const byte* relocation_end() const {
45     return code->reloc_info().begin() + code->reloc_info().length();
46   }
relocation_sizev8::internal::__anon5ea5deff0111::WasmOps47   int relocation_size() const { return code->reloc_info().length(); }
code_commentsv8::internal::__anon5ea5deff0111::WasmOps48   Address code_comments() const { return code->code_comments(); }
code_comments_sizev8::internal::__anon5ea5deff0111::WasmOps49   int code_comments_size() const { return code->code_comments_size(); }
50 };
51 
52 struct CodeDescOps {
53   const CodeDesc* code_desc;
54 
constant_poolv8::internal::__anon5ea5deff0111::CodeDescOps55   Address constant_pool() const {
56     return instruction_start() + code_desc->constant_pool_offset;
57   }
instruction_startv8::internal::__anon5ea5deff0111::CodeDescOps58   Address instruction_start() const {
59     return reinterpret_cast<Address>(code_desc->buffer);
60   }
instruction_endv8::internal::__anon5ea5deff0111::CodeDescOps61   Address instruction_end() const {
62     return instruction_start() + code_desc->instr_size;
63   }
instruction_sizev8::internal::__anon5ea5deff0111::CodeDescOps64   int instruction_size() const { return code_desc->instr_size; }
relocation_startv8::internal::__anon5ea5deff0111::CodeDescOps65   const byte* relocation_start() const {
66     return code_desc->buffer + code_desc->reloc_offset;
67   }
relocation_endv8::internal::__anon5ea5deff0111::CodeDescOps68   const byte* relocation_end() const {
69     return code_desc->buffer + code_desc->buffer_size;
70   }
relocation_sizev8::internal::__anon5ea5deff0111::CodeDescOps71   int relocation_size() const { return code_desc->reloc_size; }
code_commentsv8::internal::__anon5ea5deff0111::CodeDescOps72   Address code_comments() const {
73     return instruction_start() + code_desc->code_comments_offset;
74   }
code_comments_sizev8::internal::__anon5ea5deff0111::CodeDescOps75   int code_comments_size() const { return code_desc->code_comments_size; }
76 };
77 }  // namespace
78 
79 #define DISPATCH(ret, method)                    \
80   ret CodeReference::method() const {            \
81     DCHECK(!is_null());                          \
82     switch (kind_) {                             \
83       case JS:                                   \
84         return JSOps{js_code_}.method();         \
85       case WASM:                                 \
86         return WasmOps{wasm_code_}.method();     \
87       case CODE_DESC:                            \
88         return CodeDescOps{code_desc_}.method(); \
89       default:                                   \
90         UNREACHABLE();                           \
91     }                                            \
92   }
93 
94 DISPATCH(Address, constant_pool)
95 DISPATCH(Address, instruction_start)
96 DISPATCH(Address, instruction_end)
97 DISPATCH(int, instruction_size)
98 DISPATCH(const byte*, relocation_start)
99 DISPATCH(const byte*, relocation_end)
100 DISPATCH(int, relocation_size)
101 DISPATCH(Address, code_comments)
102 DISPATCH(int, code_comments_size)
103 
104 #undef DISPATCH
105 
106 }  // namespace internal
107 }  // namespace v8
108