feat(cbuild): 添加 lir 库依赖并注释掉未使用的模块

- 添加 { name = "lir", path = "./libs/lir" } 依赖项
- 注释掉 ir2mcode 和 sccf2target 模块以暂时禁用

refactor(ast2ir): 修复类型转换问题并简化哈希表初始化

- 修复 compute_type_layout 函数中的类型转换警告
- 在表达式处理末尾添加 UNREACHABLE() 断言
- 移除 begin_func 中的 param_names 参数
- 使用 scc_hashtable_usize_init 替代自定义比较函数

refactor(ir): 简化函数构建器接口并修复返回值处理

- 移除 scc_ir_builder_begin_func 中的 param_names 参数
- 修改 scc_ir_builder_ret_void 以正确处理 void 返回值
- 初始化返回值节点而不是直接设置为 0

refactor(ir): 简化模块初始化中的哈希表配置

- 移除自定义 hash_key 和 cmp_key 函数
- 使用 scc_hashtable_usize_init 统一初始化哈希表

feat(lir): 添加低层中间表示库基础结构

- 创建 lir 库的包配置文件
- 定义 LIR 的基本数据结构、指令类型和操作枚举
- 实现 LIR 构建器和模块管理功能
- 添加 LIR 转换器头文件和转储功能
This commit is contained in:
zzy
2026-04-18 11:35:43 +08:00
parent 5a9f816ccf
commit e5bbffe170
19 changed files with 1814 additions and 45 deletions

View File

@@ -8,7 +8,7 @@ static scc_ir_type_ref_t parse_base_type(scc_ast2ir_ctx_t *ctx,
const scc_ast_type_t *ast_type) {
scc_abi_type_layout_t layout;
// 映射内置类型
ctx->abi->compute_type_layout(ctx->abi, ast_type, &layout);
ctx->abi->compute_type_layout(ctx->abi, (void *)ast_type, &layout);
switch (layout.size) {
case 0:
return scc_ir_builder_type_void(&ctx->builder);
@@ -668,6 +668,7 @@ scc_ir_value_ref_t scc_ast2ir_expr(scc_ast2ir_ctx_t *ctx,
LOG_FATAL("Unsupported expression type: %d", expr->base.type);
return 0;
}
UNREACHABLE();
}
/**
@@ -942,7 +943,7 @@ void scc_ast2ir_decl(scc_ast2ir_ctx_t *ctx, const scc_ast_decl_t *decl,
break;
}
scc_ir_builder_begin_func(&ctx->builder, func_ref, nullptr);
scc_ir_builder_begin_func(&ctx->builder, func_ref);
scc_ir_builder_begin_bblock(&ctx->builder, "entry");
scc_vec_foreach(decl->func.type->function.params, i) {
@@ -1033,20 +1034,12 @@ void scc_ast2ir_translation_unit(scc_ast2ir_ctx_t *ctx,
}
}
static u32 scc_hash_node(const void *key, void *userdata) {
return (u32)(usize)key;
}
static int scc_cmp_node(const void *key1, const void *key2, void *userdata) {
return (u32)(usize)key1 - (u32)(usize)key2;
}
void scc_ast2ir_ctx_init(scc_ast2ir_ctx_t *ctx, const scc_abi_type_calc_t *abi,
scc_ir_cprog_t *cprog) {
Assert(ctx != nullptr);
ctx->abi = abi;
scc_ir_builder_init(&ctx->builder, cprog);
scc_hashtable_init(&ctx->ast2ir_cache, scc_hash_node, scc_cmp_node,
nullptr);
scc_hashtable_usize_init(&ctx->ast2ir_cache);
scc_hashtable_cstr_init(&ctx->symtab);
ctx->hint_using_value = false;
}