refactor(ast2ir): 更新IR构建器接口并重构类型映射

- 将IR构建器初始化函数修改为接受cprog参数
- 添加scc_ast2ir_ctx_drop函数用于资源清理
- 更新类型标识符命名规范,从大写改为小写形式
- 替换scc_ir_ctx_get_*函数调用为scc_ir_module_get_*函数
- 移除对ir_builtin.h的依赖,改用ir_builder.h中的构建器函数
- 为整数常量创建添加专门的构建器辅助函数

fix(ir): 重构IR上下文和模块管理结构

- 将原有的scc_ir_cprog_ctx_t拆分为scc_ir_module_t和scc_ir_ctx_t
- 添加scc_ir_module_t结构用于统一管理IR对象存储
- 更新IR类型枚举名称格式,从SCC_IR_TYPE_XXX改为SCC_IR_TYPE_xxx
- 添加整数、无符号整数和浮点数常量联合体定义
- 移除ir_base.h和ir_builtin.h头文件,整合到scc_ir.h中

feat(ir_builder): 添加类型构建器函数和常量创建功能

- 为各种基础类型添加scc_ir_builder_type_*内联函数
- 实现scc_ir_builder_const_int函数用于创建整数常量
- 修改构建器初始化函数签名以接受cprog参数
- 更新构建器内部结构,使用指向cprog的指针而非嵌入式结构
This commit is contained in:
zzy
2026-03-25 11:59:27 +08:00
parent d167a8ba96
commit 8c7af571c2
24 changed files with 779 additions and 792 deletions

52
libs/ir/include/ir_prog.h Normal file
View File

@@ -0,0 +1,52 @@
#ifndef __SCC_IR_PROG_H__
#define __SCC_IR_PROG_H__
#include "ir_def.h"
#include <scc_utils.h>
typedef struct {
unsigned int node_uid;
unsigned int type_uid;
unsigned int bblock_uid;
unsigned int func_uid;
SCC_VEC(scc_ir_node_t) nodes;
SCC_VEC(scc_ir_type_t) types;
SCC_VEC(scc_ir_bblock_t) bblocks;
SCC_VEC(scc_ir_func_t) funcs;
// UID -> ref index
scc_hashtable_t uid2nodes;
scc_hashtable_t uid2types;
scc_hashtable_t uid2bblocks;
scc_hashtable_t uid2funcs;
} scc_ir_module_t;
void scc_ir_module_init(scc_ir_module_t *ctx);
void scc_ir_module_drop(scc_ir_module_t *ctx);
scc_ir_type_ref_t scc_ir_module_add_type(scc_ir_module_t *ctx,
const scc_ir_type_t *type);
scc_ir_node_ref_t scc_ir_module_add_node(scc_ir_module_t *ctx,
const scc_ir_node_t *node);
scc_ir_bblock_ref_t scc_ir_module_add_bblock(scc_ir_module_t *ctx,
const scc_ir_bblock_t *bblock);
scc_ir_func_ref_t scc_ir_module_add_func(scc_ir_module_t *ctx,
const scc_ir_func_t *func);
scc_ir_type_t *scc_ir_module_get_type(scc_ir_module_t *ctx,
scc_ir_type_ref_t ref);
scc_ir_node_t *scc_ir_module_get_node(scc_ir_module_t *ctx,
scc_ir_node_ref_t ref);
scc_ir_bblock_t *scc_ir_module_get_bblock(scc_ir_module_t *ctx,
scc_ir_bblock_ref_t ref);
scc_ir_func_t *scc_ir_module_get_func(scc_ir_module_t *ctx,
scc_ir_func_ref_t ref);
typedef struct scc_ir_cprog {
scc_ir_module_t module;
scc_ir_node_ref_vec_t global_vals; /* 全局变量 */
scc_ir_func_ref_vec_t func_defs; /* 所有函数定义 */
scc_ir_func_ref_vec_t func_decls; /* 所有函数包括定义的声明 */
} scc_ir_cprog_t;
void scc_ir_cprog_init(scc_ir_cprog_t *in);
void scc_ir_cprog_drop(scc_ir_cprog_t *in);
#endif /* __SCC_IR_PROG_H__ */