stage1 人工重构ast.c

This commit is contained in:
zzy
2026-08-12 10:29:38 +08:00
parent 314100afbc
commit b0e6b406ac
22 changed files with 1619 additions and 2895 deletions

View File

@@ -2,8 +2,10 @@
#define __SPL_IR_H__
#include "../stage0/include/utils.h"
#include "spl_dbg.h"
#include "spl_type.h"
/* clang-format off */
#define SPL_IR_FN_TABLE \
X(arith.add, V0, SPL_IR_ARITH_ADD) \
@@ -91,7 +93,7 @@ typedef usize spl_ir_func_ref_t; /* 0 is error */
typedef struct {
spl_ir_kind_t kind;
usize src_ref; /* AST 节点 ref调试行号用ast2ir 注解) */
spl_dbg_node_t dbg;
union {
struct {
spl_type_id_t tid;
@@ -238,24 +240,12 @@ typedef struct {
} spl_ir_attr_t;
typedef VEC(spl_ir_attr_t) spl_ir_attr_vec_t;
/* 调试:函数内变量(名 → 内存位置。alloca 节点或参数槽。 */
typedef struct {
const char *name; /* 指向 AST 字符串,不拥有 */
spl_ir_node_ref_t alloca; /* 非参数alloca 节点 ref */
spl_type_id_t tid;
int is_param; /* 参数则用 param_idx */
usize param_idx;
usize offset; /* fp 字节偏移LADDR imm 语义ir2vm 填) */
} spl_ir_dbg_var_t;
typedef VEC(spl_ir_dbg_var_t) spl_ir_dbg_var_vec_t;
typedef struct {
const char *name;
spl_ir_attr_t attr;
spl_type_id_t fn_tid;
spl_ir_node_vec_t nodes;
spl_ir_node_ref_vec_t labels;
spl_ir_dbg_var_vec_t dbg_vars; /* 调试变量表fp 偏移在 ir2vm 填) */
} spl_ir_func_t;
typedef VEC(spl_ir_func_t) spl_ir_func_vec_t;