From e946440ed3026a166c8281cffb643ddf2eb5f401 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 21 Oct 2023 15:26:03 +0200 Subject: [PATCH] LibJS/JIT: Compile the TypeofVariable bytecode instruction --- Userland/Libraries/LibJS/Bytecode/Op.h | 2 ++ Userland/Libraries/LibJS/JIT/Compiler.cpp | 18 ++++++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 1 + 3 files changed, 21 insertions(+) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 14052dd181..3a49dd1567 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -1418,6 +1418,8 @@ public: ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; + IdentifierTableIndex identifier() const { return m_identifier; } + private: IdentifierTableIndex m_identifier; }; diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 1f8d50e714..c52f4144a2 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -550,6 +550,21 @@ void Compiler::compile_call(Bytecode::Op::Call const& op) check_exception(); } +static Value cxx_typeof_variable(VM& vm, DeprecatedFlyString const& identifier) +{ + return TRY_OR_SET_EXCEPTION(Bytecode::typeof_variable(vm, identifier)); +} + +void Compiler::compile_typeof_variable(Bytecode::Op::TypeofVariable const& op) +{ + m_assembler.mov( + Assembler::Operand::Register(ARG1), + Assembler::Operand::Imm64(bit_cast(&m_bytecode_executable.get_identifier(op.identifier().value())))); + m_assembler.native_call((void*)cxx_typeof_variable); + store_vm_register(Bytecode::Register::accumulator(), RET); + check_exception(); +} + OwnPtr Compiler::compile(Bytecode::Executable& bytecode_executable) { if (getenv("LIBJS_NO_JIT")) @@ -641,6 +656,9 @@ OwnPtr Compiler::compile(Bytecode::Executable& bytecode_execut case Bytecode::Instruction::Type::Call: compiler.compile_call(static_cast(op)); break; + case Bytecode::Instruction::Type::TypeofVariable: + compiler.compile_typeof_variable(static_cast(op)); + break; #define DO_COMPILE_COMMON_BINARY_OP(TitleCaseName, snake_case_name) \ case Bytecode::Instruction::Type::TitleCaseName: \ diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index 7aa1eb2c9b..eee4d6ec53 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -69,6 +69,7 @@ private: void compile_put_by_id(Bytecode::Op::PutById const&); void compile_call(Bytecode::Op::Call const&); + void compile_typeof_variable(Bytecode::Op::TypeofVariable const&); void store_vm_register(Bytecode::Register, Assembler::Reg); void load_vm_register(Assembler::Reg, Bytecode::Register);