mirror of
https://github.com/RGBCube/serenity
synced 2025-07-19 21:37:34 +00:00
LibJS/JIT: Record machine code location to bytecode location mapping
This commit is contained in:
parent
cf93e56833
commit
9f78e56823
3 changed files with 37 additions and 4 deletions
|
@ -1686,6 +1686,14 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
|
||||||
|
|
||||||
Compiler compiler { bytecode_executable };
|
Compiler compiler { bytecode_executable };
|
||||||
|
|
||||||
|
Vector<BytecodeMapping> mapping;
|
||||||
|
|
||||||
|
mapping.append({
|
||||||
|
.native_offset = compiler.m_output.size(),
|
||||||
|
.block_index = BytecodeMapping::EXECUTABLE,
|
||||||
|
.bytecode_offset = 0,
|
||||||
|
});
|
||||||
|
|
||||||
compiler.m_assembler.enter();
|
compiler.m_assembler.enter();
|
||||||
|
|
||||||
compiler.m_assembler.mov(
|
compiler.m_assembler.mov(
|
||||||
|
@ -1696,12 +1704,20 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
|
||||||
Assembler::Operand::Register(LOCALS_ARRAY_BASE),
|
Assembler::Operand::Register(LOCALS_ARRAY_BASE),
|
||||||
Assembler::Operand::Register(ARG2));
|
Assembler::Operand::Register(ARG2));
|
||||||
|
|
||||||
for (auto& block : bytecode_executable.basic_blocks) {
|
for (size_t block_index = 0; block_index < bytecode_executable.basic_blocks.size(); block_index++) {
|
||||||
|
auto& block = bytecode_executable.basic_blocks[block_index];
|
||||||
compiler.block_data_for(*block).start_offset = compiler.m_output.size();
|
compiler.block_data_for(*block).start_offset = compiler.m_output.size();
|
||||||
compiler.set_current_block(*block);
|
compiler.set_current_block(*block);
|
||||||
auto it = Bytecode::InstructionStreamIterator(block->instruction_stream());
|
auto it = Bytecode::InstructionStreamIterator(block->instruction_stream());
|
||||||
while (!it.at_end()) {
|
while (!it.at_end()) {
|
||||||
auto const& op = *it;
|
auto const& op = *it;
|
||||||
|
|
||||||
|
mapping.append({
|
||||||
|
.native_offset = compiler.m_output.size(),
|
||||||
|
.block_index = block_index,
|
||||||
|
.bytecode_offset = it.offset(),
|
||||||
|
});
|
||||||
|
|
||||||
switch (op.type()) {
|
switch (op.type()) {
|
||||||
# define CASE_BYTECODE_OP(OpTitleCase, op_snake_case, ...) \
|
# define CASE_BYTECODE_OP(OpTitleCase, op_snake_case, ...) \
|
||||||
case Bytecode::Instruction::Type::OpTitleCase: \
|
case Bytecode::Instruction::Type::OpTitleCase: \
|
||||||
|
@ -1723,6 +1739,12 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
|
||||||
compiler.jump_to_exit();
|
compiler.jump_to_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mapping.append({
|
||||||
|
.native_offset = compiler.m_output.size(),
|
||||||
|
.block_index = BytecodeMapping::EXECUTABLE,
|
||||||
|
.bytecode_offset = 1,
|
||||||
|
});
|
||||||
|
|
||||||
compiler.m_exit_label.link(compiler.m_assembler);
|
compiler.m_exit_label.link(compiler.m_assembler);
|
||||||
compiler.m_assembler.exit();
|
compiler.m_assembler.exit();
|
||||||
|
|
||||||
|
@ -1752,7 +1774,7 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
|
||||||
dbgln("\033[32;1mJIT compilation succeeded!\033[0m {}", bytecode_executable.name);
|
dbgln("\033[32;1mJIT compilation succeeded!\033[0m {}", bytecode_executable.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto executable = make<NativeExecutable>(executable_memory, compiler.m_output.size());
|
auto executable = make<NativeExecutable>(executable_memory, compiler.m_output.size(), mapping);
|
||||||
if constexpr (DUMP_JIT_DISASSEMBLY)
|
if constexpr (DUMP_JIT_DISASSEMBLY)
|
||||||
executable->dump_disassembly();
|
executable->dump_disassembly();
|
||||||
return executable;
|
return executable;
|
||||||
|
|
|
@ -12,9 +12,10 @@
|
||||||
|
|
||||||
namespace JS::JIT {
|
namespace JS::JIT {
|
||||||
|
|
||||||
NativeExecutable::NativeExecutable(void* code, size_t size)
|
NativeExecutable::NativeExecutable(void* code, size_t size, Vector<BytecodeMapping> mapping)
|
||||||
: m_code(code)
|
: m_code(code)
|
||||||
, m_size(size)
|
, m_size(size)
|
||||||
|
, m_mapping(move(mapping))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,21 @@
|
||||||
|
|
||||||
namespace JS::JIT {
|
namespace JS::JIT {
|
||||||
|
|
||||||
|
struct BytecodeMapping {
|
||||||
|
size_t native_offset;
|
||||||
|
size_t block_index;
|
||||||
|
size_t bytecode_offset;
|
||||||
|
|
||||||
|
// Special block index for labels outside any blocks.
|
||||||
|
static constexpr auto EXECUTABLE = NumericLimits<size_t>::max();
|
||||||
|
};
|
||||||
|
|
||||||
class NativeExecutable {
|
class NativeExecutable {
|
||||||
AK_MAKE_NONCOPYABLE(NativeExecutable);
|
AK_MAKE_NONCOPYABLE(NativeExecutable);
|
||||||
AK_MAKE_NONMOVABLE(NativeExecutable);
|
AK_MAKE_NONMOVABLE(NativeExecutable);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NativeExecutable(void* code, size_t size);
|
NativeExecutable(void* code, size_t size, Vector<BytecodeMapping>);
|
||||||
~NativeExecutable();
|
~NativeExecutable();
|
||||||
|
|
||||||
void run(VM&) const;
|
void run(VM&) const;
|
||||||
|
@ -26,6 +35,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void* m_code { nullptr };
|
void* m_code { nullptr };
|
||||||
size_t m_size { 0 };
|
size_t m_size { 0 };
|
||||||
|
Vector<BytecodeMapping> m_mapping;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue