refactor(ast2ir): 重构ABI类型系统并修复union结构问题

- 将scc_ast_def.h中的attr_of从union改为struct以修复结构定义问题
- 添加type_abi依赖到ast2ir模块的cbuild.toml配置文件中
- 重命名scc_ast2ir.h中的abi字段为type_abi,并更新相关初始化函数签名
- 移除废弃的scc_abi_type.h和相关平台ABI头文件
- 添加辅助函数is_variadic_marker和fixed_param_count用于处理可变参数
- 添加数组和聚合类型初始化的辅助函数
This commit is contained in:
zzy
2026-06-01 12:14:13 +08:00
parent 8b817da3b6
commit 31d7e91ef1
45 changed files with 1918 additions and 1551 deletions

View File

@@ -35,6 +35,42 @@ static inline void scc_mcode_drop(scc_mcode_t *mcode) {
mcode->is_littel_endian = true;
}
/**
* @brief 接管一个现有缓冲区的所有权作为 mcode 的代码数据
*
* 释放 mcode 原有的 code 缓冲区, 然后将 buf 的内部指针/容量/大小
* 转移到 mcode->code。调用后 buf 被重新初始化(空向量)。
* 避免拷贝大块代码数据。
*/
static inline void scc_mcode_adopt_buf(scc_mcode_t *mcode,
scc_mcode_buff_t *buf) {
scc_vec_free(mcode->code);
mcode->code.size = buf->size;
mcode->code.cap = buf->cap;
mcode->code.data = buf->data;
buf->size = 0;
buf->cap = 0;
buf->data = NULL;
}
/**
* @brief 释放 mcode 内部 code 缓冲区的所有权到目标向量
*
* 将 mcode->code 的数据指针/容量/大小转移到 out 向量,
* 然后 mcode->code 被重新初始化(空向量)。
* 避免拷贝大块代码数据。
*/
static inline void scc_mcode_disown_buf(scc_mcode_t *mcode,
scc_mcode_buff_t *out) {
scc_vec_free(*out);
out->size = mcode->code.size;
out->cap = mcode->code.cap;
out->data = mcode->code.data;
mcode->code.size = 0;
mcode->code.cap = 0;
mcode->code.data = NULL;
}
static inline void scc_mcode_add_u8(scc_mcode_t *mcode, u8 data) {
scc_vec_push(mcode->code, data);
}

View File

@@ -45,26 +45,26 @@ typedef struct {
scc_x86_mem_t mem;
scc_x86_reloc_op_t reloc;
};
u8 size;
u8 size_bits;
} scc_x86_operand_value_t;
static inline scc_x86_operand_value_t scc_x86_op_preg(scc_x86_reg_t reg,
u8 size) {
u8 size_bits) {
scc_x86_operand_value_t o = {
.kind = SCC_X86_OPR_REG,
.reg = reg,
.size = size,
.size_bits = size_bits,
};
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, u8 size) {
static inline scc_x86_operand_value_t scc_x86_op_vreg(int vreg, u8 size_bits) {
scc_x86_operand_value_t o = {
.kind = SCC_X86_OPR_REG,
.reg = scc_x86_op_vreg_reg(vreg),
.size = size,
.size_bits = size_bits,
};
return o;
}
@@ -72,24 +72,24 @@ static inline scc_x86_operand_value_t scc_x86_op_relbr(i32 rel) {
scc_x86_operand_value_t o = {
.kind = SCC_X86_OPR_RELBR,
.brdisp = rel,
.size = 4,
.size_bits = 32,
};
return o;
}
static inline scc_x86_operand_value_t scc_x86_op_imm(i64 imm, u8 size) {
static inline scc_x86_operand_value_t scc_x86_op_imm(i64 imm, u8 size_bits) {
scc_x86_operand_value_t o = {
.kind = SCC_X86_OPR_IMM,
.simm0 = imm,
.size = size,
.size_bits = size_bits,
};
return o;
}
static inline scc_x86_operand_value_t scc_x86_op_mem(scc_x86_mem_t mem,
u8 size) {
u8 size_bits) {
scc_x86_operand_value_t o = {
.kind = SCC_X86_OPR_MEM,
.mem = mem,
.size = size,
.size_bits = size_bits,
};
return o;
}
@@ -102,7 +102,7 @@ scc_x86_op_reloc_global_imm(const char *sym, i64 addend) {
op.reloc.target = SCC_X86_RELOC_TARGET_SYMBOL;
op.reloc.global_name = sym;
op.reloc.addend = addend;
op.size = 0;
op.size_bits = 0;
return op;
}
@@ -113,7 +113,7 @@ scc_x86_op_reloc_global_relrip(const char *sym, i64 addend) {
op.reloc.target = SCC_X86_RELOC_TARGET_SYMBOL;
op.reloc.global_name = sym;
op.reloc.addend = addend;
op.size = 4;
op.size_bits = 32;
return op;
}
@@ -125,7 +125,7 @@ scc_x86_op_reloc_global_relbr(const char *sym, i64 addend) {
op.reloc.target = SCC_X86_RELOC_TARGET_SYMBOL;
op.reloc.global_name = sym;
op.reloc.addend = addend;
op.size = 4;
op.size_bits = 32;
return op;
}
@@ -137,7 +137,7 @@ static inline scc_x86_operand_value_t scc_x86_op_reloc_block(int bid,
op.reloc.target = SCC_X86_RELOC_TARGET_BBLOCK;
op.reloc.bblock_id = bid;
op.reloc.addend = addend;
op.size = 4;
op.size_bits = 32;
return op;
}
@@ -151,7 +151,7 @@ scc_x86_op_reloc_global_mem(const char *sym, i64 addend) {
op.reloc.global_name = sym;
op.reloc.addend = addend;
// 编码时需生成 RIP 相对寻址的 ModRM/SIB
op.size = 0;
op.size_bits = 0;
return op;
}

View File

@@ -61,10 +61,10 @@ static int infer_operand_width(const scc_x86_iform_info_t *info,
for (int i = 0; i < info->num_explicit_ops; i++) {
if (ops[i].kind == SCC_X86_OPR_REG && !info->ops[i].is_implicit) {
uint16_t w;
if (ops[i].size > 0 && ops[i].reg >= SCC_X86_REG_R8 &&
if (ops[i].size_bits > 0 && ops[i].reg >= SCC_X86_REG_R8 &&
ops[i].reg <= SCC_X86_REG_R15) {
/* R8-R15宽度由 size 字段推导 */
w = ops[i].size * 8;
/* R8-R15宽度由 size_bits 字段推导单位bit */
w = ops[i].size_bits;
} else {
w = scc_reg_width(ops[i].reg);
}