Commit 9b13ecd5 authored by Ng Zhi An's avatar Ng Zhi An Committed by V8 LUCI CQ

[cleanup] Make an enum class CodeReference::Kind

Bug: v8:12244,v8:12245
Change-Id: I5b412b18df312eeb46a9af954acfa65fb403929e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3284007Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77926}
parent afb49bae
......@@ -86,26 +86,26 @@ struct CodeDescOps {
ret CodeReference::method() const { \
DCHECK(!is_null()); \
switch (kind_) { \
case JS: \
case Kind::JS: \
return JSOps{js_code_}.method(); \
case WASM: \
case Kind::WASM: \
return WasmOps{wasm_code_}.method(); \
case CODE_DESC: \
case Kind::CODE_DESC: \
return CodeDescOps{code_desc_}.method(); \
default: \
UNREACHABLE(); \
} \
}
#else
#define DISPATCH(ret, method) \
ret CodeReference::method() const { \
DCHECK(!is_null()); \
DCHECK(kind_ == JS || kind_ == CODE_DESC); \
if (kind_ == JS) { \
return JSOps{js_code_}.method(); \
} else { \
return CodeDescOps{code_desc_}.method(); \
} \
#define DISPATCH(ret, method) \
ret CodeReference::method() const { \
DCHECK(!is_null()); \
DCHECK(kind_ == Kind::JS || kind_ == Kind::CODE_DESC); \
if (kind_ == Kind::JS) { \
return JSOps{js_code_}.method(); \
} else { \
return CodeDescOps{code_desc_}.method(); \
} \
}
#endif // V8_ENABLE_WEBASSEMBLY
......
......@@ -20,12 +20,13 @@ class WasmCode;
class CodeReference {
public:
CodeReference() : kind_(NONE), null_(nullptr) {}
CodeReference() : kind_(Kind::NONE), null_(nullptr) {}
explicit CodeReference(const wasm::WasmCode* wasm_code)
: kind_(WASM), wasm_code_(wasm_code) {}
: kind_(Kind::WASM), wasm_code_(wasm_code) {}
explicit CodeReference(const CodeDesc* code_desc)
: kind_(CODE_DESC), code_desc_(code_desc) {}
explicit CodeReference(Handle<Code> js_code) : kind_(JS), js_code_(js_code) {}
: kind_(Kind::CODE_DESC), code_desc_(code_desc) {}
explicit CodeReference(Handle<Code> js_code)
: kind_(Kind::JS), js_code_(js_code) {}
Address constant_pool() const;
Address instruction_start() const;
......@@ -37,22 +38,22 @@ class CodeReference {
Address code_comments() const;
int code_comments_size() const;
bool is_null() const { return kind_ == NONE; }
bool is_js() const { return kind_ == JS; }
bool is_wasm_code() const { return kind_ == WASM; }
bool is_null() const { return kind_ == Kind::NONE; }
bool is_js() const { return kind_ == Kind::JS; }
bool is_wasm_code() const { return kind_ == Kind::WASM; }
Handle<Code> as_js_code() const {
DCHECK_EQ(JS, kind_);
DCHECK_EQ(Kind::JS, kind_);
return js_code_;
}
const wasm::WasmCode* as_wasm_code() const {
DCHECK_EQ(WASM, kind_);
DCHECK_EQ(Kind::WASM, kind_);
return wasm_code_;
}
private:
enum { NONE, JS, WASM, CODE_DESC } kind_;
enum class Kind { NONE, JS, WASM, CODE_DESC } kind_;
union {
std::nullptr_t null_;
const wasm::WasmCode* wasm_code_;
......
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