61 global.kind = Compiler_IR_Slot_Kind::Global;
63 module.global_slots.append(global);
67 function->name =
"choose";
68 function->entry_block = 0;
69 function->exit_block = 1;
70 function->next_value_id = 5;
74 flag.
kind = Compiler_IR_Slot_Kind::Parameter;
76 function->local_slots.append(flag);
80 value.kind = Compiler_IR_Slot_Kind::Local;
82 function->local_slots.append(
value);
86 entry.
label =
"entry";
89 zero.
kind = Compiler_IR_Instruction_Kind::Constant;
114 exit.terminator.kind = Compiler_IR_Terminator_Kind::Exit;
115 exit.predecessors.append(3);
122 one.
kind = Compiler_IR_Instruction_Kind::Constant;
133 then_block.terminator.kind = Compiler_IR_Terminator_Kind::Jump;
147 join_block.terminator.kind = Compiler_IR_Terminator_Kind::Return;
158 two.
kind = Compiler_IR_Instruction_Kind::Constant;
169 else_block.terminator.kind = Compiler_IR_Terminator_Kind::Jump;
173 function->blocks.append(entry);
174 function->blocks.append(
exit);
178 module.functions.append(function);
182 top->name =
"<top-level>";
183 top->entry_block = 0;
185 top->next_value_id = 3;
205 call.
kind = Compiler_IR_Instruction_Kind::Call;
217 top_entry.terminator.kind = Compiler_IR_Terminator_Kind::Jump;
218 top_entry.terminator.successors.append(1);
225 module.top_level = top;
248 auto module = make_demo_module();
255 std::cout <<
"Validation errors:\n";
256 for (
size_t i = 0; i <
report.errors.size(); ++i)
257 std::cout <<
"- " <<
report.errors.access(i) <<
'\n';
258 delete module.functions.access(0);
259 delete module.top_level;
264 const auto top_level =
vm.run_top_level();
272 std::cout <<
'\n' <<
vm.dump_globals();
274 delete module.functions.access(0);
275 delete module.top_level;
Simple portable VM for executing the register bytecode in Bytecode.H.
size_t size_t int32_t value
Arena-backed ownership context for bytecode functions and modules.
Lowers explicit IR into register-based bytecode.
Small portable VM for executing one Compiler_Bytecode_Module.
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().
void print_result(const string &label, const Multipoly &poly)
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.
and
Check uniqueness with explicit hash + equality functors.
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.
std::string compiler_bytecode_value_to_string(const Compiler_Bytecode_Value &value, const Compiler_Bytecode_Module *module=nullptr)
Renders one bytecode value deterministically.
const char * compiler_bytecode_completion_kind_name(const Compiler_Bytecode_Completion_Kind kind) noexcept
Stable debug name for one execution completion kind.
Result of one bytecode execution request.
Compiler_Bytecode_Runtime_Error error
Structured failure when kind == Runtime_Error.
size_t executed_instructions
Number of bytecode instructions observed by the VM.
bool ok() const noexcept
Returns whether execution completed without runtime errors.
Compiler_Bytecode_Completion_Kind kind
Final completion category.
Compiler_Bytecode_Value value
Produced return value or final Unit.
Bytecode module sharing global slot layout with the source IR module.
std::string message
Human-readable runtime message.
std::string code
Stable runtime code such as BCV013.
static Compiler_Bytecode_Value make_bool(const bool value)
Builds a boolean runtime value.
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.
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.