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:
@@ -2,8 +2,7 @@
|
||||
#define __SCC_IR_BUILDER_H__
|
||||
|
||||
#include "ir_ctx.h"
|
||||
#include "ir_def.h"
|
||||
#include <scc_core.h>
|
||||
#include "scc_ir.h"
|
||||
|
||||
typedef struct scc_ir_builder scc_ir_builder_t;
|
||||
|
||||
@@ -17,18 +16,16 @@ typedef struct scc_ir_builder scc_ir_builder_t;
|
||||
* - 当前构建位置(函数、基本块)
|
||||
*/
|
||||
struct scc_ir_builder {
|
||||
scc_ir_cprog_ctx_t ctx; /**< 核心上下文 */
|
||||
scc_ir_cprog_t cprog;
|
||||
scc_hashtable_t func_decl_set;
|
||||
// 当前构建位置
|
||||
scc_ir_func_ref_t current_func; /**< 当前正在构建的函数 */
|
||||
scc_ir_bblock_ref_t current_bblock; /**< 当前基本块 */
|
||||
scc_ir_cprog_t *cprog;
|
||||
scc_ir_ctx_t ctx; ///< 核心上下文
|
||||
scc_ir_func_ref_t current_func; ///< 当前正在构建的函数
|
||||
scc_ir_bblock_ref_t current_bblock; ///< 当前基本块
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 初始化 IR 构建器
|
||||
*/
|
||||
void scc_ir_builder_init(scc_ir_builder_t *builder);
|
||||
void scc_ir_builder_init(scc_ir_builder_t *builder, scc_ir_cprog_t *cprog);
|
||||
|
||||
/**
|
||||
* @brief 销毁 IR 构建器及其所有资源
|
||||
@@ -39,6 +36,46 @@ scc_ir_func_ref_t scc_ir_builder_func(scc_ir_builder_t *builder,
|
||||
scc_ir_type_ref_t type_ref,
|
||||
const char *name);
|
||||
|
||||
scc_ir_type_ref_t scc_ir_builder_type(scc_ir_builder_t *builder,
|
||||
const scc_ir_type_t *type_desc);
|
||||
|
||||
// TODO
|
||||
static inline scc_ir_node_ref_t
|
||||
scc_ir_builder_const_int(scc_ir_builder_t *builder, scc_ir_type_ref_t type,
|
||||
scc_ir_const_int_t value) {
|
||||
scc_ir_node_t node;
|
||||
scc_ir_node_init(&node, null, SCC_IR_NODE_CONST_INT);
|
||||
node.data.const_int = value;
|
||||
node.type = type;
|
||||
return scc_ir_module_add_node(&builder->cprog->module, &node);
|
||||
}
|
||||
|
||||
#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) { \
|
||||
scc_ir_type_t type_desc; \
|
||||
scc_ir_type_init(&type_desc, SCC_IR_TYPE_##scc_type); \
|
||||
return scc_ir_ctx_get_type(&builder->ctx, &type_desc); \
|
||||
}
|
||||
|
||||
SCC_IR_BUILDER_TYPE_FUNC(unknown)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(void)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(i8)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(i16)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(i32)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(i64)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(i128)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(u8)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(u16)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(u32)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(u64)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(u128)
|
||||
// SCC_IR_BUILDER_TYPE_FUNC(f8)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(f16)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(f32)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(f64)
|
||||
SCC_IR_BUILDER_TYPE_FUNC(f128)
|
||||
|
||||
/**
|
||||
* @brief 开始构建函数
|
||||
* @param func_ref 函数引用
|
||||
|
||||
Reference in New Issue
Block a user