From a28d6291ad935a283e8635608fd7489c116711f3 Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Sun, 29 Oct 2023 15:02:35 +0100 Subject: [PATCH] LibJS/JIT: Generate switch cases using X macro --- Userland/Libraries/LibJS/JIT/Compiler.cpp | 145 +--------------------- 1 file changed, 5 insertions(+), 140 deletions(-) diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 5480b4e018..68d2f8451b 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -1211,147 +1211,12 @@ OwnPtr 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(op)); - break; - case Bytecode::Instruction::Type::Store: - compiler.compile_store(static_cast(op)); - break; - case Bytecode::Instruction::Type::Load: - compiler.compile_load(static_cast(op)); - break; - case Bytecode::Instruction::Type::GetLocal: - compiler.compile_get_local(static_cast(op)); - break; - case Bytecode::Instruction::Type::SetLocal: - compiler.compile_set_local(static_cast(op)); - break; - case Bytecode::Instruction::Type::TypeofLocal: - compiler.compile_typeof_local(static_cast(op)); - break; - case Bytecode::Instruction::Type::Jump: - compiler.compile_jump(static_cast(op)); - break; - case Bytecode::Instruction::Type::JumpConditional: - compiler.compile_jump_conditional(static_cast(op)); - break; - case Bytecode::Instruction::Type::JumpNullish: - compiler.compile_jump_nullish(static_cast(op)); - break; - case Bytecode::Instruction::Type::Increment: - compiler.compile_increment(static_cast(op)); - break; - case Bytecode::Instruction::Type::Decrement: - compiler.compile_decrement(static_cast(op)); - break; - case Bytecode::Instruction::Type::EnterUnwindContext: - compiler.compile_enter_unwind_context(static_cast(op)); - break; - case Bytecode::Instruction::Type::LeaveUnwindContext: - compiler.compile_leave_unwind_context(static_cast(op)); - break; - case Bytecode::Instruction::Type::Throw: - compiler.compile_throw(static_cast(op)); - break; - case Bytecode::Instruction::Type::Return: - compiler.compile_return(static_cast(op)); - break; - case Bytecode::Instruction::Type::CreateLexicalEnvironment: - compiler.compile_create_lexical_environment(static_cast(op)); - break; - case Bytecode::Instruction::Type::LeaveLexicalEnvironment: - compiler.compile_leave_lexical_environment(static_cast(op)); - break; - case Bytecode::Instruction::Type::NewString: - compiler.compile_new_string(static_cast(op)); - break; - case Bytecode::Instruction::Type::NewObject: - compiler.compile_new_object(static_cast(op)); - break; - case Bytecode::Instruction::Type::NewArray: - compiler.compile_new_array(static_cast(op)); - break; - case Bytecode::Instruction::Type::NewFunction: - compiler.compile_new_function(static_cast(op)); - break; - case Bytecode::Instruction::Type::NewRegExp: - compiler.compile_new_regexp(static_cast(op)); - break; - case Bytecode::Instruction::Type::NewBigInt: - compiler.compile_new_bigint(static_cast(op)); - break; - case Bytecode::Instruction::Type::GetById: - compiler.compile_get_by_id(static_cast(op)); - break; - case Bytecode::Instruction::Type::GetByValue: - compiler.compile_get_by_value(static_cast(op)); - break; - case Bytecode::Instruction::Type::GetGlobal: - compiler.compile_get_global(static_cast(op)); - break; - case Bytecode::Instruction::Type::GetVariable: - compiler.compile_get_variable(static_cast(op)); - break; - case Bytecode::Instruction::Type::GetCalleeAndThisFromEnvironment: - compiler.compile_get_callee_and_this_from_environment(static_cast(op)); - break; - case Bytecode::Instruction::Type::PutById: - compiler.compile_put_by_id(static_cast(op)); - break; - case Bytecode::Instruction::Type::PutByValue: - compiler.compile_put_by_value(static_cast(op)); - break; - case Bytecode::Instruction::Type::ToNumeric: - compiler.compile_to_numeric(static_cast(op)); - break; - case Bytecode::Instruction::Type::ResolveThisBinding: - compiler.compile_resolve_this_binding(static_cast(op)); - break; - case Bytecode::Instruction::Type::Call: - compiler.compile_call(static_cast(op)); - break; - case Bytecode::Instruction::Type::CallWithArgumentArray: - compiler.compile_call_with_argument_array(static_cast(op)); - break; - case Bytecode::Instruction::Type::TypeofVariable: - compiler.compile_typeof_variable(static_cast(op)); - break; - case Bytecode::Instruction::Type::SetVariable: - compiler.compile_set_variable(static_cast(op)); - break; - case Bytecode::Instruction::Type::Add: - compiler.compile_add(static_cast(op)); - break; - case Bytecode::Instruction::Type::LessThan: - compiler.compile_less_than(static_cast(op)); - break; - case Bytecode::Instruction::Type::ContinuePendingUnwind: - compiler.compile_continue_pending_unwind(static_cast(op)); - break; - case Bytecode::Instruction::Type::ConcatString: - compiler.compile_concat_string(static_cast(op)); - break; - case Bytecode::Instruction::Type::CreateVariable: - compiler.compile_create_variable(static_cast(op)); - break; - case Bytecode::Instruction::Type::NewClass: - compiler.compile_new_class(static_cast(op)); - break; - -# define DO_COMPILE_COMMON_BINARY_OP(TitleCaseName, snake_case_name) \ - case Bytecode::Instruction::Type::TitleCaseName: \ - compiler.compile_##snake_case_name(static_cast(op)); \ +# define CASE_BYTECODE_OP(OpTitleCase, op_snake_case) \ + case Bytecode::Instruction::Type::OpTitleCase: \ + compiler.compile_##op_snake_case(static_cast(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(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);