feat(abi): 新增ABI类型布局描述接口和Windows x64实现

- 新增scc_abi包,包含基础类型布局描述接口
- 实现Windows x64 ABI类型布局计算功能
- 定义基本类型枚举和布局信息结构体
- 提供类型布局计算的核心接口函数

refactor(ast2ir): 使用新的ABI接口替换旧的类型转换实现

- 将旧的scc_type_abi_t替换为新的scc_abi_type_calc_t
- 更新AST到IR的类型转换逻辑,使用新的ABI计算接口
- 修改上下文初始化和类型解析相关代码
- 移除废弃的头文件和相关实现

refactor(ir): 统一IR节点引用类型命名并完善构建器功能

- 将scc_ir_node_ref_vec_t重命名为scc_ir_value_ref_vec_t保持一致性
- 更新聚合类型的字段名称从elements到fields
- 添加全局变量分配构建器函数scc_ir_builder_global_alloca
- 清理构建器中多余的注释和代码
This commit is contained in:
zzy
2026-04-12 11:30:31 +08:00
parent 630e22b73b
commit 694778e4a0
19 changed files with 383 additions and 274 deletions

View File

@@ -42,6 +42,19 @@ scc_ir_type_ref_t scc_ir_builder_type(scc_ir_builder_t *builder,
void scc_ir_builder_add_instr(scc_ir_builder_t *builder,
scc_ir_value_ref_t instr);
scc_ir_value_ref_t scc_ir_builder_global_alloca(scc_ir_builder_t *builder,
scc_ir_type_ref_t type,
scc_ir_value_ref_t value);
/**
* @brief 创建alloca指令在当前基本块中
* @param type 分配的类型
* @param name 变量名可为nullptr
*/
scc_ir_value_ref_t scc_ir_builder_alloca(scc_ir_builder_t *builder,
scc_ir_type_ref_t type,
const char *name);
#define SCC_IR_BUILDER_TYPE_FUNC(scc_type) \
[[maybe_unused]] static inline scc_ir_type_ref_t \
scc_ir_builder_type_##scc_type(scc_ir_builder_t *builder) { \
@@ -122,25 +135,15 @@ scc_ir_builder_const_string(scc_ir_builder_t *builder, const char *str,
buff[i - 1] = str[i];
}
buff[len - 2] = '\0';
scc_vec_unsafe_from_buffer(const_array_value.data.const_array.elements,
scc_vec_unsafe_from_buffer(const_array_value.data.const_array.fields,
(u8 *)buff, len - 1);
scc_ir_value_ref_t const_array_ref =
scc_ir_module_add_value(builder->ctx.module, &const_array_value);
Assert(const_array_ref != SCC_IR_REF_nullptr);
// 3. 创建全局变量节点,类型为指针,初始值指向常量数组
char *name = scc_malloc(32);
// FIXME MAYBE MEMORY LEAK
scc_ir_value_ref_t global_value_ref = scc_ir_module_add_value(
builder->ctx.module, &(scc_ir_value_t){
.name = name,
.tag = SCC_IR_VALUE_TAG_GLOBAL_ALLOC,
.type = array_type_ref,
.data.global_alloc.value = const_array_ref,
});
scc_snprintf(name, 32, "$G%u", global_value_ref);
scc_vec_push(builder->cprog->global_vals, global_value_ref);
scc_ir_value_ref_t global_value_ref =
scc_ir_builder_global_alloca(builder, array_type_ref, const_array_ref);
// scc_hashtable_insert(builder);
scc_ir_value_ref_t pointer_to_global_value = scc_ir_module_add_value(
@@ -203,15 +206,6 @@ scc_ir_func_ref_t scc_ir_builder_current_bblock(scc_ir_builder_t *builder);
void scc_ir_builder_set_current_bblock(scc_ir_builder_t *builder,
scc_ir_bblock_ref_t bblock);
/**
* @brief 创建alloca指令在当前基本块中
* @param type 分配的类型
* @param name 变量名可为nullptr
*/
scc_ir_value_ref_t scc_ir_builder_alloca(scc_ir_builder_t *builder,
scc_ir_type_ref_t type,
const char *name);
scc_ir_value_ref_t scc_ir_builder_func_arg_ref(scc_ir_builder_t *builder,
scc_ir_type_ref_t type,
const char *name, usize arg_idx);