|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Small reusable helper that allocates and connects IR nodes. More...
#include <Compiler_IR_Builder.H>
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 |
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.
|
inlineexplicitnoexcept |
Builds IR nodes inside context.
Definition at line 117 of file Compiler_IR_Builder.H.
|
inlinestaticprivate |
Definition at line 80 of file Compiler_IR_Builder.H.
References block(), and Aleph::Compiler_IR_Detail::contains_block_id().
|
inlinestatic |
Appends one global slot to module.
Definition at line 132 of file Compiler_IR_Builder.H.
Referenced by Aleph::Compiler_Line_Frontend::lower_ir(), main(), and TEST().
|
inlinestatic |
Appends one local or parameter slot to function.
Definition at line 185 of file Compiler_IR_Builder.H.
Referenced by Aleph::Compiler_Line_Frontend::lower_ir(), main(), and TEST().
|
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.
|
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 Aleph::Compiler_Line_Frontend::lower_ir(), main(), and TEST().
|
inlinestaticprivate |
Definition at line 92 of file Compiler_IR_Builder.H.
References ah_runtime_error_unless, block(), Aleph::Compiler_IR_Detail::block_name(), merge_function_span(), merge_span(), and Aleph::Compiler_IR_Instruction::span.
|
inlinestaticprivate |
Definition at line 68 of file Compiler_IR_Builder.H.
References ah_runtime_error_unless, and Aleph::Compiler_IR_Function::blocks.
Referenced by add_edge(), append_instruction(), set_entry_block(), and set_exit_block().
|
inlinenoexcept |
Returns the underlying ownership context.
Definition at line 120 of file Compiler_IR_Builder.H.
References ir_.
|
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::Compiler_IR_Block::id, and Aleph::Compiler_IR_Block::label.
Referenced by Aleph::Compiler_Line_Frontend::lower_ir(), main(), TEST(), TEST(), and TEST().
|
inlinestatic |
Emits one binary instruction.
Definition at line 348 of file Compiler_IR_Builder.H.
Referenced by Aleph::Compiler_Line_Frontend::lower_ir(), main(), and TEST().
|
inlinestatic |
Emits one call instruction.
Definition at line 388 of file Compiler_IR_Builder.H.
Referenced by Aleph::Compiler_Line_Frontend::lower_ir(), main(), and TEST().
|
inlinestatic |
Emits one constant instruction.
Definition at line 234 of file Compiler_IR_Builder.H.
Referenced by Aleph::Compiler_Line_Frontend::build_ir_operand(), Aleph::Compiler_Line_Frontend::lower_ir(), main(), and TEST().
|
inlinestatic |
Emits one function reference instruction.
Definition at line 370 of file Compiler_IR_Builder.H.
Referenced by Aleph::Compiler_Line_Frontend::lower_ir(), main(), and TEST().
|
inlinestatic |
Emits one load from a global slot.
Definition at line 274 of file Compiler_IR_Builder.H.
|
inlinestatic |
Emits one load from a local or parameter slot.
Definition at line 254 of file Compiler_IR_Builder.H.
Referenced by Aleph::Compiler_Line_Frontend::build_ir_operand(), main(), and TEST().
|
inlinestatic |
Emits one store into a global slot.
Definition at line 311 of file Compiler_IR_Builder.H.
Referenced by Aleph::Compiler_Line_Frontend::lower_ir(), main(), and TEST().
|
inlinestatic |
Emits one store into a local or parameter slot.
Definition at line 292 of file Compiler_IR_Builder.H.
|
inlinestatic |
Emits one unary instruction.
Definition at line 328 of file Compiler_IR_Builder.H.
|
inline |
Allocates one function without inserting it into a module.
Definition at line 148 of file Compiler_IR_Builder.H.
Referenced by Aleph::Compiler_Line_Frontend::lower_ir(), main(), TEST(), TEST(), and TEST().
|
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 Aleph::Compiler_Line_Frontend::lower_ir(), and main().
|
inlinestaticprivatenoexcept |
Definition at line 75 of file Compiler_IR_Builder.H.
References merge_span().
Referenced by append_instruction(), and set_terminator_span().
|
inlinestaticprivatenoexcept |
Definition at line 56 of file Compiler_IR_Builder.H.
References Aleph::compiler_hir_merge_spans().
Referenced by append_instruction(), merge_function_span(), and set_terminator_span().
|
inlinestatic |
Sets one conditional branch terminator and both outgoing edges.
Definition at line 424 of file Compiler_IR_Builder.H.
|
inlinestatic |
Marks one block as the canonical entry block.
Definition at line 213 of file Compiler_IR_Builder.H.
References block(), and Aleph::Compiler_IR_Function::entry_block.
Referenced by Aleph::Compiler_Line_Frontend::lower_ir(), main(), TEST(), and TEST().
|
inlinestatic |
Sets one block terminator to Exit.
Definition at line 461 of file Compiler_IR_Builder.H.
Referenced by Aleph::Compiler_Line_Frontend::lower_ir(), main(), TEST(), TEST(), and TEST().
|
inlinestatic |
Marks one block as the canonical exit block.
Definition at line 220 of file Compiler_IR_Builder.H.
References block(), and Aleph::Compiler_IR_Function::exit_block.
Referenced by Aleph::Compiler_Line_Frontend::lower_ir(), main(), TEST(), and TEST().
|
inlinestatic |
Sets one jump terminator and predecessor/successor edge.
Definition at line 409 of file Compiler_IR_Builder.H.
Referenced by Aleph::Compiler_Line_Frontend::lower_ir(), main(), TEST(), and TEST().
|
inlinestatic |
Sets one return terminator and connects it to the exit block.
Definition at line 444 of file Compiler_IR_Builder.H.
Referenced by Aleph::Compiler_Line_Frontend::lower_ir(), main(), and TEST().
|
inlinestaticprivatenoexcept |
Definition at line 106 of file Compiler_IR_Builder.H.
References merge_function_span(), and merge_span().
|
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 Aleph::Compiler_Line_Frontend::lower_ir(), main(), and TEST().
|
inlinestatic |
Marks one block as unreachable.
Definition at line 480 of file Compiler_IR_Builder.H.
|
private |
Definition at line 54 of file Compiler_IR_Builder.H.
Referenced by context(), and make_module().