feat(ir2mcode): 添加IR到机器码转换模块并更新依赖配置
- 新增ir2mcode库用于将IR转换为机器码 - 添加sccf2target依赖以支持目标平台转换 - 在ast库中添加scc_pos依赖支持位置信息 - 更新cbuild.toml配置文件添加新库依赖 - 实现AMD64架构代码生成功能 - 添加寄存器分配器实现栈和寄存器位置管理 - 支持基本的算术运算和内存访问操作 - 添加PE格式目标文件生成支持
This commit is contained in:
47
libs/ir2mcode/include/reg_alloc.h
Normal file
47
libs/ir2mcode/include/reg_alloc.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#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_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__ */
|
||||
Reference in New Issue
Block a user