mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:37:36 +00:00
LibJS/JIT: Add support for Add/Sub/Mul/Div bytecode ops
This commit is contained in:
parent
891b071654
commit
45be2a8f72
2 changed files with 74 additions and 2 deletions
|
@ -320,6 +320,62 @@ void Compiler::compile_throw(Bytecode::Op::Throw const&)
|
||||||
check_exception();
|
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<NativeExecutable> Compiler::compile(Bytecode::Executable const& bytecode_executable)
|
OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable const& bytecode_executable)
|
||||||
{
|
{
|
||||||
if (getenv("LIBJS_NO_JIT"))
|
if (getenv("LIBJS_NO_JIT"))
|
||||||
|
@ -381,6 +437,18 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable const& bytecode_
|
||||||
case Bytecode::Instruction::Type::Throw:
|
case Bytecode::Instruction::Type::Throw:
|
||||||
compiler.compile_throw(static_cast<Bytecode::Op::Throw const&>(op));
|
compiler.compile_throw(static_cast<Bytecode::Op::Throw const&>(op));
|
||||||
break;
|
break;
|
||||||
|
case Bytecode::Instruction::Type::Add:
|
||||||
|
compiler.compile_add(static_cast<Bytecode::Op::Add const&>(op));
|
||||||
|
break;
|
||||||
|
case Bytecode::Instruction::Type::Sub:
|
||||||
|
compiler.compile_sub(static_cast<Bytecode::Op::Sub const&>(op));
|
||||||
|
break;
|
||||||
|
case Bytecode::Instruction::Type::Mul:
|
||||||
|
compiler.compile_mul(static_cast<Bytecode::Op::Mul const&>(op));
|
||||||
|
break;
|
||||||
|
case Bytecode::Instruction::Type::Div:
|
||||||
|
compiler.compile_div(static_cast<Bytecode::Op::Div const&>(op));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
dbgln("JIT compilation failed: {}", bytecode_executable.name);
|
dbgln("JIT compilation failed: {}", bytecode_executable.name);
|
||||||
dbgln("Unsupported bytecode op: {}", op.to_deprecated_string(bytecode_executable));
|
dbgln("Unsupported bytecode op: {}", op.to_deprecated_string(bytecode_executable));
|
||||||
|
|
|
@ -41,6 +41,10 @@ private:
|
||||||
void compile_enter_unwind_context(Bytecode::Op::EnterUnwindContext const&);
|
void compile_enter_unwind_context(Bytecode::Op::EnterUnwindContext const&);
|
||||||
void compile_leave_unwind_context(Bytecode::Op::LeaveUnwindContext const&);
|
void compile_leave_unwind_context(Bytecode::Op::LeaveUnwindContext const&);
|
||||||
void compile_throw(Bytecode::Op::Throw 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 store_vm_register(Bytecode::Register, Assembler::Reg);
|
||||||
void load_vm_register(Assembler::Reg, Bytecode::Register);
|
void load_vm_register(Assembler::Reg, Bytecode::Register);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue