- 实现了指针解引用(*)和取地址(&)操作符的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中添加对应的期望返回值
51 lines
1.7 KiB
C
51 lines
1.7 KiB
C
#ifndef __SCC_REG_ALLOC_H__
|
|
#define __SCC_REG_ALLOC_H__
|
|
|
|
#include <scc_core.h>
|
|
#include <scc_ir.h>
|
|
#include <scc_utils.h>
|
|
|
|
typedef enum {
|
|
SCC_REG_KIND_UNDEF,
|
|
SCC_REG_KIND_FUNC_ARG,
|
|
SCC_REG_KIND_GPR, ///< 通用寄存器(整数)
|
|
SCC_REG_KIND_FPR, ///< 浮点数寄存器
|
|
SCC_REG_KIND_STACK, ///< 栈
|
|
SCC_REG_KIND_STACK_ADDR, ///< 栈地址(如 alloc 节点)
|
|
SCC_REG_KIND_IMM, ///< 整数立即数
|
|
SCC_REG_KIND_IMM_FP, ///< 浮点数常量
|
|
} scc_reg_kind_t;
|
|
|
|
typedef struct {
|
|
scc_reg_kind_t kind;
|
|
usize idx;
|
|
} scc_reg_loc_t;
|
|
typedef SCC_VEC(scc_reg_loc_t) scc_reg_loc_vec_t;
|
|
|
|
struct scc_reg_alloc;
|
|
typedef struct scc_reg_alloc scc_reg_alloc_t;
|
|
typedef scc_hashtable_t *(*scc_reg_alloc_func_t)(
|
|
scc_reg_alloc_t *ctx, ///< @param [in] 上下文
|
|
scc_ir_func_t *func ///< @param [in] 待处理的 IR 函数
|
|
);
|
|
|
|
typedef struct scc_reg_alloc {
|
|
scc_ir_module_t *ir_module; ///< IR存储节点
|
|
scc_hashtable_t node_ref2reg_loc; ///< 输出结果哈希表
|
|
scc_reg_loc_vec_t reg_loc_vec;
|
|
int gpr_caller_saved; ///< 函数可以随意修改,调用者如果在意需自行保护.
|
|
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))
|
|
|
|
void scc_reg_alloc_init(scc_reg_alloc_t *ctx, scc_reg_alloc_func_t func,
|
|
scc_ir_module_t *ir_module);
|
|
scc_hashtable_t *scc_reg_alloc_with_stack(scc_reg_alloc_t *ctx,
|
|
scc_ir_func_t *func);
|
|
|
|
#endif /* __SCC_REG_ALLOC_H__ */
|