
This change removes the mmap inside of Block in favor of a growing vector of bytes. This is favorable for two reasons: - We don't take more space than we need - There is no limit to the growth of the vector (previously, if the Block overstepped its 64kb boundary, it would just crash) However, if that vector happens to resize, any pointer pointing into that vector would become invalid. To avoid this, this commit adds an InstructionHandle<Op> class which just stores a block and an offset into that block.
41 lines
813 B
C++
41 lines
813 B
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibJS/Bytecode/Block.h>
|
|
#include <LibJS/Bytecode/Op.h>
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
NonnullOwnPtr<Block> Block::create()
|
|
{
|
|
return adopt_own(*new Block);
|
|
}
|
|
|
|
Block::~Block()
|
|
{
|
|
Bytecode::InstructionStreamIterator it(instruction_stream());
|
|
while (!it.at_end()) {
|
|
auto& to_destroy = (*it);
|
|
++it;
|
|
Instruction::destroy(const_cast<Instruction&>(to_destroy));
|
|
}
|
|
}
|
|
|
|
void Block::dump() const
|
|
{
|
|
Bytecode::InstructionStreamIterator it(instruction_stream());
|
|
while (!it.at_end()) {
|
|
warnln("[{:4x}] {}", it.offset(), (*it).to_string());
|
|
++it;
|
|
}
|
|
}
|
|
|
|
void InstructionStreamIterator::operator++()
|
|
{
|
|
m_offset += dereference().length();
|
|
}
|
|
|
|
}
|