1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:58:11 +00:00

LibJS: Create static unwind mappings for BasicBlocks

This is currently only used in the bytecode dump to annotate to where
unwinds lead per block, but will be hooked up to the virtual machine in
the next commit.
This commit is contained in:
Hendiadyoin1 2023-10-19 23:18:54 +02:00 committed by Andreas Kling
parent 647f0ccd3f
commit 73f347b75c
6 changed files with 92 additions and 6 deletions

View file

@ -44,6 +44,24 @@ public:
ASTNode const* m_previous_node { nullptr };
};
class UnwindContext {
public:
UnwindContext(Generator&, Optional<Label> finalizer);
UnwindContext const* previous() const { return m_previous_context; }
void set_handler(Label handler) { m_handler = handler; }
Optional<Label> handler() const { return m_handler; }
Optional<Label> finalizer() const { return m_finalizer; }
~UnwindContext();
private:
Generator& m_generator;
Optional<Label> m_finalizer;
Optional<Label> m_handler {};
UnwindContext const* m_previous_context { nullptr };
};
template<typename OpType, typename... Args>
void emit(Args&&... args)
{
@ -114,7 +132,14 @@ public:
{
if (name.is_empty())
name = DeprecatedString::number(m_next_block++);
m_root_basic_blocks.append(BasicBlock::create(name));
auto block = BasicBlock::create(name);
if (auto const* context = m_current_unwind_context) {
if (context->handler().has_value())
block->set_handler(context->handler().value().block());
if (m_current_unwind_context->finalizer().has_value())
block->set_finalizer(context->finalizer().value().block());
}
m_root_basic_blocks.append(move(block));
return *m_root_basic_blocks.last();
}
@ -228,6 +253,8 @@ private:
BasicBlock* m_current_basic_block { nullptr };
ASTNode const* m_current_ast_node { nullptr };
UnwindContext const* m_current_unwind_context { nullptr };
Vector<NonnullOwnPtr<BasicBlock>> m_root_basic_blocks;
NonnullOwnPtr<StringTable> m_string_table;
NonnullOwnPtr<IdentifierTable> m_identifier_table;