mirror of
https://github.com/RGBCube/serenity
synced 2025-06-25 14:02:12 +00:00
LibJS/JIT: Support the NewString bytecode op
This necessitated making the JIT::Compiler aware of the current Bytecode::Executable, since that's where all the string literals are held, but that seems like a good thing.
This commit is contained in:
parent
efe58ebf2f
commit
c2fe7af095
3 changed files with 30 additions and 3 deletions
|
@ -157,6 +157,8 @@ public:
|
||||||
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
||||||
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const;
|
||||||
|
|
||||||
|
StringTableIndex index() const { return m_string; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StringTableIndex m_string;
|
StringTableIndex m_string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -383,12 +383,27 @@ void Compiler::compile_return(Bytecode::Op::Return const&)
|
||||||
m_assembler.exit();
|
m_assembler.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<NativeExecutable> 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<u64>(&string)));
|
||||||
|
m_assembler.native_call((void*)cxx_new_string);
|
||||||
|
store_vm_register(Bytecode::Register::accumulator(), RET);
|
||||||
|
}
|
||||||
|
|
||||||
|
OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_executable)
|
||||||
{
|
{
|
||||||
if (getenv("LIBJS_NO_JIT"))
|
if (getenv("LIBJS_NO_JIT"))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
Compiler compiler;
|
Compiler compiler { bytecode_executable };
|
||||||
|
|
||||||
compiler.m_assembler.enter();
|
compiler.m_assembler.enter();
|
||||||
|
|
||||||
|
@ -459,6 +474,9 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable const& bytecode_
|
||||||
case Bytecode::Instruction::Type::Return:
|
case Bytecode::Instruction::Type::Return:
|
||||||
compiler.compile_return(static_cast<Bytecode::Op::Return const&>(op));
|
compiler.compile_return(static_cast<Bytecode::Op::Return const&>(op));
|
||||||
break;
|
break;
|
||||||
|
case Bytecode::Instruction::Type::NewString:
|
||||||
|
compiler.compile_new_string(static_cast<Bytecode::Op::NewString 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));
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace JS::JIT {
|
||||||
|
|
||||||
class Compiler {
|
class Compiler {
|
||||||
public:
|
public:
|
||||||
static OwnPtr<NativeExecutable> compile(Bytecode::Executable const&);
|
static OwnPtr<NativeExecutable> compile(Bytecode::Executable&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr auto GPR0 = Assembler::Reg::RAX;
|
static constexpr auto GPR0 = Assembler::Reg::RAX;
|
||||||
|
@ -46,6 +46,7 @@ private:
|
||||||
void compile_mul(Bytecode::Op::Mul const&);
|
void compile_mul(Bytecode::Op::Mul const&);
|
||||||
void compile_div(Bytecode::Op::Div const&);
|
void compile_div(Bytecode::Op::Div const&);
|
||||||
void compile_return(Bytecode::Op::Return 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 store_vm_register(Bytecode::Register, Assembler::Reg);
|
||||||
void load_vm_register(Assembler::Reg, Bytecode::Register);
|
void load_vm_register(Assembler::Reg, Bytecode::Register);
|
||||||
|
@ -60,8 +61,14 @@ private:
|
||||||
void push_unwind_context(bool valid, Optional<Bytecode::Label> const& handler, Optional<Bytecode::Label> const& finalizer);
|
void push_unwind_context(bool valid, Optional<Bytecode::Label> const& handler, Optional<Bytecode::Label> const& finalizer);
|
||||||
void pop_unwind_context();
|
void pop_unwind_context();
|
||||||
|
|
||||||
|
explicit Compiler(Bytecode::Executable& bytecode_executable)
|
||||||
|
: m_bytecode_executable(bytecode_executable)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Vector<u8> m_output;
|
Vector<u8> m_output;
|
||||||
Assembler m_assembler { m_output };
|
Assembler m_assembler { m_output };
|
||||||
|
Bytecode::Executable& m_bytecode_executable;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue