1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:37:35 +00:00

LibJS/Bytecode: Make NewPrimitiveArray a variable-length instruction

Instead of having a FixedArray with a separate heap allocation, we can
just bake the primitive values into the instruction itself.
This commit is contained in:
Andreas Kling 2024-03-03 12:37:28 +01:00
parent 5813df21c8
commit 60a555e364
4 changed files with 44 additions and 13 deletions

View file

@ -81,12 +81,12 @@ public:
op->set_source_record({ m_current_ast_node->start_offset(), m_current_ast_node->end_offset() });
}
template<typename OpType, typename... Args>
void emit_with_extra_operand_slots(size_t extra_operand_slots, Args&&... args)
template<typename OpType, typename ExtraSlotType, typename... Args>
void emit_with_extra_slots(size_t extra_slot_count, Args&&... args)
{
VERIFY(!is_current_block_terminated());
size_t size_to_allocate = round_up_to_power_of_two(sizeof(OpType) + extra_operand_slots * sizeof(Operand), alignof(void*));
size_t size_to_allocate = round_up_to_power_of_two(sizeof(OpType) + extra_slot_count * sizeof(ExtraSlotType), alignof(void*));
size_t slot_offset = m_current_basic_block->size();
grow(size_to_allocate);
void* slot = m_current_basic_block->data() + slot_offset;
@ -97,6 +97,18 @@ public:
op->set_source_record({ m_current_ast_node->start_offset(), m_current_ast_node->end_offset() });
}
template<typename OpType, typename... Args>
void emit_with_extra_operand_slots(size_t extra_operand_slots, Args&&... args)
{
emit_with_extra_slots<OpType, Operand>(extra_operand_slots, forward<Args>(args)...);
}
template<typename OpType, typename... Args>
void emit_with_extra_value_slots(size_t extra_operand_slots, Args&&... args)
{
emit_with_extra_slots<OpType, Value>(extra_operand_slots, forward<Args>(args)...);
}
struct ReferenceOperands {
Optional<Operand> base {}; // [[Base]]
Optional<Operand> referenced_name {}; // [[ReferencedName]] as an operand