Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1115)

Unified Diff: src/interpreter/interpreter.cc

Issue 2560893002: [interpreter] Avoid code duplication in Interpreter::Initialize(). (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/interpreter/interpreter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/interpreter.cc
diff --git a/src/interpreter/interpreter.cc b/src/interpreter/interpreter.cc
index 9d2fd2029f6bcf72e68e8dfc3127e65eace5c35f..5b484cca78e1558c880bbf89b5f219243eb04ee6 100644
--- a/src/interpreter/interpreter.cc
+++ b/src/interpreter/interpreter.cc
@@ -73,30 +73,9 @@ void Interpreter::Initialize() {
};
for (OperandScale operand_scale : kOperandScales) {
-#define GENERATE_CODE(Name, ...) \
- { \
- if (Bytecodes::BytecodeHasHandler(Bytecode::k##Name, operand_scale)) { \
- InterpreterDispatchDescriptor descriptor(isolate_); \
- compiler::CodeAssemblerState state( \
- isolate_, &zone, descriptor, \
- Code::ComputeFlags(Code::BYTECODE_HANDLER), \
- Bytecodes::ToString(Bytecode::k##Name), \
- Bytecodes::ReturnCount(Bytecode::k##Name)); \
- InterpreterAssembler assembler(&state, Bytecode::k##Name, \
- operand_scale); \
- Do##Name(&assembler); \
- Handle<Code> code = compiler::CodeAssembler::GenerateCode(&state); \
- size_t index = GetDispatchTableIndex(Bytecode::k##Name, operand_scale); \
- dispatch_table_[index] = code->entry(); \
- TraceCodegen(code); \
- PROFILE( \
- isolate_, \
- CodeCreateEvent( \
- CodeEventListener::BYTECODE_HANDLER_TAG, \
- AbstractCode::cast(*code), \
- Bytecodes::ToString(Bytecode::k##Name, operand_scale).c_str())); \
- } \
- }
+#define GENERATE_CODE(Name, ...) \
+ InstallBytecodeHandler(&zone, Bytecode::k##Name, operand_scale, \
+ &Interpreter::Do##Name);
BYTECODE_LIST(GENERATE_CODE)
#undef GENERATE_CODE
}
@@ -114,6 +93,27 @@ void Interpreter::Initialize() {
DCHECK(IsDispatchTableInitialized());
}
+void Interpreter::InstallBytecodeHandler(Zone* zone, Bytecode bytecode,
+ OperandScale operand_scale,
+ BytecodeGeneratorFunc generator) {
+ if (!Bytecodes::BytecodeHasHandler(bytecode, operand_scale)) return;
+
+ InterpreterDispatchDescriptor descriptor(isolate_);
+ compiler::CodeAssemblerState state(
+ isolate_, zone, descriptor, Code::ComputeFlags(Code::BYTECODE_HANDLER),
+ Bytecodes::ToString(bytecode), Bytecodes::ReturnCount(bytecode));
+ InterpreterAssembler assembler(&state, bytecode, operand_scale);
+ (this->*generator)(&assembler);
+ Handle<Code> code = compiler::CodeAssembler::GenerateCode(&state);
+ size_t index = GetDispatchTableIndex(bytecode, operand_scale);
+ dispatch_table_[index] = code->entry();
+ TraceCodegen(code);
+ PROFILE(isolate_, CodeCreateEvent(
+ CodeEventListener::BYTECODE_HANDLER_TAG,
+ AbstractCode::cast(*code),
+ Bytecodes::ToString(bytecode, operand_scale).c_str()));
+}
+
Code* Interpreter::GetBytecodeHandler(Bytecode bytecode,
OperandScale operand_scale) {
DCHECK(IsDispatchTableInitialized());
« no previous file with comments | « src/interpreter/interpreter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698