refactor(ast2ir): 提取模块访问函数并优化类型大小计算
- 添加 scc_ast2ir_mir_module 内联函数统一访问模块 - 替换所有直接访问 ctx->builder.cprog->module 的地方 - 移除重复的 scc_hir_type_size 函数实现 - 添加 scc_hir_module_type_size 函数到模块接口 - 更新所有类型大小计算调用使用新函数 feat(hir): 增强构建器安全性和全局变量处理 - 为 scc_hir_builder_integer 添加空指针检查断言 - 修复 scc_hir_builder_global_alloca 中全局变量类型设置 - 改进 scc_hir_builder_get_elem_ptr 处理空指针索引情况 - 重构字符串常量生成使用 get_elem_ptr 构建器函数 refactor(lir): 简化地址表达式表示并增强内置函数支持 - 移除复杂地址结构体 scc_lir_addr_t - 简化 scc_lir_instr 结构体中的地址表示 - 移除 STORE_ADDR 操作码 - 添加 memcpy 和 memset 内置函数操作码 - 在符号元数据中使用联合体替代嵌套结构体 feat(hir2lir): 完善 HIR 到 LIR 转换中的内置函数处理 - 添加 ensure_vreg 辅助函数确保虚拟寄存器操作数 - 正确处理全局变量地址符号引用 - 优化 GET_ELEM_PTR 转换使用类型大小计算 - 完整实现所有内置函数(BUILTIN)的 LIR 转换 - 包括 memcpy、memset、va_start、va_arg、va_end、va_copy 等
This commit is contained in:
@@ -45,16 +45,21 @@ typedef struct {
|
||||
scc_x86_mem_t mem;
|
||||
scc_x86_reloc_op_t reloc;
|
||||
};
|
||||
usize size;
|
||||
} scc_x86_operand_value_t;
|
||||
|
||||
static inline scc_x86_operand_value_t scc_x86_op_preg(scc_x86_reg_t reg) {
|
||||
scc_x86_operand_value_t o = {.kind = SCC_X86_OPR_REG, .reg = reg};
|
||||
return o;
|
||||
}
|
||||
static inline scc_x86_reg_t scc_x86_op_vreg_reg(int vreg) {
|
||||
return (int)SCC_X86_REG_COUNT + vreg;
|
||||
}
|
||||
static inline scc_x86_operand_value_t scc_x86_op_vreg(int vreg) {
|
||||
scc_x86_operand_value_t o = {
|
||||
.kind = SCC_X86_OPR_REG,
|
||||
.reg = (scc_x86_reg_t)((int)SCC_X86_REG_COUNT + vreg)};
|
||||
.reg = scc_x86_op_vreg_reg(vreg),
|
||||
};
|
||||
return o;
|
||||
}
|
||||
static inline scc_x86_operand_value_t scc_x86_op_relbr(i32 rel) {
|
||||
@@ -81,6 +86,16 @@ scc_x86_op_reloc_global_imm(const char *sym, i64 addend) {
|
||||
return op;
|
||||
}
|
||||
|
||||
static inline scc_x86_operand_value_t
|
||||
scc_x86_op_reloc_global_relrip(const char *sym, i64 addend) {
|
||||
scc_x86_operand_value_t op = {.kind = SCC_X86_OPR_RELOC};
|
||||
op.reloc.kind = SCC_X86_OPR_MEM;
|
||||
op.reloc.target = SCC_X86_RELOC_TARGET_SYMBOL;
|
||||
op.reloc.global_name = sym;
|
||||
op.reloc.addend = addend;
|
||||
return op;
|
||||
}
|
||||
|
||||
// 2. 全局符号重定位(相对跳转/调用:CALL/JMP rel32)
|
||||
static inline scc_x86_operand_value_t
|
||||
scc_x86_op_reloc_global_relbr(const char *sym, i64 addend) {
|
||||
|
||||
@@ -23,8 +23,6 @@ static inline void patch_bytes(scc_mcode_t *mcode, usize offset,
|
||||
scc_memcpy(buf + offset, data, size);
|
||||
}
|
||||
|
||||
/* ---------- 实现补丁接口 ---------- */
|
||||
|
||||
static inline int scc_x86_patch_disp(scc_mcode_t *mcode, usize offset,
|
||||
scc_x86_disp_t disp) {
|
||||
if (!mcode || disp.displacement_bits == 0)
|
||||
|
||||
Reference in New Issue
Block a user