Files
scc/libs/lir/include/scc_lir_module.h
zzy e5bbffe170 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 转换器头文件和转储功能
2026-04-18 11:35:43 +08:00

99 lines
3.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file scc_lir_module.h
* @brief LIR 模块:管理函数定义、全局符号和声明
*/
#ifndef __SCC_LIR_MODULE_H__
#define __SCC_LIR_MODULE_H__
#include "scc_lir.h"
#include <scc_core.h>
#include <scc_hashtable.h>
typedef enum scc_lir_symbol_kind {
SCC_LIR_SYMBOL_FUNC, // 函数符号
SCC_LIR_SYMBOL_DATA, // 数据符号(全局变量、常量)
SCC_LIR_SYMBOL_EXTERN, // 外部符号(未定义,需链接器解析)
} scc_lir_symbol_kind_t;
typedef struct scc_lir_symbol {
const char *name; // 符号名(驻留字符串或前端管理)
scc_lir_symbol_kind_t kind; // 符号类型
scc_lir_attr_t attr; // 属性static, weak 等)
union {
struct {
scc_lir_func_t *func; // 指向函数体(若为定义)
} func;
struct {
u8 *init_data; // 初始化数据(若为 NULL 则零初始化)
usize size; // 数据大小(字节)
int align; // 对齐要求
} data;
};
} scc_lir_symbol_t;
typedef struct scc_lir_module {
SCC_VEC(scc_lir_func_t *) funcs; // 所有函数定义(按添加顺序)
SCC_VEC(scc_lir_symbol_t) symbols; // 所有全局符号(包含声明和定义)
scc_hashtable_t symbol_map; // name -> 索引 (usize) 在 symbols 向量中
} scc_lir_module_t;
/**
* @brief 初始化 LIR 模块
*/
void scc_lir_module_init(scc_lir_module_t *module);
/**
* @brief 销毁 LIR 模块,释放所有函数和符号资源
*/
void scc_lir_module_drop(scc_lir_module_t *module);
/**
* @brief 添加一个函数定义到模块
* @param mod 模块
* @param func 函数定义(所有权转移给模块)
* @return 符号指针(内部持有,不可释放)
*/
const scc_lir_symbol_t *scc_lir_module_add_func_def(scc_lir_module_t *module,
scc_lir_func_t *func);
/**
* @brief 添加一个函数声明(外部或未定义)
* @param mod 模块
* @param name 函数名
* @param attr 属性
* @return 符号指针
*/
const scc_lir_symbol_t *scc_lir_module_add_func_decl(scc_lir_module_t *module,
const char *name,
scc_lir_attr_t attr);
/**
* @brief 添加一个全局数据符号(定义或外部)
* @param mod 模块
* @param name 符号名
* @param kind 种类DATA 或 EXTERN
* @param init_data 初始化数据(若为 DATA 定义;若为 NULL 则零初始化)
* @param size 数据大小(若为 EXTERN 可为 0
* @param align 对齐要求
* @param attr 属性
* @return 符号指针
*/
const scc_lir_symbol_t *scc_lir_module_add_data(scc_lir_module_t *module,
const char *name,
scc_lir_symbol_kind_t kind,
const u8 *init_data, usize size,
u32 align, scc_lir_attr_t attr);
/**
* @brief 通过名称查找符号
* @param mod 模块
* @param name 符号名
* @return 符号指针,未找到返回 nullptr
*/
const scc_lir_symbol_t *
scc_lir_module_lookup_symbol(const scc_lir_module_t *module, const char *name);
#endif /* __SCC_LIR_MODULE_H__ */