添加了frame_alloc.h头文件定义帧分配器操作接口,实现了Windows 64位 平台的帧分配器实现,包括槽位分配、偏移计算和栈帧布局管理功能。 BREAKING CHANGE: 移除了旧的frame_manager.h接口,采用新的frame_alloc_ops_t 抽象接口。 fix(ast2ir): 修复字符串字面量表达式返回值问题 修复了AST到IR转换过程中字符串字面量表达式的处理,确保正确返回 创建的常量字符串值引用而非直接跳出。 fix(ir): 修复内置memcpy函数参数验证和类型比较逻辑 在IR构建器中为builtin_memcpy函数添加参数空指针检查,在类型比较 函数中添加未知类型的边界条件处理,增强系统稳定性。 refactor(ir2mcode): 重构寄存器分配器接口以支持帧分配器集成 修改寄存器分配器接口以接受帧分配器参数,统一节点到位置的映射表 命名,并提供便捷的栈大小和偏移获取接口。
78 lines
2.6 KiB
C
78 lines
2.6 KiB
C
#ifndef __SCC_REG_ALLOC_H__
|
|
#define __SCC_REG_ALLOC_H__
|
|
|
|
#include "frame_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;
|
|
union {
|
|
usize data;
|
|
int slot_idx;
|
|
int gpr_idx;
|
|
int fpr_idx;
|
|
} data;
|
|
} 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 void (*scc_reg_alloc_func_t)(scc_reg_alloc_t *ctx, scc_ir_func_t *func,
|
|
scc_frame_alloc_ops_t *frame_alloc);
|
|
|
|
typedef struct scc_reg_alloc {
|
|
scc_frame_alloc_ops_t *frame_alloc;
|
|
scc_ir_module_t *ir_module; ///< IR存储节点
|
|
scc_hashtable_t node2loc; ///< 输出结果哈希表
|
|
scc_reg_loc_vec_t loc_vec;
|
|
scc_reg_alloc_func_t reg_alloc_func;
|
|
} scc_reg_alloc_t;
|
|
|
|
void scc_reg_alloc_init(scc_reg_alloc_t *ctx, scc_reg_alloc_func_t strategy,
|
|
scc_ir_module_t *ir_module);
|
|
static inline scc_hashtable_t *
|
|
scc_reg_alloc_run(scc_reg_alloc_t *ctx, scc_ir_func_t *func,
|
|
const scc_frame_alloc_ops_t *frame_alloc) {
|
|
if (ctx->frame_alloc != nullptr) {
|
|
ctx->frame_alloc->drop(ctx->frame_alloc);
|
|
ctx->frame_alloc = nullptr;
|
|
}
|
|
Assert(ctx->frame_alloc == nullptr);
|
|
ctx->frame_alloc = frame_alloc->new(func);
|
|
Assert(ctx->frame_alloc != nullptr);
|
|
ctx->reg_alloc_func(ctx, func, ctx->frame_alloc);
|
|
ctx->frame_alloc->finalize(ctx->frame_alloc);
|
|
return &ctx->node2loc;
|
|
}
|
|
|
|
static inline usize scc_reg_stack_size(scc_reg_alloc_t *ctx) {
|
|
return ctx->frame_alloc->get_frame_size(ctx->frame_alloc);
|
|
}
|
|
|
|
static inline int scc_reg_stack_offset(scc_reg_alloc_t *ctx,
|
|
scc_reg_loc_t *loc) {
|
|
Assert(loc->kind == SCC_REG_KIND_STACK ||
|
|
loc->kind == SCC_REG_KIND_STACK_ADDR);
|
|
return ctx->frame_alloc->get_slot_offset(ctx->frame_alloc,
|
|
loc->data.slot_idx);
|
|
}
|
|
|
|
void scc_reg_alloc_strategy_pure_stack(scc_reg_alloc_t *ctx,
|
|
scc_ir_func_t *func,
|
|
scc_frame_alloc_ops_t *frame_alloc);
|
|
|
|
#endif /* __SCC_REG_ALLOC_H__ */
|