• 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 #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:
CodeReference()22   CodeReference() : kind_(JS), js_code_() {}
CodeReference(const wasm::WasmCode * wasm_code)23   explicit CodeReference(const wasm::WasmCode* wasm_code)
24       : kind_(WASM), wasm_code_(wasm_code) {}
CodeReference(Handle<Code> js_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;
is_null()34   bool is_null() const {
35     return kind_ == JS ? js_code_.is_null() : wasm_code_ == nullptr;
36   }
37 
as_js_code()38   Handle<Code> as_js_code() const {
39     DCHECK_EQ(JS, kind_);
40     return js_code_;
41   }
42 
as_wasm_code()43   const wasm::WasmCode* as_wasm_code() const {
44     DCHECK_EQ(WASM, kind_);
45     return wasm_code_;
46   }
47 
48  private:
49   enum { JS, WASM } kind_;
50   union {
51     const wasm::WasmCode* wasm_code_;
52     Handle<Code> js_code_;
53   };
54 
55   DISALLOW_NEW_AND_DELETE();
56 };
57 ASSERT_TRIVIALLY_COPYABLE(CodeReference);
58 
59 }  // namespace internal
60 }  // namespace v8
61 
62 #endif  // V8_CODE_REFERENCE_H_
63