code-reference.h 1.74 KB
Newer Older
1 2 3 4
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_CODEGEN_CODE_REFERENCE_H_
#define V8_CODEGEN_CODE_REFERENCE_H_
7

8
#include "src/handles/handles.h"
9
#include "src/objects/code.h"
10 11 12 13 14

namespace v8 {
namespace internal {

class Code;
15
class CodeDesc;
16 17 18 19 20

namespace wasm {
class WasmCode;
}

21 22
class CodeReference {
 public:
23
  CodeReference() : kind_(NONE), null_(nullptr) {}
24 25
  explicit CodeReference(const wasm::WasmCode* wasm_code)
      : kind_(WASM), wasm_code_(wasm_code) {}
26 27
  explicit CodeReference(const CodeDesc* code_desc)
      : kind_(CODE_DESC), code_desc_(code_desc) {}
28
  explicit CodeReference(Handle<Code> js_code) : kind_(JS), js_code_(js_code) {}
29 30 31 32 33 34 35 36

  Address constant_pool() const;
  Address instruction_start() const;
  Address instruction_end() const;
  int instruction_size() const;
  const byte* relocation_start() const;
  const byte* relocation_end() const;
  int relocation_size() const;
37
  Address code_comments() const;
38
  int code_comments_size() const;
39 40 41 42

  bool is_null() const { return kind_ == NONE; }
  bool is_js() const { return kind_ == JS; }
  bool is_wasm_code() const { return kind_ == WASM; }
43

44
  Handle<Code> as_js_code() const {
45
    DCHECK_EQ(JS, kind_);
46 47 48 49
    return js_code_;
  }

  const wasm::WasmCode* as_wasm_code() const {
50
    DCHECK_EQ(WASM, kind_);
51 52 53
    return wasm_code_;
  }

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 61
    Handle<Code> js_code_;
  };
62

63
  DISALLOW_NEW_AND_DELETE()
64
};
65
ASSERT_TRIVIALLY_COPYABLE(CodeReference);
66 67 68 69

}  // namespace internal
}  // namespace v8

70
#endif  // V8_CODEGEN_CODE_REFERENCE_H_