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 {
namespace internal {
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 {
return kind == JS
? code.js->InstructionStart()
: reinterpret_cast<Address>(code.wasm->instructions().start());
return kind_ == JS
? js_code_->InstructionStart()
: reinterpret_cast<Address>(wasm_code_->instructions().start());
}
Address CodeReference::instruction_end() const {
return kind == JS
? code.js->InstructionEnd()
: reinterpret_cast<Address>(code.wasm->instructions().start() +
code.wasm->instructions().size());
return kind_ == JS
? js_code_->InstructionEnd()
: reinterpret_cast<Address>(wasm_code_->instructions().start() +
wasm_code_->instructions().size());
}
int CodeReference::instruction_size() const {
return kind == JS ? code.js->InstructionSize()
: code.wasm->instructions().length();
return kind_ == JS ? js_code_->InstructionSize()
: wasm_code_->instructions().length();
}
const byte* CodeReference::relocation_start() const {
return kind == JS ? code.js->relocation_start()
: code.wasm->reloc_info().start();
return kind_ == JS ? js_code_->relocation_start()
: wasm_code_->reloc_info().start();
}
const byte* CodeReference::relocation_end() const {
return kind == JS ? code.js->relocation_end()
: code.wasm->reloc_info().start() +
code.wasm->reloc_info().length();
return kind_ == JS ? js_code_->relocation_end()
: wasm_code_->reloc_info().start() +
wasm_code_->reloc_info().length();
}
int CodeReference::relocation_size() const {
return kind == JS ? code.js->relocation_size()
: code.wasm->reloc_info().length();
return kind_ == JS ? js_code_->relocation_size()
: wasm_code_->reloc_info().length();
}
} // namespace internal
......
......@@ -6,7 +6,7 @@
#define V8_CODE_REFERENCE_H_
#include "src/handles.h"
#include "src/objects.h"
#include "src/objects/code.h"
namespace v8 {
namespace internal {
......@@ -17,10 +17,12 @@ namespace wasm {
class WasmCode;
}
struct CodeReference {
explicit CodeReference(const wasm::WasmCode* wasm_code = nullptr)
: kind(WASM), code(wasm_code) {}
explicit CodeReference(Handle<Code> js_code) : kind(JS), code(js_code) {}
class CodeReference {
public:
CodeReference() : kind_(JS), 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 instruction_start() const;
......@@ -30,22 +32,19 @@ struct CodeReference {
const byte* relocation_end() const;
int relocation_size() 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:
enum { JS, WASM } kind;
union CodeUnion {
explicit CodeUnion(Handle<Code> js_code) : js(js_code) {}
explicit CodeUnion(const wasm::WasmCode* wasm_code) : wasm(wasm_code) {}
CodeUnion() : wasm(nullptr) {}
enum { JS, WASM } kind_;
union {
const wasm::WasmCode* wasm_code_;
Handle<Code> js_code_;
};
const wasm::WasmCode* wasm;
Handle<Code> js;
} code;
DISALLOW_NEW_AND_DELETE()
DISALLOW_NEW_AND_DELETE();
};
ASSERT_TRIVIALLY_COPYABLE(CodeReference);
} // namespace internal
} // 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