- 将IR构建器初始化函数修改为接受cprog参数 - 添加scc_ast2ir_ctx_drop函数用于资源清理 - 更新类型标识符命名规范,从大写改为小写形式 - 替换scc_ir_ctx_get_*函数调用为scc_ir_module_get_*函数 - 移除对ir_builtin.h的依赖,改用ir_builder.h中的构建器函数 - 为整数常量创建添加专门的构建器辅助函数 fix(ir): 重构IR上下文和模块管理结构 - 将原有的scc_ir_cprog_ctx_t拆分为scc_ir_module_t和scc_ir_ctx_t - 添加scc_ir_module_t结构用于统一管理IR对象存储 - 更新IR类型枚举名称格式,从SCC_IR_TYPE_XXX改为SCC_IR_TYPE_xxx - 添加整数、无符号整数和浮点数常量联合体定义 - 移除ir_base.h和ir_builtin.h头文件,整合到scc_ir.h中 feat(ir_builder): 添加类型构建器函数和常量创建功能 - 为各种基础类型添加scc_ir_builder_type_*内联函数 - 实现scc_ir_builder_const_int函数用于创建整数常量 - 修改构建器初始化函数签名以接受cprog参数 - 更新构建器内部结构,使用指向cprog的指针而非嵌入式结构
49 lines
1.6 KiB
C
49 lines
1.6 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_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;
|
|
} 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__ */
|