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

@@ -153,8 +153,7 @@ scc_ir_value_ref_t scc_ir_builder_const_string(scc_ir_builder_t *builder,
* @return void
*/
void scc_ir_builder_begin_func(scc_ir_builder_t *builder,
scc_ir_func_ref_t func_ref,
const char **param_names);
scc_ir_func_ref_t func_ref);
/**
* @brief 结束当前函数的构建

View File

@@ -85,8 +85,7 @@ scc_ir_value_ref_t scc_ir_builder_const_string(scc_ir_builder_t *builder,
}
void scc_ir_builder_begin_func(scc_ir_builder_t *builder,
scc_ir_func_ref_t func_ref,
const char **param_names) {
scc_ir_func_ref_t func_ref) {
SCC_IR_BUILDER_CHECK_NO_BORROW(builder);
builder->current_func = func_ref;
@@ -480,7 +479,12 @@ scc_ir_value_ref_t scc_ir_builder_ret_void(scc_ir_builder_t *builder) {
SCC_IR_BUILDER_CHECK_NO_BORROW(builder);
scc_ir_value_t ret_node = {0};
ret_node.tag = SCC_IR_VALUE_TAG_RET;
ret_node.data.ret.ret_val = 0;
scc_ir_value_t ret_val_node;
scc_ir_value_init(&ret_val_node, nullptr, SCC_IR_VALUE_TAG_NULLPTR);
ret_val_node.type = scc_ir_builder_type_void(builder);
ret_node.data.ret.ret_val =
scc_ir_module_add_value(GET_MODULE(builder), &ret_val_node);
scc_ir_value_ref_t value_ref =
scc_ir_module_add_value(GET_MODULE(builder), &ret_node);

View File

@@ -1,19 +1,14 @@
#include <ir_module.h>
static u32 hash_key(const void *key, void *userdata) { return (u32)(usize)key; }
static int cmp_key(const void *key1, const void *key2, void *userdata) {
return (u32)(usize)key1 != (u32)(usize)key2;
}
void scc_ir_module_init(scc_ir_module_t *ctx) {
scc_vec_init(ctx->values);
scc_vec_init(ctx->types);
scc_vec_init(ctx->bblocks);
scc_vec_init(ctx->funcs);
scc_hashtable_init(&ctx->uid2value, hash_key, cmp_key, nullptr);
scc_hashtable_init(&ctx->uid2type, hash_key, cmp_key, nullptr);
scc_hashtable_init(&ctx->uid2bblock, hash_key, cmp_key, nullptr);
scc_hashtable_init(&ctx->uid2func, hash_key, cmp_key, nullptr);
scc_hashtable_usize_init(&ctx->uid2value);
scc_hashtable_usize_init(&ctx->uid2type);
scc_hashtable_usize_init(&ctx->uid2bblock);
scc_hashtable_usize_init(&ctx->uid2func);
// 预留UID 0 作为无效引用
scc_vec_push(ctx->values, (scc_ir_value_t){0});
scc_vec_push(ctx->types, (scc_ir_type_t){0});