stage1 实现并修复ast2ir的核心功能的正确性

This commit is contained in:
zzy committed 2026-09-12 09:46:56 +08:00
1 parent 49ccdec3dd
commit 87d9b7ea34
7 files changed
+1408 -110

No files matched your search

+15 -5
View File
@@ -315,12 +315,16 @@ static spl_ir_node_ref_t builder_alloc_node(spl_ir_builder_t *b, spl_ir_kind_t k
spl_ir_node_t *n = spl_ir_node(&b->ir, b->current_fn, ref);
n->kind = kind;
n->dbg = b->dbg;
if (b->current_block < vec_size(b->blocks)) {
vec_at(b->blocks, b->current_block) = ref;
} else {
if (b->current_block >= vec_size(b->blocks)) {
Panic("unknown bblock");
return 0;
}
spl_ir_node_ref_t *slot = &vec_at(b->blocks, b->current_block);
if (*slot == 0)
*slot = ref;
return ref;
}
@@ -378,7 +382,7 @@ void spl_ir_builder_fn_end(spl_ir_builder_t *b) {
target = vec_at(b->blocks, fx->block);
}
if (target == 0) {
Panic("unknown reloc target bblock");
Panic("reloc to empty/unknown bblock #%zu", fx->block);
}
switch (fx->slot) {
case SPL_IR_FIX_BR_TRUE:
@@ -411,6 +415,10 @@ void spl_ir_builder_block_end(spl_ir_builder_t *b) {
if (!b->terminated) {
Panic("bblock must be end of terminated");
}
if (b->current_block != 0 && b->current_block < vec_size(b->blocks) &&
vec_at(b->blocks, b->current_block) == 0) {
Panic("bblock #%zu is empty (no entry node emitted)", b->current_block);
}
}
#define X(name, kind) \
@@ -769,7 +777,9 @@ spl_ir_node_ref_t spl_ir_builder_control_ret(spl_ir_builder_t *b, spl_type_id_t
}
spl_ir_node_ref_t spl_ir_builder_control_unreachable(spl_ir_builder_t *b) {
return builder_alloc_node(b, SPL_IR_CONTROL_UNREACHABLE);
spl_ir_node_ref_t ref = builder_alloc_node(b, SPL_IR_CONTROL_UNREACHABLE);
b->terminated = true;
return ref;
}
spl_ir_node_ref_t spl_ir_builder_control_trap(spl_ir_builder_t *b) {