#ifndef __SCC_REG_ALLOC_H__ #define __SCC_REG_ALLOC_H__ #include #include #include typedef enum { SCC_REG_KIND_UNDEF, 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_cprog_ctx_t *ir_ctx; ///< 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_cprog_ctx_t *ir_ctx); scc_hashtable_t *scc_reg_alloc_with_stack(scc_reg_alloc_t *ctx, scc_ir_func_t *func); #endif /* __SCC_REG_ALLOC_H__ */