2021-06-03 10:46:30 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibJS/Bytecode/Block.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 {
|
|
|
|
|
|
|
|
NonnullOwnPtr<Block> Block::create()
|
|
|
|
{
|
|
|
|
return adopt_own(*new Block);
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::~Block()
|
|
|
|
{
|
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-07 15:12:43 +02:00
|
|
|
void Block::dump() const
|
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()) {
|
|
|
|
warnln("[{:4x}] {}", it.offset(), (*it).to_string());
|
|
|
|
++it;
|
|
|
|
}
|
2021-06-03 10:46:30 +02:00
|
|
|
}
|
|
|
|
|
2021-06-07 15:12:43 +02:00
|
|
|
void InstructionStreamIterator::operator++()
|
|
|
|
{
|
|
|
|
m_offset += dereference().length();
|
2021-06-03 10:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|