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 { ...@@ -86,26 +86,26 @@ struct CodeDescOps {
ret CodeReference::method() const { \ ret CodeReference::method() const { \
DCHECK(!is_null()); \ DCHECK(!is_null()); \
switch (kind_) { \ switch (kind_) { \
case JS: \ case Kind::JS: \
return JSOps{js_code_}.method(); \ return JSOps{js_code_}.method(); \
case WASM: \ case Kind::WASM: \
return WasmOps{wasm_code_}.method(); \ return WasmOps{wasm_code_}.method(); \
case CODE_DESC: \ case Kind::CODE_DESC: \
return CodeDescOps{code_desc_}.method(); \ return CodeDescOps{code_desc_}.method(); \
default: \ default: \
UNREACHABLE(); \ UNREACHABLE(); \
} \ } \
} }
#else #else
#define DISPATCH(ret, method) \ #define DISPATCH(ret, method) \
ret CodeReference::method() const { \ ret CodeReference::method() const { \
DCHECK(!is_null()); \ DCHECK(!is_null()); \
DCHECK(kind_ == JS || kind_ == CODE_DESC); \ DCHECK(kind_ == Kind::JS || kind_ == Kind::CODE_DESC); \
if (kind_ == JS) { \ if (kind_ == Kind::JS) { \
return JSOps{js_code_}.method(); \ return JSOps{js_code_}.method(); \
} else { \ } else { \
return CodeDescOps{code_desc_}.method(); \ return CodeDescOps{code_desc_}.method(); \
} \ } \
} }
#endif // V8_ENABLE_WEBASSEMBLY #endif // V8_ENABLE_WEBASSEMBLY
......
...@@ -20,12 +20,13 @@ class WasmCode; ...@@ -20,12 +20,13 @@ class WasmCode;
class CodeReference { class CodeReference {
public: public:
CodeReference() : kind_(NONE), null_(nullptr) {} CodeReference() : kind_(Kind::NONE), null_(nullptr) {}
explicit CodeReference(const wasm::WasmCode* wasm_code) 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) explicit CodeReference(const CodeDesc* code_desc)
: kind_(CODE_DESC), code_desc_(code_desc) {} : kind_(Kind::CODE_DESC), code_desc_(code_desc) {}
explicit CodeReference(Handle<Code> js_code) : kind_(JS), js_code_(js_code) {} explicit CodeReference(Handle<Code> js_code)
: kind_(Kind::JS), js_code_(js_code) {}
Address constant_pool() const; Address constant_pool() const;
Address instruction_start() const; Address instruction_start() const;
...@@ -37,22 +38,22 @@ class CodeReference { ...@@ -37,22 +38,22 @@ class CodeReference {
Address code_comments() const; Address code_comments() const;
int code_comments_size() const; int code_comments_size() const;
bool is_null() const { return kind_ == NONE; } bool is_null() const { return kind_ == Kind::NONE; }
bool is_js() const { return kind_ == JS; } bool is_js() const { return kind_ == Kind::JS; }
bool is_wasm_code() const { return kind_ == WASM; } bool is_wasm_code() const { return kind_ == Kind::WASM; }
Handle<Code> as_js_code() const { Handle<Code> as_js_code() const {
DCHECK_EQ(JS, kind_); DCHECK_EQ(Kind::JS, kind_);
return js_code_; return js_code_;
} }
const wasm::WasmCode* as_wasm_code() const { const wasm::WasmCode* as_wasm_code() const {
DCHECK_EQ(WASM, kind_); DCHECK_EQ(Kind::WASM, kind_);
return wasm_code_; return wasm_code_;
} }
private: private:
enum { NONE, JS, WASM, CODE_DESC } kind_; enum class Kind { NONE, JS, WASM, CODE_DESC } kind_;
union { union {
std::nullptr_t null_; std::nullptr_t null_;
const wasm::WasmCode* wasm_code_; 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