feat(ast2ir): 添加指针运算支持并修复整数字面量解析

- 实现了指针解引用(*)和取地址(&)操作符的IR转换
- 添加parse_lexme2const_int函数统一处理整数字面量解析
- 支持数组大小表达式的常量解析
- 修复函数缺少返回语句的问题,在函数末尾添加默认ret指令

refactor(ir_builder): 调整函数参数类型处理逻辑

- 修改函数参数以指针形式传递,更新参数类型处理方式
- 优化参数节点创建过程,将参数类型包装为指针类型

fix(ir_dump): 修正IR输出格式问题

- 调整基本块和函数的输出格式,确保正确的换行和缩进
- 统一输出格式,提升可读性

feat(ir2mcode): 添加帧管理器头文件定义

- 定义frame_manager.h接口,包含栈帧分配相关函数声明
- 提供栈槽分配、寄存器保存、偏移计算等功能接口

refactor(reg_alloc): 添加初始栈大小配置

- 在寄存器分配器中增加init_stack_size字段
- 支持初始化栈大小设置,为后续帧管理功能做准备

test: 添加指针操作测试用例

- 新增14_pointer.c测试文件,验证指针取地址和解引用功能
- 在expect.toml中添加对应的期望返回值
This commit is contained in:
zzy
2026-04-04 13:22:19 +08:00
parent ca187c78f1
commit 27d86d5685
11 changed files with 109 additions and 41 deletions

View File

@@ -0,0 +1,27 @@
#ifndef __SCC_FRAME_MANAGER_H__
#define __SCC_FRAME_MANAGER_H__
typedef struct frame_manager frame_manager_t;
// 初始化帧管理器,传入 ABI 参数(影子空间大小、栈对齐等)
void frame_manager_init(frame_manager_t *fm, int shadow_space, int align);
// 分配一个栈槽用于局部变量或临时值返回虚拟槽索引从0开始
int frame_alloc_slot(frame_manager_t *fm, int size);
// 分配一个保存的寄存器槽(用于被调用者保存的寄存器),返回虚拟槽索引
int frame_alloc_saved_reg(frame_manager_t *fm, int reg_width);
// 计算最终栈帧总大小(已对齐)
int frame_total_size(frame_manager_t *fm);
// 将虚拟槽索引转换为相对于 RBP 的偏移(正数,表示从 RBP 向下的距离)
int frame_slot_offset(frame_manager_t *fm, int slot_idx);
// 获取影子空间大小(固定)
int frame_shadow_space(frame_manager_t *fm);
// 获取保存寄存器区域的总大小
int frame_saved_reg_size(frame_manager_t *fm);
#endif /* __SCC_FRAME_MANAGER_H__ */

View File

@@ -37,6 +37,7 @@ typedef struct scc_reg_alloc {
int gpr_callee_saved; ///< 函数必须保护这些寄存器的值.
scc_reg_alloc_func_t reg_alloc_func;
int alloc_stack_size;
int init_stack_size;
} scc_reg_alloc_t;
#define scc_reg_alloc(ctx, func) ((ctx)->reg_alloc_func(ctx, func))