51 global.kind = Compiler_IR_Slot_Kind::Global;
53 module.global_slots.append(global);
57 function->name =
"choose";
58 function->entry_block = 0;
59 function->exit_block = 1;
60 function->next_value_id = 5;
64 flag.
kind = Compiler_IR_Slot_Kind::Parameter;
66 function->local_slots.append(flag);
70 value.kind = Compiler_IR_Slot_Kind::Local;
72 function->local_slots.append(
value);
76 entry.
label =
"entry";
79 zero.
kind = Compiler_IR_Instruction_Kind::Constant;
104 exit.terminator.kind = Compiler_IR_Terminator_Kind::Exit;
105 exit.predecessors.append(3);
112 one.
kind = Compiler_IR_Instruction_Kind::Constant;
123 then_block.terminator.kind = Compiler_IR_Terminator_Kind::Jump;
137 join_block.terminator.kind = Compiler_IR_Terminator_Kind::Return;
148 two.
kind = Compiler_IR_Instruction_Kind::Constant;
159 else_block.terminator.kind = Compiler_IR_Terminator_Kind::Jump;
163 function->blocks.append(entry);
164 function->blocks.append(
exit);
168 module.functions.append(function);
172 top->name =
"<top-level>";
173 top->entry_block = 0;
175 top->next_value_id = 3;
195 call.
kind = Compiler_IR_Instruction_Kind::Call;
207 top_entry.terminator.kind = Compiler_IR_Terminator_Kind::Jump;
208 top_entry.terminator.successors.append(1);
213 top_exit.terminator.kind = Compiler_IR_Terminator_Kind::Exit;
218 module.top_level = top;
228 auto module = make_demo_module();
235 std::cout <<
"\nWarnings:\n";
236 for (
size_t i = 0; i <
report.warnings.size(); ++i)
237 std::cout <<
"- " <<
report.warnings.access(i) <<
'\n';
240 delete module.functions.access(0);
241 delete module.top_level;
242 return report.valid ? 0 : 1;
Reusable bytecode format and lowering from Compiler_IR_Model.H.
size_t size_t int32_t value
Arena-backed ownership context for bytecode functions and modules.
Lowers explicit IR into register-based bytecode.
T & append()
Allocate a new entry to the end of array.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
void exit(const char *file, int line, const char *format,...)
Print a message and exit the program.
std::string compiler_dump_bytecode_module(const Compiler_Bytecode_Module *module, const Compiler_Type_Context *types=nullptr)
Dumps all lowered bytecode in one module deterministically.
constexpr size_t compiler_ir_invalid_id() noexcept
Returns the sentinel invalid IR id.
Compiler_Bytecode_Validation_Report validate_bytecode_module(const Compiler_Bytecode_Module &module)
Validates all bytecode functions in one module.
One basic block of IR instructions.
std::string label
Deterministic debug label.
Compiler_IR_Terminator terminator
Explicit block terminator.
DynArray< Compiler_IR_Instruction > instructions
Linear instruction list.
Compiler_IR_Block_Id id
Stable block id.
Lowered IR for one function or top-level body.
One instruction producing an optional explicit result value.
std::string text
Constant spelling or debug payload.
Compiler_IR_Instruction_Kind kind
Instruction category.
Compiler_IR_Value_Id result_id
Produced value id, or 0 for void instructions.
DynArray< Compiler_IR_Value_Id > operands
Input values in deterministic order.
Lowered IR module with shared global slots and functions.
One storage slot used by the IR.
std::string name
Debug name of the slot.
size_t id
Stable slot id within its storage space.
Compiler_IR_Slot_Kind kind
Slot storage category.
Compiler_IR_Terminator_Kind kind
Terminator category.
DynArray< Compiler_IR_Block_Id > successors
Successor blocks in deterministic order.
Compiler_IR_Value_Id condition_value
Branch condition value, if any.