stage2 修复大量AI生成的风格问题 stage1 修复对于vm abi的错误生成

This commit is contained in:
zzy committed 2026-10-03 15:05:55 +08:00
1 parent 0e38858785
commit 76f980654c
40 files changed
+619 -938

No files matched your search

+9 -16
View File
@@ -1,10 +1,7 @@
// Expect retcode = 0
// SIR 中间表示(移植自 stage1/spl_ir.c/.h)。节点用 arena 序号引用(0 = error),
// 按函数分桶。节点公共字段(kind/dbg/attrs)在外层 entry,kind 专属载荷在 ADT
// IrBody;kind 与载荷变体一一对应(多种 kind 可共享同一载荷形状)。
//
// builder 维护当前函数/基本块/fixup 表,负责发射节点与回填跳转。
// SIR 中间表示:节点用 arena 序号引用(0=error),按函数分桶;公共字段在 IrEntry,
// kind 专属载荷在 IrBody ADT(kind 与载荷一一对应)。builder 负责发射与跳转回填。
type .{ .Error } = @import("utils/error.spl");
type .{ .Vec } = @import("utils/vec.spl");
@@ -138,7 +135,6 @@ type Ir = @self;
funcs: Vec, // IrFunc
globals: Vec, // Global
// ---- 生命周期 ----
fn new_entry(): IrEntry {
ret IrEntry {
@@ -159,8 +155,8 @@ fn new(): Ir {
.nodes = Vec.blank(@sizeof(IrEntry), @alignof(IrEntry)),
};
var sn = new_entry();
match Vec.push(&sentinel.nodes, &sn as *u8) { .Ok => {}, .Err(error) => {} }
match Vec.push(&ir.funcs, &sentinel as *u8) { .Ok => {}, .Err(error) => {} }
Vec.push(&sentinel.nodes, &sn as *u8);
Vec.push(&ir.funcs, &sentinel as *u8);
ret ir;
}
@@ -307,7 +303,6 @@ fn kind_name(kind: IrKind): []u8 {
ret "?";
}
// ---- dump ----
fn out_str(out: *ByteBuffer, s: []u8): bool {
match ByteBuffer.append(out, s) { .Ok => { ret true; }, .Err(error) => { ret false; } }
@@ -360,11 +355,10 @@ fn dump_body(out: *ByteBuffer, ty: *TypeTable, e: *IrEntry): bool {
.Arith(a) => {
if !dump_type(out, ty, a.tid) { ret false; }
if !dump_ref(out, a.left) { ret false; }
// 一元 arith(neg/abs/not)不打印 right(镜像 stage1)。
if @enum2int(e.kind) == @enum2int(IrKind.ArithNeg) ||
@enum2int(e.kind) == @enum2int(IrKind.ArithAbs) ||
@enum2int(e.kind) == @enum2int(IrKind.ArithNot) {
ret true;
// 一元 arith(neg/abs/not)不打印 right。
match e.kind {
.ArithNeg, .ArithAbs, .ArithNot => { ret true; },
_ => {},
}
ret dump_ref(out, a.right);
},
@@ -465,7 +459,7 @@ fn dump_body(out: *ByteBuffer, ty: *TypeTable, e: *IrEntry): bool {
match ByteBuffer.append_byte(out, cv as u8) { .Ok => {}, .Err(error) => { ret false; } }
ret out_str(out, "'");
}
// stage1 对其他常量统一按 int_lit 打印(union 别名)。
// 其他常量统一按 int_lit 打印(union 别名)。
var iv: usize = 0;
match c.lit {
.Int(v) => { iv = v; },
@@ -582,7 +576,6 @@ fn dump(self: *Ir, ty: *TypeTable, attr: *Attr, out: *ByteBuffer): bool {
ret true;
}
// ---- 测试 ----
fn test_kinds() {
@assert(ByteView.eq(ByteView.from_slice(kind_name(.ArithAdd)), ByteView.from_slice("arith.add")),