- 在AST定义中移除函数调用结构体中的冗余name字段 - 实现完整的函数声明和定义处理流程,支持符号表查找 - 添加函数参数引用节点类型,支持参数传递和访问 - 实现函数调用的IR生成,包括参数处理和符号解析 - 添加断言确保节点有效性,提升代码健壮性 fix(ast2ir): 优化类型转换处理逻辑 - 移除多余的注释说明 - 简化参数为空检查逻辑,提高代码简洁性 - 修复函数调用时的符号表查找机制 refactor(ir): 改进IR构建器接口设计 - 修改函数构建相关API,使接口更加清晰 - 添加函数声明集合管理 - 重构内置类型缓存机制 feat(ir2mcode): 完善AMD64代码生成 - 实现函数参数到寄存器的映射 - 添加函数调用约定支持(最多4个参数) - 实现函数符号和重定位处理 - 添加栈帧管理机制 - 修正栈偏移计算 chore(ir): 清理和优化IR dump输出 - 更新节点类型描述信息 - 改进函数声明和定义的输出格式 - 修正格式化输出中的符号显示问题 style: 代码格式化和命名规范化 - 统一重定位类型枚举命名 - 优化函数参数验证和错误处理
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_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__ */
|