diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 5330751b11..48979164e6 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -315,11 +315,67 @@ void Compiler::compile_leave_unwind_context(Bytecode::Op::LeaveUnwindContext con void Compiler::compile_throw(Bytecode::Op::Throw const&) { - load_vm_register(GPR0, Bytecode::Register::accumulator()); + load_vm_register(GPR0, Bytecode::Register::accumulator()); store_vm_register(Bytecode::Register::exception(), GPR0); check_exception(); } +static Value cxx_add(VM& vm, Value lhs, Value rhs) +{ + return TRY_OR_SET_EXCEPTION(add(vm, lhs, rhs)); +} + +void Compiler::compile_add(Bytecode::Op::Add const& op) +{ + load_vm_register(ARG1, op.lhs()); + load_vm_register(ARG2, Bytecode::Register::accumulator()); + m_assembler.native_call((void*)cxx_add); + store_vm_register(Bytecode::Register::accumulator(), RET); + check_exception(); +} + +static Value cxx_sub(VM& vm, Value lhs, Value rhs) +{ + return TRY_OR_SET_EXCEPTION(sub(vm, lhs, rhs)); +} + +void Compiler::compile_sub(Bytecode::Op::Sub const& op) +{ + load_vm_register(ARG1, op.lhs()); + load_vm_register(ARG2, Bytecode::Register::accumulator()); + m_assembler.native_call((void*)cxx_sub); + store_vm_register(Bytecode::Register::accumulator(), RET); + check_exception(); +} + +static Value cxx_mul(VM& vm, Value lhs, Value rhs) +{ + return TRY_OR_SET_EXCEPTION(mul(vm, lhs, rhs)); +} + +void Compiler::compile_mul(Bytecode::Op::Mul const& op) +{ + load_vm_register(ARG1, op.lhs()); + load_vm_register(ARG2, Bytecode::Register::accumulator()); + m_assembler.native_call((void*)cxx_mul); + store_vm_register(Bytecode::Register::accumulator(), RET); + check_exception(); +} + +static Value cxx_div(VM& vm, Value lhs, Value rhs) +{ + return TRY_OR_SET_EXCEPTION(div(vm, lhs, rhs)); +} + +void Compiler::compile_div(Bytecode::Op::Div const& op) +{ + load_vm_register(ARG1, op.lhs()); + load_vm_register(ARG2, Bytecode::Register::accumulator()); + m_assembler.native_call((void*)cxx_div); + store_vm_register(Bytecode::Register::accumulator(), RET); + check_exception(); +} + OwnPtr Compiler::compile(Bytecode::Executable const& bytecode_executable) { if (getenv("LIBJS_NO_JIT")) @@ -381,6 +437,18 @@ OwnPtr Compiler::compile(Bytecode::Executable const& bytecode_ case Bytecode::Instruction::Type::Throw: compiler.compile_throw(static_cast(op)); break; + case Bytecode::Instruction::Type::Add: + compiler.compile_add(static_cast(op)); + break; + case Bytecode::Instruction::Type::Sub: + compiler.compile_sub(static_cast(op)); + break; + case Bytecode::Instruction::Type::Mul: + compiler.compile_mul(static_cast(op)); + break; + case Bytecode::Instruction::Type::Div: + compiler.compile_div(static_cast(op)); + break; default: dbgln("JIT compilation failed: {}", bytecode_executable.name); dbgln("Unsupported bytecode op: {}", op.to_deprecated_string(bytecode_executable)); @@ -424,7 +492,7 @@ OwnPtr Compiler::compile(Bytecode::Executable const& bytecode_ } size_t res = write(STDOUT_FILENO, compiler.m_output.data(), compiler.m_output.size()); - if (!res) {} + if (!res) { } memcpy(executable_memory, compiler.m_output.data(), compiler.m_output.size()); mprotect(executable_memory, compiler.m_output.size(), PROT_READ | PROT_EXEC); diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index 5328edf72b..597e4fac5b 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -41,6 +41,10 @@ private: void compile_enter_unwind_context(Bytecode::Op::EnterUnwindContext const&); void compile_leave_unwind_context(Bytecode::Op::LeaveUnwindContext const&); void compile_throw(Bytecode::Op::Throw const&); + void compile_add(Bytecode::Op::Add const&); + void compile_sub(Bytecode::Op::Sub const&); + void compile_mul(Bytecode::Op::Mul const&); + void compile_div(Bytecode::Op::Div const&); void store_vm_register(Bytecode::Register, Assembler::Reg); void load_vm_register(Assembler::Reg, Bytecode::Register);