1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-04 12:07:35 +00:00

JSSpecCompiler: Add --dump-cfg option

This commit is contained in:
Dan Klishch 2023-10-01 23:30:43 -04:00 committed by Andrew Kaster
parent ff44aea917
commit ce6b987330
4 changed files with 53 additions and 0 deletions

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2023, Dan Klishch <danilklishch@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/StringBuilder.h>
#include "AST/AST.h"
#include "Compiler/ControlFlowGraph.h"
using namespace JSSpecCompiler;
ErrorOr<void> AK::Formatter<ControlFlowGraph>::format(FormatBuilder& format_builder, ControlFlowGraph const& control_flow_graph)
{
auto& builder = format_builder.builder();
for (auto const& block : control_flow_graph.blocks) {
builder.appendff("{}:\n", block->m_index);
for (auto const& expression : block->m_expressions)
builder.appendff("{}", expression);
builder.appendff("{}\n", Tree(block->m_continuation));
}
// Remove trailing \n
builder.trim(1);
return {};
}