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

@@ -12,8 +12,7 @@ typedef struct {
scc_hashtable_t continue_cache; ///< continue cache
scc_hashtable_t symtab; ///< symbol to ir_ref
scc_hashtable_t type_cache; ///< scc_ast_canon_type_t* -> scc_hir_type_ref_t
// scc_strpool_t strpool; ///< string pool
const scc_abi_type_calc_t *abi;
const scc_type_abi_t *type_abi;
cbool hint_using_value; // 转换时尽可能使用value而不是alloc
scc_ast_module_t *ast_module;
@@ -23,7 +22,7 @@ static inline scc_hir_module_t *scc_ast2ir_mir_module(scc_ast2ir_ctx_t *ctx) {
return &ctx->builder.cprog->module;
}
void scc_ast2ir_ctx_init(scc_ast2ir_ctx_t *ctx, const scc_abi_type_calc_t *abi,
void scc_ast2ir_ctx_init(scc_ast2ir_ctx_t *ctx, const scc_type_abi_t *type_abi,
scc_ast_module_t *ast_module, scc_hir_cprog_t *cprog);
void scc_ast2ir_ctx_drop(scc_ast2ir_ctx_t *ctx);
@@ -42,6 +41,38 @@ scc_hir_type_ref_t
scc_ast2ir_parse_base_type(scc_ast2ir_ctx_t *ctx,
const scc_ast_qual_type_t *ast_type);
// Utils
// 判断 AST 参数是否为 ... 生成的假 VA_LIST 参数
static cbool is_variadic_marker(const scc_ast_decl_t *decl_param) {
return decl_param->name == nullptr &&
decl_param->param.type->base.type == SCC_AST_TYPE_BUILTIN &&
scc_ast_canon_type(decl_param->param.type)->builtin.type ==
SCC_AST_BUILTIN_TYPE_VA_LIST;
}
// 计算函数类型中的固定参数个数(去掉尾部的 ... 标记)
static int fixed_param_count(const scc_ast_canon_type_t *canon) {
int n = (int)scc_vec_size(canon->function.params);
if (n > 0) {
const scc_ast_decl_t *last =
scc_vec_at(canon->function.params, (usize)(n - 1));
if (is_variadic_marker(last))
return n - 1;
}
return n;
}
void emit_array_initialization(scc_ast2ir_ctx_t *ctx,
scc_hir_value_ref_t array_ptr,
const scc_hir_type_t *array_type,
const scc_ast_expr_t *init_expr);
void emit_aggregate_initialization(scc_ast2ir_ctx_t *ctx,
scc_hir_value_ref_t base_ptr,
const scc_hir_type_t *type,
const scc_ast_expr_t *init_expr);
// ====== 类型提升Type Promotion接口 ======
/**