2021-06-03 08:46:30 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
2021-06-03 08:46:30 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2023-10-27 03:57:51 +00:00
|
|
|
#include <AK/String.h>
|
2021-06-09 02:19:58 +00:00
|
|
|
#include <LibJS/Bytecode/BasicBlock.h>
|
2021-06-07 13:12:43 +00:00
|
|
|
#include <LibJS/Bytecode/Op.h>
|
2021-06-03 08:46:30 +00:00
|
|
|
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
|
2024-05-06 06:06:56 +00:00
|
|
|
NonnullOwnPtr<BasicBlock> BasicBlock::create(u32 index, String name)
|
2021-06-03 08:46:30 +00:00
|
|
|
{
|
2024-05-06 06:06:56 +00:00
|
|
|
return adopt_own(*new BasicBlock(index, move(name)));
|
2021-06-03 08:46:30 +00:00
|
|
|
}
|
|
|
|
|
2024-05-06 06:06:56 +00:00
|
|
|
BasicBlock::BasicBlock(u32 index, String name)
|
|
|
|
: m_index(index)
|
|
|
|
, m_name(move(name))
|
2021-06-08 22:50:42 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-09 02:19:58 +00:00
|
|
|
BasicBlock::~BasicBlock()
|
2021-06-03 08:46:30 +00:00
|
|
|
{
|
2021-06-07 13:12:43 +00:00
|
|
|
Bytecode::InstructionStreamIterator it(instruction_stream());
|
|
|
|
while (!it.at_end()) {
|
|
|
|
auto& to_destroy = (*it);
|
|
|
|
++it;
|
|
|
|
Instruction::destroy(const_cast<Instruction&>(to_destroy));
|
|
|
|
}
|
2021-06-07 13:24:33 +00:00
|
|
|
}
|
|
|
|
|
2021-06-09 02:19:58 +00:00
|
|
|
void BasicBlock::grow(size_t additional_size)
|
2021-06-08 22:50:42 +00:00
|
|
|
{
|
2023-09-30 07:33:11 +00:00
|
|
|
m_buffer.grow_capacity(m_buffer.size() + additional_size);
|
2023-09-28 07:29:42 +00:00
|
|
|
m_buffer.resize(m_buffer.size() + additional_size);
|
2021-06-08 22:50:42 +00:00
|
|
|
}
|
|
|
|
|
2021-06-03 08:46:30 +00:00
|
|
|
}
|