1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

LibJS/JIT: Generate switch cases using X macro

This commit is contained in:
Simon Wanner 2023-10-29 15:02:35 +01:00 committed by Andreas Kling
parent f89bfb3f27
commit a28d6291ad

View file

@ -1211,147 +1211,12 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
while (!it.at_end()) {
auto const& op = *it;
switch (op.type()) {
case Bytecode::Instruction::Type::LoadImmediate:
compiler.compile_load_immediate(static_cast<Bytecode::Op::LoadImmediate const&>(op));
break;
case Bytecode::Instruction::Type::Store:
compiler.compile_store(static_cast<Bytecode::Op::Store const&>(op));
break;
case Bytecode::Instruction::Type::Load:
compiler.compile_load(static_cast<Bytecode::Op::Load const&>(op));
break;
case Bytecode::Instruction::Type::GetLocal:
compiler.compile_get_local(static_cast<Bytecode::Op::GetLocal const&>(op));
break;
case Bytecode::Instruction::Type::SetLocal:
compiler.compile_set_local(static_cast<Bytecode::Op::SetLocal const&>(op));
break;
case Bytecode::Instruction::Type::TypeofLocal:
compiler.compile_typeof_local(static_cast<Bytecode::Op::TypeofLocal const&>(op));
break;
case Bytecode::Instruction::Type::Jump:
compiler.compile_jump(static_cast<Bytecode::Op::Jump const&>(op));
break;
case Bytecode::Instruction::Type::JumpConditional:
compiler.compile_jump_conditional(static_cast<Bytecode::Op::JumpConditional const&>(op));
break;
case Bytecode::Instruction::Type::JumpNullish:
compiler.compile_jump_nullish(static_cast<Bytecode::Op::JumpNullish const&>(op));
break;
case Bytecode::Instruction::Type::Increment:
compiler.compile_increment(static_cast<Bytecode::Op::Increment const&>(op));
break;
case Bytecode::Instruction::Type::Decrement:
compiler.compile_decrement(static_cast<Bytecode::Op::Decrement const&>(op));
break;
case Bytecode::Instruction::Type::EnterUnwindContext:
compiler.compile_enter_unwind_context(static_cast<Bytecode::Op::EnterUnwindContext const&>(op));
break;
case Bytecode::Instruction::Type::LeaveUnwindContext:
compiler.compile_leave_unwind_context(static_cast<Bytecode::Op::LeaveUnwindContext const&>(op));
break;
case Bytecode::Instruction::Type::Throw:
compiler.compile_throw(static_cast<Bytecode::Op::Throw const&>(op));
break;
case Bytecode::Instruction::Type::Return:
compiler.compile_return(static_cast<Bytecode::Op::Return const&>(op));
break;
case Bytecode::Instruction::Type::CreateLexicalEnvironment:
compiler.compile_create_lexical_environment(static_cast<Bytecode::Op::CreateLexicalEnvironment const&>(op));
break;
case Bytecode::Instruction::Type::LeaveLexicalEnvironment:
compiler.compile_leave_lexical_environment(static_cast<Bytecode::Op::LeaveLexicalEnvironment const&>(op));
break;
case Bytecode::Instruction::Type::NewString:
compiler.compile_new_string(static_cast<Bytecode::Op::NewString const&>(op));
break;
case Bytecode::Instruction::Type::NewObject:
compiler.compile_new_object(static_cast<Bytecode::Op::NewObject const&>(op));
break;
case Bytecode::Instruction::Type::NewArray:
compiler.compile_new_array(static_cast<Bytecode::Op::NewArray const&>(op));
break;
case Bytecode::Instruction::Type::NewFunction:
compiler.compile_new_function(static_cast<Bytecode::Op::NewFunction const&>(op));
break;
case Bytecode::Instruction::Type::NewRegExp:
compiler.compile_new_regexp(static_cast<Bytecode::Op::NewRegExp const&>(op));
break;
case Bytecode::Instruction::Type::NewBigInt:
compiler.compile_new_bigint(static_cast<Bytecode::Op::NewBigInt const&>(op));
break;
case Bytecode::Instruction::Type::GetById:
compiler.compile_get_by_id(static_cast<Bytecode::Op::GetById const&>(op));
break;
case Bytecode::Instruction::Type::GetByValue:
compiler.compile_get_by_value(static_cast<Bytecode::Op::GetByValue const&>(op));
break;
case Bytecode::Instruction::Type::GetGlobal:
compiler.compile_get_global(static_cast<Bytecode::Op::GetGlobal const&>(op));
break;
case Bytecode::Instruction::Type::GetVariable:
compiler.compile_get_variable(static_cast<Bytecode::Op::GetVariable const&>(op));
break;
case Bytecode::Instruction::Type::GetCalleeAndThisFromEnvironment:
compiler.compile_get_callee_and_this_from_environment(static_cast<Bytecode::Op::GetCalleeAndThisFromEnvironment const&>(op));
break;
case Bytecode::Instruction::Type::PutById:
compiler.compile_put_by_id(static_cast<Bytecode::Op::PutById const&>(op));
break;
case Bytecode::Instruction::Type::PutByValue:
compiler.compile_put_by_value(static_cast<Bytecode::Op::PutByValue const&>(op));
break;
case Bytecode::Instruction::Type::ToNumeric:
compiler.compile_to_numeric(static_cast<Bytecode::Op::ToNumeric const&>(op));
break;
case Bytecode::Instruction::Type::ResolveThisBinding:
compiler.compile_resolve_this_binding(static_cast<Bytecode::Op::ResolveThisBinding const&>(op));
break;
case Bytecode::Instruction::Type::Call:
compiler.compile_call(static_cast<Bytecode::Op::Call const&>(op));
break;
case Bytecode::Instruction::Type::CallWithArgumentArray:
compiler.compile_call_with_argument_array(static_cast<Bytecode::Op::CallWithArgumentArray const&>(op));
break;
case Bytecode::Instruction::Type::TypeofVariable:
compiler.compile_typeof_variable(static_cast<Bytecode::Op::TypeofVariable const&>(op));
break;
case Bytecode::Instruction::Type::SetVariable:
compiler.compile_set_variable(static_cast<Bytecode::Op::SetVariable const&>(op));
break;
case Bytecode::Instruction::Type::Add:
compiler.compile_add(static_cast<Bytecode::Op::Add const&>(op));
break;
case Bytecode::Instruction::Type::LessThan:
compiler.compile_less_than(static_cast<Bytecode::Op::LessThan const&>(op));
break;
case Bytecode::Instruction::Type::ContinuePendingUnwind:
compiler.compile_continue_pending_unwind(static_cast<Bytecode::Op::ContinuePendingUnwind const&>(op));
break;
case Bytecode::Instruction::Type::ConcatString:
compiler.compile_concat_string(static_cast<Bytecode::Op::ConcatString const&>(op));
break;
case Bytecode::Instruction::Type::CreateVariable:
compiler.compile_create_variable(static_cast<Bytecode::Op::CreateVariable const&>(op));
break;
case Bytecode::Instruction::Type::NewClass:
compiler.compile_new_class(static_cast<Bytecode::Op::NewClass const&>(op));
break;
# define DO_COMPILE_COMMON_BINARY_OP(TitleCaseName, snake_case_name) \
case Bytecode::Instruction::Type::TitleCaseName: \
compiler.compile_##snake_case_name(static_cast<Bytecode::Op::TitleCaseName const&>(op)); \
# define CASE_BYTECODE_OP(OpTitleCase, op_snake_case) \
case Bytecode::Instruction::Type::OpTitleCase: \
compiler.compile_##op_snake_case(static_cast<Bytecode::Op::OpTitleCase const&>(op)); \
break;
JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(DO_COMPILE_COMMON_BINARY_OP)
# undef DO_COMPILE_COMMON_BINARY_OP
# define DO_COMPILE_COMMON_UNARY_OP(TitleCaseName, snake_case_name) \
case Bytecode::Instruction::Type::TitleCaseName: \
compiler.compile_##snake_case_name(static_cast<Bytecode::Op::TitleCaseName const&>(op)); \
break;
JS_ENUMERATE_COMMON_UNARY_OPS(DO_COMPILE_COMMON_UNARY_OP)
# undef DO_COMPILE_COMMON_UNARY_OP
JS_ENUMERATE_IMPLEMENTED_JIT_OPS(CASE_BYTECODE_OP)
# undef CASE_BYTECODE_OP
default:
if constexpr (LOG_JIT_FAILURE) {
dbgln("\033[31;1mJIT compilation failed\033[0m: {}", bytecode_executable.name);