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 : #ifndef V8_CODE_REFERENCE_H_
6 : #define V8_CODE_REFERENCE_H_
7 :
8 : #include "src/handles.h"
9 : #include "src/objects/code.h"
10 :
11 : namespace v8 {
12 : namespace internal {
13 :
14 : class Code;
15 : class CodeDesc;
16 :
17 : namespace wasm {
18 : class WasmCode;
19 : }
20 :
21 : class CodeReference {
22 : public:
23 0 : CodeReference() : kind_(NONE), null_(nullptr) {}
24 : explicit CodeReference(const wasm::WasmCode* wasm_code)
25 : : kind_(WASM), wasm_code_(wasm_code) {}
26 : explicit CodeReference(const CodeDesc* code_desc)
27 : : kind_(CODE_DESC), code_desc_(code_desc) {}
28 : explicit CodeReference(Handle<Code> js_code) : kind_(JS), js_code_(js_code) {}
29 :
30 : Address constant_pool() const;
31 : Address instruction_start() const;
32 : Address instruction_end() const;
33 : int instruction_size() const;
34 : const byte* relocation_start() const;
35 : const byte* relocation_end() const;
36 : int relocation_size() const;
37 : Address code_comments() const;
38 : int code_comments_size() const;
39 :
40 : bool is_null() const { return kind_ == NONE; }
41 : bool is_js() const { return kind_ == JS; }
42 : bool is_wasm_code() const { return kind_ == WASM; }
43 :
44 : Handle<Code> as_js_code() const {
45 : DCHECK_EQ(JS, kind_);
46 : return js_code_;
47 : }
48 :
49 : const wasm::WasmCode* as_wasm_code() const {
50 : DCHECK_EQ(WASM, kind_);
51 : return wasm_code_;
52 : }
53 :
54 : private:
55 : enum { NONE, JS, WASM, CODE_DESC } kind_;
56 : union {
57 : std::nullptr_t null_;
58 : const wasm::WasmCode* wasm_code_;
59 : const CodeDesc* code_desc_;
60 : Handle<Code> js_code_;
61 : };
62 :
63 : DISALLOW_NEW_AND_DELETE()
64 : };
65 : ASSERT_TRIVIALLY_COPYABLE(CodeReference);
66 :
67 : } // namespace internal
68 : } // namespace v8
69 :
70 : #endif // V8_CODE_REFERENCE_H_
|