mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +00:00
LibJS/Bytecode: Remove Instruction::m_length field
Now that the interpreter is unrolled, we can advance the program counter manually based on the current instruction type. This makes most instructions a bit smaller. :^)
This commit is contained in:
@@ -10,13 +10,6 @@
|
||||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
Instruction::Instruction(Type type, size_t length)
|
||||
: m_type(type)
|
||||
, m_length(length)
|
||||
{
|
||||
VERIFY(length <= NumericLimits<u32>::max());
|
||||
}
|
||||
|
||||
void Instruction::destroy(Instruction& instruction)
|
||||
{
|
||||
#define __BYTECODE_OP(op) \
|
||||
@@ -49,6 +42,42 @@ void Instruction::visit_labels(Function<void(JS::Bytecode::Label&)> visitor)
|
||||
#undef __BYTECODE_OP
|
||||
}
|
||||
|
||||
template<typename Op>
|
||||
concept HasVariableLength = Op::IsVariableLength;
|
||||
|
||||
template<typename Op>
|
||||
concept HasFixedLength = !Op::IsVariableLength;
|
||||
|
||||
template<HasVariableLength Op>
|
||||
size_t get_length_impl(Op const& op)
|
||||
{
|
||||
return op.length_impl();
|
||||
}
|
||||
|
||||
// Function template for types without a length_impl method
|
||||
template<HasFixedLength Op>
|
||||
size_t get_length_impl(Op const&)
|
||||
{
|
||||
return sizeof(Op);
|
||||
}
|
||||
|
||||
size_t Instruction::length() const
|
||||
{
|
||||
#define __BYTECODE_OP(op) \
|
||||
case Type::op: { \
|
||||
auto& typed_op = static_cast<Op::op const&>(*this); \
|
||||
return get_length_impl(typed_op); \
|
||||
}
|
||||
|
||||
switch (type()) {
|
||||
ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
#undef __BYTECODE_OP
|
||||
}
|
||||
|
||||
UnrealizedSourceRange InstructionStreamIterator::source_range() const
|
||||
{
|
||||
VERIFY(m_executable);
|
||||
|
||||
Reference in New Issue
Block a user