Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Compiler_CFG.H File Reference

Basic-block CFG representation and lowering from structured HIR. More...

#include <limits>
#include <sstream>
#include <string>
#include <utility>
#include <Compiler_HIR_Model.H>
#include <ah-arena.H>
#include <ah-errors.H>
#include <tpl_dynArray.H>
Include dependency graph for Compiler_CFG.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Aleph::Compiler_CFG_Terminator
 Detailed information about a block's termination. More...
 
struct  Aleph::Compiler_CFG_Block
 Represents a single basic block in a CFG. More...
 
struct  Aleph::Compiler_CFG_Function
 CFG representation of a single function or top-level body. More...
 
struct  Aleph::Compiler_CFG_Module
 Aggregates all lowered CFGs for a compilation unit. More...
 
class  Aleph::Compiler_CFG_Context
 Arena-backed ownership context for CFG objects. More...
 
struct  Aleph::Compiler_CFG_Context::Owned_Object
 Internal tracker for objects with non-trivial destructors. More...
 
struct  Aleph::Compiler_CFG_Validation_Report
 Detailed results of a CFG structural validation. More...
 
class  Aleph::Compiler_CFG_Lowering
 Transformation engine that lowers typed HIR into reusable CFGs. More...
 
struct  Aleph::Compiler_CFG_Lowering::Loop_Targets
 Internal state for loop lowering. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 
namespace  Aleph::Compiler_CFG_Detail
 

Typedefs

using Aleph::Compiler_CFG_Block_Id = size_t
 Typedef for unique block identifiers within a function.
 

Enumerations

enum class  Aleph::Compiler_CFG_Terminator_Kind {
  Aleph::None , Aleph::Jump , Aleph::Branch , Aleph::Return ,
  Aleph::Exit , Aleph::Unreachable
}
 Categories of basic block terminators. More...
 

Functions

constexpr Compiler_CFG_Block_Id Aleph::compiler_cfg_invalid_block_id () noexcept
 Returns the sentinel value for an invalid block ID.
 
const char * Aleph::compiler_cfg_terminator_kind_name (const Compiler_CFG_Terminator_Kind kind) noexcept
 Returns a stable string name for a CFG terminator kind.
 
std::string Aleph::Compiler_CFG_Detail::block_name (const Compiler_CFG_Block_Id id)
 Generates a standard block label (e.g., "B0").
 
bool Aleph::Compiler_CFG_Detail::contains_block_id (const DynArray< Compiler_CFG_Block_Id > &ids, const Compiler_CFG_Block_Id id) noexcept
 Checks if a block ID is present in a list of IDs.
 
void Aleph::Compiler_CFG_Detail::append_indented_text (std::ostream &out, const std::string &text, const size_t indent)
 Appends text to a stream with a consistent indentation.
 
void Aleph::Compiler_CFG_Detail::append_hir_stmt_dump (std::ostream &out, const Compiler_HIR_Stmt *stmt, const Compiler_Type_Context *types, const size_t indent)
 Dumps a HIR statement to the stream for debugging.
 
void Aleph::Compiler_CFG_Detail::append_hir_expr_dump (std::ostream &out, const Compiler_HIR_Expr *expr, const Compiler_Type_Context *types, const size_t indent)
 Dumps a HIR expression to the stream for debugging.
 
bool Aleph::Compiler_CFG_Detail::is_linear_stmt (const Compiler_HIR_Stmt *stmt) noexcept
 Checks if an HIR statement is linear (non-branching).
 
Compiler_CFG_Validation_Report Aleph::validate_cfg_function (const Compiler_CFG_Function &function)
 Validates one lowered CFG function structurally.
 
Compiler_CFG_Validation_Report Aleph::validate_cfg_module (const Compiler_CFG_Module &module)
 Validates all CFGs in a lowered module.
 
std::string Aleph::compiler_dump_cfg_function (const Compiler_CFG_Function *function, const Compiler_Type_Context *types=nullptr)
 Dumps a single CFG function in text format for debugging.
 
std::string Aleph::compiler_dump_cfg_module (const Compiler_CFG_Module *module, const Compiler_Type_Context *types=nullptr)
 Dumps a complete CFG module in text format for debugging.
 

Detailed Description

Basic-block CFG representation and lowering from structured HIR.

This header introduces the first reusable control-flow graph (CFG) layer for the compiler-support platform. It sits after Compiler_HIR.H: HIR preserves structured control flow, while CFG makes branches, loops, exits, and joins explicit as basic blocks and terminators.

The current CFG layer includes:

  • Basic blocks with stable numeric identifiers.
  • Explicit terminators (Jump, Branch, Return, Exit, Unreachable).
  • Lowering from HIR functions and top-level HIR statements.
  • Successor and predecessor tracking for graph traversal.
  • Structural validation with deterministic diagnostics.
  • Plain-text dumps suitable for tests, docs, and debugging.

The MVP remains deliberately high-level. It does not yet introduce SSA, explicit temporaries, or a low-level IR. Its purpose is to provide a stable bridge between structured interpretation and later MIR/SSA passes.

Definition in file Compiler_CFG.H.