mirror of
https://github.com/zebrajr/ladybird.git
synced 2026-01-15 12:15:15 +00:00
While we're in the bytecode compiler, we want to know which type of Operand we're dealing with, but once we've generated the bytecode stream, we only ever need its index. This patch simplifies Operand by removing the aarch64 bitfield hacks and makes it 32-bit on all platforms. We keep 3 type bits in the high bits of the index while compiling, and then zero them out when flattening the final bytecode stream. This makes bytecode more compact on x86_64, and avoids bit twiddling on aarch64. Everyone wins something! When stringifying bytecode for debugging output, we now have an API in Executable that can look at a raw operand index and tell you what type of operand it was, based on known quantities of each type in the stack frame.
24 lines
537 B
C++
24 lines
537 B
C++
/*
|
|
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibJS/Bytecode/Generator.h>
|
|
#include <LibJS/Bytecode/ScopedOperand.h>
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
ScopedOperandImpl::~ScopedOperandImpl()
|
|
{
|
|
if (!m_generator.is_finished() && m_operand.is_register() && m_operand.as_register().index() >= Register::reserved_register_count)
|
|
m_generator.free_register(m_operand.as_register());
|
|
}
|
|
|
|
Register Operand::as_register() const
|
|
{
|
|
return Register { index() };
|
|
}
|
|
|
|
}
|