48 std::unique_ptr<Compiler_IR_Function> function;
49 std::unique_ptr<Compiler_IR_Function> top_level;
66 auto &
module = demo.module;
70 global.kind = Compiler_IR_Slot_Kind::Global;
72 module.global_slots.append(global);
74 demo.function = std::make_unique<Compiler_IR_Function>();
75 auto * function =
demo.function.get();
77 function->name =
"add_one";
78 function->entry_block = 0;
79 function->exit_block = 1;
80 function->next_value_id = 4;
84 param.kind = Compiler_IR_Slot_Kind::Parameter;
86 function->local_slots.append(
param);
90 local.
kind = Compiler_IR_Slot_Kind::Local;
92 function->local_slots.append(local);
96 entry.
label =
"entry";
99 one.
kind = Compiler_IR_Instruction_Kind::Constant;
111 load_x.
kind = Compiler_IR_Instruction_Kind::Load;
123 add.kind = Compiler_IR_Instruction_Kind::Binary;
125 add.op = Compiler_Operator_Kind::Plus;
126 add.operands.append(2);
127 add.operands.append(3);
135 exit.predecessors.append(0);
137 function->blocks.append(entry);
138 function->blocks.append(
exit);
139 module.functions.append(function);
141 demo.top_level = std::make_unique<Compiler_IR_Function>();
142 auto * top =
demo.top_level.get();
144 top->name =
"<top-level>";
145 top->entry_block = 0;
147 top->next_value_id = 3;
166 call.
kind = Compiler_IR_Instruction_Kind::Call;
178 top_entry.terminator.kind = Compiler_IR_Terminator_Kind::Jump;
179 top_entry.terminator.successors.append(1);
186 module.top_level = top;
193 auto module = make_demo_module();
202 std::cerr <<
"Emission errors:\n";
203 for (
size_t i = 0; i <
emitted.errors.size(); ++i)
204 std::cerr <<
"- " <<
emitted.errors.access(i) <<
'\n';
211 std::cout <<
"\n/* Warnings:\n";
212 for (
size_t i = 0; i <
emitted.warnings.size(); ++i)
213 std::cout <<
" - " <<
emitted.warnings.access(i) <<
'\n';
Portable C backend that emits standalone C from Compiler_IR_Model.H.
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().
Compiler_SSA_Block & block(Compiler_SSA_Function &function, const Compiler_SSA_Block_Id id)
Main namespace for Aleph-w library functions.
void exit(const char *file, int line, const char *format,...)
Print a message and exit the program.
constexpr size_t compiler_ir_invalid_id() noexcept
Returns the sentinel invalid IR id.
Compiler_C_Backend_Emission compiler_emit_c_module(const Compiler_IR_Module *module, const Compiler_C_Backend_Options &options={}, const Compiler_Type_Context *types=nullptr)
Convenience wrapper that emits one IR module to portable C.
double add(double a, double b)
static struct argp_option options[]
Options that control one C backend emission request.
std::string module_name
Prefix used to derive stable C identifiers.
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.
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 return_value
Return value, if any.
Compiler_SSA_Block_Id id
Dense SSA block id.
std::string label
Deterministic debug label.
Compiler_SSA_Terminator terminator
Explicit block terminator.
Compiler_IR_Terminator_Kind kind
Terminator category.