Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Compiler_IR_Builder Class Reference

Small reusable helper that allocates and connects IR nodes. More...

#include <Compiler_IR_Builder.H>

Collaboration diagram for Aleph::Compiler_IR_Builder:
[legend]

Public Member Functions

 Compiler_IR_Builder (Compiler_IR_Context &context) noexcept
 Builds IR nodes inside context.
 
Compiler_IR_Context & context () const noexcept
 Returns the underlying ownership context.
 
Compiler_IR_Module * make_module () const
 Allocates one empty IR module.
 
Compiler_IR_Function * make_function (std::string name, const Compiler_Type_Id type_id=0, const Source_Span &span={}, const Compiler_HIR_Function *source_function=nullptr) const
 Allocates one function without inserting it into a module.
 

Static Public Member Functions

static Compiler_IR_Global_Slot_Id add_global_slot (Compiler_IR_Module &module, std::string name, const Compiler_Type_Id type_id, const Source_Span &span={})
 Appends one global slot to module.
 
static Compiler_IR_Function_Id append_function (Compiler_IR_Module &module, Compiler_IR_Function *function)
 Appends one non-top-level function to module and assigns its id.
 
static Compiler_IR_Function * set_top_level (Compiler_IR_Module &module, Compiler_IR_Function *function)
 Installs one top-level function body in module.
 
static Compiler_IR_Local_Slot_Id add_local_slot (Compiler_IR_Function &function, const Compiler_IR_Slot_Kind kind, std::string name, const Compiler_Type_Id type_id, const Source_Span &span={})
 Appends one local or parameter slot to function.
 
static Compiler_IR_Block_Id create_block (Compiler_IR_Function &function, std::string label)
 Creates one empty block and returns its id.
 
static void set_entry_block (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id)
 Marks one block as the canonical entry block.
 
static void set_exit_block (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id)
 Marks one block as the canonical exit block.
 
static Compiler_IR_Value_Id allocate_value (Compiler_IR_Function &function) noexcept
 Allocates the next explicit IR value id in function.
 
static Compiler_IR_Value_Id emit_constant (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id, const Compiler_Type_Id type_id, std::string text, const Source_Span &span={}, const bool bool_value=false)
 Emits one constant instruction.
 
static Compiler_IR_Value_Id emit_load_local (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id, const Compiler_IR_Local_Slot_Id slot_id, const Compiler_Type_Id type_id, const Source_Span &span={})
 Emits one load from a local or parameter slot.
 
static Compiler_IR_Value_Id emit_load_global (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id, const Compiler_IR_Global_Slot_Id slot_id, const Compiler_Type_Id type_id, const Source_Span &span={})
 Emits one load from a global slot.
 
static void emit_store_local (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id, const Compiler_IR_Local_Slot_Id slot_id, const Compiler_IR_Value_Id value_id, const Compiler_Type_Id type_id, const Source_Span &span={})
 Emits one store into a local or parameter slot.
 
static void emit_store_global (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id, const Compiler_IR_Global_Slot_Id slot_id, const Compiler_IR_Value_Id value_id, const Compiler_Type_Id type_id, const Source_Span &span={})
 Emits one store into a global slot.
 
static Compiler_IR_Value_Id emit_unary (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id, const Compiler_Operator_Kind op, const Compiler_IR_Value_Id operand, const Compiler_Type_Id type_id, const Source_Span &span={})
 Emits one unary instruction.
 
static Compiler_IR_Value_Id emit_binary (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id, const Compiler_Operator_Kind op, const Compiler_IR_Value_Id lhs, const Compiler_IR_Value_Id rhs, const Compiler_Type_Id type_id, const Source_Span &span={})
 Emits one binary instruction.
 
static Compiler_IR_Value_Id emit_function_ref (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id, const Compiler_IR_Function_Id function_id, const Compiler_Type_Id type_id, const Source_Span &span={})
 Emits one function reference instruction.
 
static Compiler_IR_Value_Id emit_call (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id, const Compiler_IR_Value_Id callee, const DynArray< Compiler_IR_Value_Id > &arguments, const Compiler_Type_Id type_id, const Source_Span &span={})
 Emits one call instruction.
 
static void set_jump (Compiler_IR_Function &function, const Compiler_IR_Block_Id from, const Compiler_IR_Block_Id to, const Source_Span &span={})
 Sets one jump terminator and predecessor/successor edge.
 
static void set_branch (Compiler_IR_Function &function, const Compiler_IR_Block_Id from, const Compiler_IR_Value_Id condition_value, const Compiler_IR_Block_Id then_block, const Compiler_IR_Block_Id else_block, const Source_Span &span={})
 Sets one conditional branch terminator and both outgoing edges.
 
static void set_return (Compiler_IR_Function &function, const Compiler_IR_Block_Id from, const Compiler_IR_Value_Id return_value, const Source_Span &span={})
 Sets one return terminator and connects it to the exit block.
 
static void set_exit (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id, const Source_Span &span={})
 Sets one block terminator to Exit.
 
static void set_unreachable (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id, const Source_Span &span={})
 Marks one block as unreachable.
 

Static Private Member Functions

static void merge_span (Source_Span &dst, const Source_Span &src) noexcept
 
static Compiler_IR_Block & block (Compiler_IR_Function &function, const Compiler_IR_Block_Id id)
 
static void merge_function_span (Compiler_IR_Function &function, const Source_Span &span) noexcept
 
static void add_edge (Compiler_IR_Function &function, const Compiler_IR_Block_Id from, const Compiler_IR_Block_Id to)
 
static Compiler_IR_Instruction & append_instruction (Compiler_IR_Function &function, const Compiler_IR_Block_Id block_id, Compiler_IR_Instruction instruction)
 
static void set_terminator_span (Compiler_IR_Function &function, Compiler_IR_Block &blk, const Source_Span &span) noexcept
 

Private Attributes

Compiler_IR_Context * ir_ = nullptr
 

Detailed Description

Small reusable helper that allocates and connects IR nodes.

The builder keeps block successors, predecessor lists, and aggregate spans in sync while reusing an external Compiler_IR_Context for ownership.

Definition at line 52 of file Compiler_IR_Builder.H.

Constructor & Destructor Documentation

◆ Compiler_IR_Builder()

Aleph::Compiler_IR_Builder::Compiler_IR_Builder ( Compiler_IR_Context &  context)
inlineexplicitnoexcept

Builds IR nodes inside context.

Definition at line 117 of file Compiler_IR_Builder.H.

Member Function Documentation

◆ add_edge()

static void Aleph::Compiler_IR_Builder::add_edge ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  from,
const Compiler_IR_Block_Id  to 
)
inlinestaticprivate

◆ add_global_slot()

static Compiler_IR_Global_Slot_Id Aleph::Compiler_IR_Builder::add_global_slot ( Compiler_IR_Module &  module,
std::string  name,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
)
inlinestatic

Appends one global slot to module.

Definition at line 132 of file Compiler_IR_Builder.H.

Referenced by main(), and TEST().

◆ add_local_slot()

static Compiler_IR_Local_Slot_Id Aleph::Compiler_IR_Builder::add_local_slot ( Compiler_IR_Function &  function,
const Compiler_IR_Slot_Kind  kind,
std::string  name,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
)
inlinestatic

Appends one local or parameter slot to function.

Definition at line 185 of file Compiler_IR_Builder.H.

Referenced by main(), and TEST().

◆ allocate_value()

static Compiler_IR_Value_Id Aleph::Compiler_IR_Builder::allocate_value ( Compiler_IR_Function &  function)
inlinestaticnoexcept

Allocates the next explicit IR value id in function.

Definition at line 227 of file Compiler_IR_Builder.H.

References Aleph::Compiler_IR_Function::next_value_id.

◆ append_function()

static Compiler_IR_Function_Id Aleph::Compiler_IR_Builder::append_function ( Compiler_IR_Module &  module,
Compiler_IR_Function *  function 
)
inlinestatic

Appends one non-top-level function to module and assigns its id.

Definition at line 163 of file Compiler_IR_Builder.H.

References ah_runtime_error_unless, and Aleph::Compiler_IR_Function::id.

Referenced by main(), and TEST().

◆ append_instruction()

◆ block()

static Compiler_IR_Block & Aleph::Compiler_IR_Builder::block ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  id 
)
inlinestaticprivate

◆ context()

Compiler_IR_Context & Aleph::Compiler_IR_Builder::context ( ) const
inlinenoexcept

Returns the underlying ownership context.

Definition at line 120 of file Compiler_IR_Builder.H.

References ir_.

◆ create_block()

static Compiler_IR_Block_Id Aleph::Compiler_IR_Builder::create_block ( Compiler_IR_Function &  function,
std::string  label 
)
inlinestatic

Creates one empty block and returns its id.

Definition at line 203 of file Compiler_IR_Builder.H.

References Aleph::Compiler_IR_Function::blocks, Aleph::blossom_maximum_cardinality_matching(), and Aleph::Compiler_IR_Block::id.

Referenced by main(), TEST(), TEST(), and TEST().

◆ emit_binary()

static Compiler_IR_Value_Id Aleph::Compiler_IR_Builder::emit_binary ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  block_id,
const Compiler_Operator_Kind  op,
const Compiler_IR_Value_Id  lhs,
const Compiler_IR_Value_Id  rhs,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
)
inlinestatic

Emits one binary instruction.

Definition at line 348 of file Compiler_IR_Builder.H.

Referenced by main(), and TEST().

◆ emit_call()

static Compiler_IR_Value_Id Aleph::Compiler_IR_Builder::emit_call ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  block_id,
const Compiler_IR_Value_Id  callee,
const DynArray< Compiler_IR_Value_Id > &  arguments,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
)
inlinestatic

Emits one call instruction.

Definition at line 388 of file Compiler_IR_Builder.H.

Referenced by main(), and TEST().

◆ emit_constant()

static Compiler_IR_Value_Id Aleph::Compiler_IR_Builder::emit_constant ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  block_id,
const Compiler_Type_Id  type_id,
std::string  text,
const Source_Span &  span = {},
const bool  bool_value = false 
)
inlinestatic

Emits one constant instruction.

Definition at line 234 of file Compiler_IR_Builder.H.

Referenced by main(), and TEST().

◆ emit_function_ref()

static Compiler_IR_Value_Id Aleph::Compiler_IR_Builder::emit_function_ref ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  block_id,
const Compiler_IR_Function_Id  function_id,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
)
inlinestatic

Emits one function reference instruction.

Definition at line 370 of file Compiler_IR_Builder.H.

Referenced by main(), and TEST().

◆ emit_load_global()

static Compiler_IR_Value_Id Aleph::Compiler_IR_Builder::emit_load_global ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  block_id,
const Compiler_IR_Global_Slot_Id  slot_id,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
)
inlinestatic

Emits one load from a global slot.

Definition at line 274 of file Compiler_IR_Builder.H.

◆ emit_load_local()

static Compiler_IR_Value_Id Aleph::Compiler_IR_Builder::emit_load_local ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  block_id,
const Compiler_IR_Local_Slot_Id  slot_id,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
)
inlinestatic

Emits one load from a local or parameter slot.

Definition at line 254 of file Compiler_IR_Builder.H.

Referenced by main(), and TEST().

◆ emit_store_global()

static void Aleph::Compiler_IR_Builder::emit_store_global ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  block_id,
const Compiler_IR_Global_Slot_Id  slot_id,
const Compiler_IR_Value_Id  value_id,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
)
inlinestatic

Emits one store into a global slot.

Definition at line 311 of file Compiler_IR_Builder.H.

Referenced by main(), and TEST().

◆ emit_store_local()

static void Aleph::Compiler_IR_Builder::emit_store_local ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  block_id,
const Compiler_IR_Local_Slot_Id  slot_id,
const Compiler_IR_Value_Id  value_id,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
)
inlinestatic

Emits one store into a local or parameter slot.

Definition at line 292 of file Compiler_IR_Builder.H.

◆ emit_unary()

static Compiler_IR_Value_Id Aleph::Compiler_IR_Builder::emit_unary ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  block_id,
const Compiler_Operator_Kind  op,
const Compiler_IR_Value_Id  operand,
const Compiler_Type_Id  type_id,
const Source_Span &  span = {} 
)
inlinestatic

Emits one unary instruction.

Definition at line 328 of file Compiler_IR_Builder.H.

◆ make_function()

Compiler_IR_Function * Aleph::Compiler_IR_Builder::make_function ( std::string  name,
const Compiler_Type_Id  type_id = 0,
const Source_Span &  span = {},
const Compiler_HIR_Function *  source_function = nullptr 
) const
inline

Allocates one function without inserting it into a module.

Definition at line 148 of file Compiler_IR_Builder.H.

Referenced by main(), TEST(), TEST(), and TEST().

◆ make_module()

Compiler_IR_Module * Aleph::Compiler_IR_Builder::make_module ( ) const
inline

Allocates one empty IR module.

Definition at line 126 of file Compiler_IR_Builder.H.

References ir_, and Aleph::Compiler_IR_Context::make().

Referenced by main().

◆ merge_function_span()

static void Aleph::Compiler_IR_Builder::merge_function_span ( Compiler_IR_Function &  function,
const Source_Span &  span 
)
inlinestaticprivatenoexcept

Definition at line 75 of file Compiler_IR_Builder.H.

References merge_span().

Referenced by append_instruction(), and set_terminator_span().

◆ merge_span()

static void Aleph::Compiler_IR_Builder::merge_span ( Source_Span &  dst,
const Source_Span &  src 
)
inlinestaticprivatenoexcept

◆ set_branch()

static void Aleph::Compiler_IR_Builder::set_branch ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  from,
const Compiler_IR_Value_Id  condition_value,
const Compiler_IR_Block_Id  then_block,
const Compiler_IR_Block_Id  else_block,
const Source_Span &  span = {} 
)
inlinestatic

Sets one conditional branch terminator and both outgoing edges.

Definition at line 424 of file Compiler_IR_Builder.H.

◆ set_entry_block()

static void Aleph::Compiler_IR_Builder::set_entry_block ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  block_id 
)
inlinestatic

Marks one block as the canonical entry block.

Definition at line 213 of file Compiler_IR_Builder.H.

References block(), Aleph::blossom_maximum_cardinality_matching(), and Aleph::Compiler_IR_Function::entry_block.

Referenced by main(), TEST(), and TEST().

◆ set_exit()

static void Aleph::Compiler_IR_Builder::set_exit ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  block_id,
const Source_Span &  span = {} 
)
inlinestatic

Sets one block terminator to Exit.

Definition at line 461 of file Compiler_IR_Builder.H.

Referenced by main(), TEST(), TEST(), and TEST().

◆ set_exit_block()

static void Aleph::Compiler_IR_Builder::set_exit_block ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  block_id 
)
inlinestatic

Marks one block as the canonical exit block.

Definition at line 220 of file Compiler_IR_Builder.H.

References block(), Aleph::blossom_maximum_cardinality_matching(), and Aleph::Compiler_IR_Function::exit_block.

Referenced by main(), TEST(), and TEST().

◆ set_jump()

static void Aleph::Compiler_IR_Builder::set_jump ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  from,
const Compiler_IR_Block_Id  to,
const Source_Span &  span = {} 
)
inlinestatic

Sets one jump terminator and predecessor/successor edge.

Definition at line 409 of file Compiler_IR_Builder.H.

Referenced by main(), TEST(), and TEST().

◆ set_return()

static void Aleph::Compiler_IR_Builder::set_return ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  from,
const Compiler_IR_Value_Id  return_value,
const Source_Span &  span = {} 
)
inlinestatic

Sets one return terminator and connects it to the exit block.

Definition at line 444 of file Compiler_IR_Builder.H.

Referenced by main(), and TEST().

◆ set_terminator_span()

static void Aleph::Compiler_IR_Builder::set_terminator_span ( Compiler_IR_Function &  function,
Compiler_IR_Block &  blk,
const Source_Span &  span 
)
inlinestaticprivatenoexcept

◆ set_top_level()

static Compiler_IR_Function * Aleph::Compiler_IR_Builder::set_top_level ( Compiler_IR_Module &  module,
Compiler_IR_Function *  function 
)
inlinestatic

Installs one top-level function body in module.

Definition at line 174 of file Compiler_IR_Builder.H.

References ah_runtime_error_unless, Aleph::compiler_ir_invalid_id(), and Aleph::Compiler_IR_Function::id.

Referenced by main(), and TEST().

◆ set_unreachable()

static void Aleph::Compiler_IR_Builder::set_unreachable ( Compiler_IR_Function &  function,
const Compiler_IR_Block_Id  block_id,
const Source_Span &  span = {} 
)
inlinestatic

Marks one block as unreachable.

Definition at line 478 of file Compiler_IR_Builder.H.

Member Data Documentation

◆ ir_

Compiler_IR_Context* Aleph::Compiler_IR_Builder::ir_ = nullptr
private

Definition at line 54 of file Compiler_IR_Builder.H.

Referenced by context(), and make_module().


The documentation for this class was generated from the following file: