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 :
16 : namespace wasm {
17 : class WasmCode;
18 : }
19 :
20 : class CodeReference {
21 : public:
22 0 : CodeReference() : kind_(JS), js_code_() {}
23 : explicit CodeReference(const wasm::WasmCode* wasm_code)
24 : : kind_(WASM), wasm_code_(wasm_code) {}
25 : explicit CodeReference(Handle<Code> js_code) : kind_(JS), js_code_(js_code) {}
26 :
27 : Address constant_pool() const;
28 : Address instruction_start() const;
29 : Address instruction_end() const;
30 : int instruction_size() const;
31 : const byte* relocation_start() const;
32 : const byte* relocation_end() const;
33 : int relocation_size() const;
34 : Address code_comments() const;
35 : bool is_null() const {
36 : return kind_ == JS ? js_code_.is_null() : wasm_code_ == nullptr;
37 : }
38 :
39 : Handle<Code> as_js_code() const {
40 : DCHECK_EQ(JS, kind_);
41 : return js_code_;
42 : }
43 :
44 : const wasm::WasmCode* as_wasm_code() const {
45 : DCHECK_EQ(WASM, kind_);
46 : return wasm_code_;
47 : }
48 :
49 : private:
50 : enum { JS, WASM } kind_;
51 : union {
52 : const wasm::WasmCode* wasm_code_;
53 : Handle<Code> js_code_;
54 : };
55 :
56 : DISALLOW_NEW_AND_DELETE();
57 : };
58 : ASSERT_TRIVIALLY_COPYABLE(CodeReference);
59 :
60 : } // namespace internal
61 : } // namespace v8
62 :
63 : #endif // V8_CODE_REFERENCE_H_
|