feat(ast2ir): 添加AST上下文支持并修复类型转换逻辑

- 在scc_ast2ir_ctx_t中添加ast_ctx字段用于访问AST上下文
- 修改scc_ast2ir_ctx_init函数签名以接收ast_ctx参数
- 修复enum类型的处理逻辑,使用正确的内置类型获取方式
- 修正for循环控制流中错误的跳转目标
- 移除未使用的parse_struct_union_layout函数

refactor(cfg): 优化模块接口的const正确性

- 将scc_cfg_module_unsafe_get_*系列函数的module参数标记为const
- 提高接口的安全性和一致性

refactor(lir): 简化寄存器定义宏

- 移除未使用的SCC_LIR_PREG宏定义
- 简化头文件中的冗余声明

fix(hir2lir): 修复空指针常量的表示方式

- 修正NULL值的AP整数表示,正确初始化ap结构体字段
- 确保空指针在低级IR中被正确表示

refactor(mir): 重构函数元数据结构

- 为MIR函数元数据添加栈槽位和寄存器分配相关字段
- 定义新的栈槽位数据结构scc_mir_stack_slot_t
- 添加函数元数据初始化函数scc_mir_func_meta_init

refactor(x86): 改进后端代码生成

- 修正ret指令生成,使用近返回指令RET_NEAR
- 修复伪alloca指令的形式转换问题
- 改进选择函数的const正确性
- 正确初始化函数元数据结构

style(config): 添加MIR阶段配置选项

- 为MIR各个处理阶段添加配置标志
- 包括寄存器分配、栈布局和前言后记生成的输出选项

fix(parser): 改进错误处理机制

- 修正语义分析上下文变量命名
- 添加解析错误码检查,及时返回错误状态
This commit is contained in:
zzy
2026-05-01 22:51:31 +08:00
parent 85d698acdf
commit b06c4fe3cc
14 changed files with 89 additions and 39 deletions

View File

@@ -7,4 +7,7 @@
void scc_lir2mir(scc_mir_module_t *mir_module,
const scc_lir_module_t *lir_module);
// TODO
void scc_mir_pass(scc_mir_module_t *mir_module);
#endif /* __SCC_LIR2MIR_H__ */

View File

@@ -47,14 +47,27 @@ typedef struct scc_mir_bblock_meta {
#define SCC_MIR_BBLOCK_VALUES(bblock) \
((scc_mir_instr_vec_t *)&((bblock)->values))
typedef struct scc_mir_stack_slot {
int slot_id;
int size; // 通常是 8 字节 (指针大小)
int alignment; // 对齐要求
int offset; // 相对于 RSP 的偏移 (最终确定)
} scc_mir_stack_slot_t;
typedef SCC_VEC(scc_mir_stack_slot_t) scc_mir_stack_slot_vec_t;
typedef scc_cfg_func_t scc_mir_func_t;
typedef struct scc_mir_func_meta {
// 栈帧信息 (由 FrameLayout Pass 填充)
int frame_size;
int stack_alignment;
// 寄存器分配信息
SCC_VEC(int) vreg_alloc; // vreg -> phys reg 映射
scc_mir_stack_slot_vec_t stack_slots;
scc_hashtable_t vreg2preg; // vreg -> phys reg-1 表示溢出
scc_hashtable_t vreg2slot; // vreg -> stack slot index
} scc_mir_func_meta_t;
#define SCC_MIR_FUNC_META(func) ((scc_mir_func_meta_t *)(func)->meta)
void scc_mir_func_meta_init(scc_mir_func_meta_t *func_meta);
#endif /* __SCC_MIR_H__ */