Line data Source code
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/code-reference.h"
6 :
7 : #include "src/code-desc.h"
8 : #include "src/globals.h"
9 : #include "src/handles-inl.h"
10 : #include "src/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 :
20 0 : Address constant_pool() const { return code->constant_pool(); }
21 0 : Address instruction_start() const { return code->InstructionStart(); }
22 0 : Address instruction_end() const { return code->InstructionEnd(); }
23 0 : int instruction_size() const { return code->InstructionSize(); }
24 : const byte* relocation_start() const { return code->relocation_start(); }
25 : const byte* relocation_end() const { return code->relocation_end(); }
26 : int relocation_size() const { return code->relocation_size(); }
27 0 : Address code_comments() const { return code->code_comments(); }
28 0 : int code_comments_size() const { return code->code_comments_size(); }
29 : };
30 :
31 : struct WasmOps {
32 : const wasm::WasmCode* code;
33 :
34 0 : Address constant_pool() const { return code->constant_pool(); }
35 : Address instruction_start() const {
36 0 : return reinterpret_cast<Address>(code->instructions().start());
37 : }
38 : Address instruction_end() const {
39 0 : return reinterpret_cast<Address>(code->instructions().start() +
40 0 : code->instructions().size());
41 : }
42 : int instruction_size() const { return code->instructions().length(); }
43 : const byte* relocation_start() const { return code->reloc_info().start(); }
44 : const byte* relocation_end() const {
45 0 : return code->reloc_info().start() + code->reloc_info().length();
46 : }
47 : int relocation_size() const { return code->reloc_info().length(); }
48 0 : Address code_comments() const { return code->code_comments(); }
49 0 : int code_comments_size() const { return code->code_comments_size(); }
50 : };
51 :
52 : struct CodeDescOps {
53 : const CodeDesc* code_desc;
54 :
55 : Address constant_pool() const {
56 0 : return instruction_start() + code_desc->constant_pool_offset;
57 : }
58 : Address instruction_start() const {
59 0 : return reinterpret_cast<Address>(code_desc->buffer);
60 : }
61 : Address instruction_end() const {
62 0 : return instruction_start() + code_desc->instr_size;
63 : }
64 0 : int instruction_size() const { return code_desc->instr_size; }
65 : const byte* relocation_start() const {
66 0 : return code_desc->buffer + code_desc->reloc_offset;
67 : }
68 : const byte* relocation_end() const {
69 0 : return code_desc->buffer + code_desc->buffer_size;
70 : }
71 0 : int relocation_size() const { return code_desc->reloc_size; }
72 : Address code_comments() const {
73 0 : return instruction_start() + code_desc->code_comments_offset;
74 : }
75 0 : 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 0 : DISPATCH(Address, constant_pool)
95 0 : DISPATCH(Address, instruction_start)
96 0 : DISPATCH(Address, instruction_end)
97 0 : DISPATCH(int, instruction_size)
98 0 : DISPATCH(const byte*, relocation_start)
99 0 : DISPATCH(const byte*, relocation_end)
100 0 : DISPATCH(int, relocation_size)
101 0 : DISPATCH(Address, code_comments)
102 0 : DISPATCH(int, code_comments_size)
103 :
104 : #undef DISPATCH
105 :
106 : } // namespace internal
107 122036 : } // namespace v8
|