2021-06-03 10:46:30 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2023-10-26 23:57:51 -04:00
|
|
|
#include <AK/String.h>
|
2021-06-09 06:49:58 +04:30
|
|
|
#include <LibJS/Bytecode/BasicBlock.h>
|
2021-06-07 15:12:43 +02:00
|
|
|
#include <LibJS/Bytecode/Op.h>
|
2021-06-03 10:46:30 +02:00
|
|
|
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
|
2023-10-26 23:57:51 -04:00
|
|
|
NonnullOwnPtr<BasicBlock> BasicBlock::create(String name)
|
2021-06-03 10:46:30 +02:00
|
|
|
{
|
2023-09-28 09:29:42 +02:00
|
|
|
return adopt_own(*new BasicBlock(move(name)));
|
2021-06-03 10:46:30 +02:00
|
|
|
}
|
|
|
|
|
2023-10-26 23:57:51 -04:00
|
|
|
BasicBlock::BasicBlock(String name)
|
2021-06-09 06:49:58 +04:30
|
|
|
: m_name(move(name))
|
2021-06-09 00:50:42 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-09 06:49:58 +04:30
|
|
|
BasicBlock::~BasicBlock()
|
2021-06-03 10:46:30 +02:00
|
|
|
{
|
2021-06-07 15:12:43 +02: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 15:24:33 +02:00
|
|
|
}
|
|
|
|
|
2021-06-09 10:02:01 +02:00
|
|
|
void BasicBlock::dump(Bytecode::Executable const& executable) const
|
2021-06-03 10:46:30 +02:00
|
|
|
{
|
2021-06-07 15:12:43 +02:00
|
|
|
Bytecode::InstructionStreamIterator it(instruction_stream());
|
2023-10-19 23:18:54 +02:00
|
|
|
|
2021-06-09 06:49:58 +04:30
|
|
|
if (!m_name.is_empty())
|
2023-10-19 23:18:54 +02:00
|
|
|
warn("{}", m_name);
|
|
|
|
if (m_handler || m_finalizer) {
|
|
|
|
warn(" [");
|
|
|
|
if (m_handler)
|
|
|
|
warn(" Handler: {}", Label { *m_handler });
|
|
|
|
if (m_finalizer)
|
|
|
|
warn(" Finalizer: {}", Label { *m_finalizer });
|
|
|
|
warn(" ]");
|
|
|
|
}
|
|
|
|
warnln(":");
|
2021-06-07 15:12:43 +02:00
|
|
|
while (!it.at_end()) {
|
2022-12-06 01:12:49 +00:00
|
|
|
warnln("[{:4x}] {}", it.offset(), (*it).to_deprecated_string(executable));
|
2021-06-07 15:12:43 +02:00
|
|
|
++it;
|
|
|
|
}
|
2021-06-03 10:46:30 +02:00
|
|
|
}
|
|
|
|
|
2021-06-09 06:49:58 +04:30
|
|
|
void BasicBlock::grow(size_t additional_size)
|
2021-06-09 00:50:42 +02:00
|
|
|
{
|
2023-09-30 09:33:11 +02:00
|
|
|
m_buffer.grow_capacity(m_buffer.size() + additional_size);
|
2023-09-28 09:29:42 +02:00
|
|
|
m_buffer.resize(m_buffer.size() + additional_size);
|
2021-06-09 00:50:42 +02:00
|
|
|
}
|
|
|
|
|
2021-06-03 10:46:30 +02:00
|
|
|
}
|