Commit 0d292505 authored by ishell's avatar ishell Committed by Commit bot

[interpreter] Avoid code duplication in Interpreter::Initialize().

BUG=

Review-Url: https://codereview.chromium.org/2560893002
Cr-Commit-Position: refs/heads/master@{#41561}
parent 089e4fd3
......@@ -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());
......
......@@ -76,6 +76,14 @@ class Interpreter {
BYTECODE_LIST(DECLARE_BYTECODE_HANDLER_GENERATOR)
#undef DECLARE_BYTECODE_HANDLER_GENERATOR
typedef void (Interpreter::*BytecodeGeneratorFunc)(InterpreterAssembler*);
// Generates handler for given |bytecode| and |operand_scale| using
// |generator| and installs it into the dispatch table.
void InstallBytecodeHandler(Zone* zone, Bytecode bytecode,
OperandScale operand_scale,
BytecodeGeneratorFunc generator);
// Generates code to perform the binary operation via |Generator|.
template <class Generator>
void DoBinaryOpWithFeedback(InterpreterAssembler* assembler);
......
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