feat(ir2mcode): 添加帧分配器框架和Windows 64位实现
添加了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): 重构寄存器分配器接口以支持帧分配器集成 修改寄存器分配器接口以接受帧分配器参数,统一节点到位置的映射表 命名,并提供便捷的栈大小和偏移获取接口。
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#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>
|
||||
@@ -18,33 +19,59 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
scc_reg_kind_t kind;
|
||||
usize idx;
|
||||
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 scc_hashtable_t *(*scc_reg_alloc_func_t)(
|
||||
scc_reg_alloc_t *ctx, ///< @param [in] 上下文
|
||||
scc_ir_func_t *func ///< @param [in] 待处理的 IR 函数
|
||||
);
|
||||
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_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_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;
|
||||
int alloc_stack_size;
|
||||
int init_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,
|
||||
void scc_reg_alloc_init(scc_reg_alloc_t *ctx, scc_reg_alloc_func_t strategy,
|
||||
scc_ir_module_t *ir_module);
|
||||
scc_hashtable_t *scc_reg_alloc_with_stack(scc_reg_alloc_t *ctx,
|
||||
scc_ir_func_t *func);
|
||||
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__ */
|
||||
|
||||
Reference in New Issue
Block a user