Commit 7d32cf4e authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[cleanup] Clean up CodeReference class

This CL fixes the new {CodeReference} class to comply to the style
guide. It makes it a proper class, renames private fields to end in an
underscore and simplifies the union declaration.

R=ahaas@chromium.org
CC=herhut@chromium.org

Bug: v8:7570
Change-Id: I329bbc6fca1ba3c0cb34fb4e1179eb4fa9044e76
Reviewed-on: https://chromium-review.googlesource.com/1023414Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52722}
parent ba020627
...@@ -12,41 +12,41 @@ namespace v8 { ...@@ -12,41 +12,41 @@ namespace v8 {
namespace internal { namespace internal {
Address CodeReference::constant_pool() const { Address CodeReference::constant_pool() const {
return kind == JS ? code.js->constant_pool() : code.wasm->constant_pool(); return kind_ == JS ? js_code_->constant_pool() : wasm_code_->constant_pool();
} }
Address CodeReference::instruction_start() const { Address CodeReference::instruction_start() const {
return kind == JS return kind_ == JS
? code.js->InstructionStart() ? js_code_->InstructionStart()
: reinterpret_cast<Address>(code.wasm->instructions().start()); : reinterpret_cast<Address>(wasm_code_->instructions().start());
} }
Address CodeReference::instruction_end() const { Address CodeReference::instruction_end() const {
return kind == JS return kind_ == JS
? code.js->InstructionEnd() ? js_code_->InstructionEnd()
: reinterpret_cast<Address>(code.wasm->instructions().start() + : reinterpret_cast<Address>(wasm_code_->instructions().start() +
code.wasm->instructions().size()); wasm_code_->instructions().size());
} }
int CodeReference::instruction_size() const { int CodeReference::instruction_size() const {
return kind == JS ? code.js->InstructionSize() return kind_ == JS ? js_code_->InstructionSize()
: code.wasm->instructions().length(); : wasm_code_->instructions().length();
} }
const byte* CodeReference::relocation_start() const { const byte* CodeReference::relocation_start() const {
return kind == JS ? code.js->relocation_start() return kind_ == JS ? js_code_->relocation_start()
: code.wasm->reloc_info().start(); : wasm_code_->reloc_info().start();
} }
const byte* CodeReference::relocation_end() const { const byte* CodeReference::relocation_end() const {
return kind == JS ? code.js->relocation_end() return kind_ == JS ? js_code_->relocation_end()
: code.wasm->reloc_info().start() + : wasm_code_->reloc_info().start() +
code.wasm->reloc_info().length(); wasm_code_->reloc_info().length();
} }
int CodeReference::relocation_size() const { int CodeReference::relocation_size() const {
return kind == JS ? code.js->relocation_size() return kind_ == JS ? js_code_->relocation_size()
: code.wasm->reloc_info().length(); : wasm_code_->reloc_info().length();
} }
} // namespace internal } // namespace internal
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define V8_CODE_REFERENCE_H_ #define V8_CODE_REFERENCE_H_
#include "src/handles.h" #include "src/handles.h"
#include "src/objects.h" #include "src/objects/code.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -17,10 +17,12 @@ namespace wasm { ...@@ -17,10 +17,12 @@ namespace wasm {
class WasmCode; class WasmCode;
} }
struct CodeReference { class CodeReference {
explicit CodeReference(const wasm::WasmCode* wasm_code = nullptr) public:
: kind(WASM), code(wasm_code) {} CodeReference() : kind_(JS), js_code_() {}
explicit CodeReference(Handle<Code> js_code) : kind(JS), code(js_code) {} explicit CodeReference(const wasm::WasmCode* wasm_code)
: kind_(WASM), wasm_code_(wasm_code) {}
explicit CodeReference(Handle<Code> js_code) : kind_(JS), js_code_(js_code) {}
Address constant_pool() const; Address constant_pool() const;
Address instruction_start() const; Address instruction_start() const;
...@@ -30,22 +32,19 @@ struct CodeReference { ...@@ -30,22 +32,19 @@ struct CodeReference {
const byte* relocation_end() const; const byte* relocation_end() const;
int relocation_size() const; int relocation_size() const;
bool is_null() const { bool is_null() const {
return kind == JS ? code.js.is_null() : code.wasm == nullptr; return kind_ == JS ? js_code_.is_null() : wasm_code_ == nullptr;
} }
private: private:
enum { JS, WASM } kind; enum { JS, WASM } kind_;
union CodeUnion { union {
explicit CodeUnion(Handle<Code> js_code) : js(js_code) {} const wasm::WasmCode* wasm_code_;
explicit CodeUnion(const wasm::WasmCode* wasm_code) : wasm(wasm_code) {} Handle<Code> js_code_;
CodeUnion() : wasm(nullptr) {} };
const wasm::WasmCode* wasm; DISALLOW_NEW_AND_DELETE();
Handle<Code> js;
} code;
DISALLOW_NEW_AND_DELETE()
}; };
ASSERT_TRIVIALLY_COPYABLE(CodeReference);
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment