diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 8f1c217cf1..00903594d0 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -157,6 +157,8 @@ public: ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; + StringTableIndex index() const { return m_string; } + private: StringTableIndex m_string; }; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 6a3f9df860..e90c0df9d0 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -383,12 +383,27 @@ void Compiler::compile_return(Bytecode::Op::Return const&) m_assembler.exit(); } -OwnPtr Compiler::compile(Bytecode::Executable const& bytecode_executable) +static Value cxx_new_string(VM& vm, DeprecatedString const& string) +{ + return PrimitiveString::create(vm, string); +} + +void Compiler::compile_new_string(Bytecode::Op::NewString const& op) +{ + auto const& string = m_bytecode_executable.string_table->get(op.index()); + m_assembler.mov( + Assembler::Operand::Register(ARG1), + Assembler::Operand::Imm64(bit_cast(&string))); + m_assembler.native_call((void*)cxx_new_string); + store_vm_register(Bytecode::Register::accumulator(), RET); +} + +OwnPtr Compiler::compile(Bytecode::Executable& bytecode_executable) { if (getenv("LIBJS_NO_JIT")) return nullptr; - Compiler compiler; + Compiler compiler { bytecode_executable }; compiler.m_assembler.enter(); @@ -459,6 +474,9 @@ OwnPtr Compiler::compile(Bytecode::Executable const& bytecode_ case Bytecode::Instruction::Type::Return: compiler.compile_return(static_cast(op)); break; + case Bytecode::Instruction::Type::NewString: + compiler.compile_new_string(static_cast(op)); + break; default: dbgln("JIT compilation failed: {}", bytecode_executable.name); dbgln("Unsupported bytecode op: {}", op.to_deprecated_string(bytecode_executable)); diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index 88b9910db7..5142b7f136 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -15,7 +15,7 @@ namespace JS::JIT { class Compiler { public: - static OwnPtr compile(Bytecode::Executable const&); + static OwnPtr compile(Bytecode::Executable&); private: static constexpr auto GPR0 = Assembler::Reg::RAX; @@ -46,6 +46,7 @@ private: void compile_mul(Bytecode::Op::Mul const&); void compile_div(Bytecode::Op::Div const&); void compile_return(Bytecode::Op::Return const&); + void compile_new_string(Bytecode::Op::NewString const&); void store_vm_register(Bytecode::Register, Assembler::Reg); void load_vm_register(Assembler::Reg, Bytecode::Register); @@ -60,8 +61,14 @@ private: void push_unwind_context(bool valid, Optional const& handler, Optional const& finalizer); void pop_unwind_context(); + explicit Compiler(Bytecode::Executable& bytecode_executable) + : m_bytecode_executable(bytecode_executable) + { + } + Vector m_output; Assembler m_assembler { m_output }; + Bytecode::Executable& m_bytecode_executable; }; }