- 添加 scc_ast2ir_mir_module 内联函数统一访问模块 - 替换所有直接访问 ctx->builder.cprog->module 的地方 - 移除重复的 scc_hir_type_size 函数实现 - 添加 scc_hir_module_type_size 函数到模块接口 - 更新所有类型大小计算调用使用新函数 feat(hir): 增强构建器安全性和全局变量处理 - 为 scc_hir_builder_integer 添加空指针检查断言 - 修复 scc_hir_builder_global_alloca 中全局变量类型设置 - 改进 scc_hir_builder_get_elem_ptr 处理空指针索引情况 - 重构字符串常量生成使用 get_elem_ptr 构建器函数 refactor(lir): 简化地址表达式表示并增强内置函数支持 - 移除复杂地址结构体 scc_lir_addr_t - 简化 scc_lir_instr 结构体中的地址表示 - 移除 STORE_ADDR 操作码 - 添加 memcpy 和 memset 内置函数操作码 - 在符号元数据中使用联合体替代嵌套结构体 feat(hir2lir): 完善 HIR 到 LIR 转换中的内置函数处理 - 添加 ensure_vreg 辅助函数确保虚拟寄存器操作数 - 正确处理全局变量地址符号引用 - 优化 GET_ELEM_PTR 转换使用类型大小计算 - 完整实现所有内置函数(BUILTIN)的 LIR 转换 - 包括 memcpy、memset、va_start、va_arg、va_end、va_copy 等
42 lines
1.6 KiB
C
42 lines
1.6 KiB
C
#ifndef __SCC_AST2IR_H__
|
|
#define __SCC_AST2IR_H__
|
|
|
|
#include <scc_ast.h>
|
|
#include <scc_hir_builder.h>
|
|
#include <scc_type_abi.h>
|
|
|
|
typedef struct {
|
|
scc_hir_builder_t builder;
|
|
scc_hashtable_t ast2ir_cache; ///< ast node to ir ref cache
|
|
scc_hashtable_t break_cache; ///< break cache
|
|
scc_hashtable_t continue_cache; ///< continue cache
|
|
scc_hashtable_t symtab; ///< symbol to ir_ref
|
|
scc_hashtable_t type_cache; ///< scc_ast_canon_type_t* -> scc_hir_type_ref_t
|
|
// scc_strpool_t strpool; ///< string pool
|
|
const scc_abi_type_calc_t *abi;
|
|
cbool hint_using_value; // 转换时尽可能使用value而不是alloc
|
|
|
|
scc_ast_ctx_t *ast_ctx;
|
|
} scc_ast2ir_ctx_t;
|
|
|
|
static inline scc_hir_module_t *scc_ast2ir_mir_module(scc_ast2ir_ctx_t *ctx) {
|
|
return &ctx->builder.cprog->module;
|
|
}
|
|
|
|
void scc_ast2ir_ctx_init(scc_ast2ir_ctx_t *ctx, const scc_abi_type_calc_t *abi,
|
|
scc_ast_ctx_t *ast_ctx, scc_hir_cprog_t *cprog);
|
|
void scc_ast2ir_ctx_drop(scc_ast2ir_ctx_t *ctx);
|
|
|
|
void scc_ast2ir_run(scc_ast2ir_ctx_t *ctx,
|
|
const scc_ast_translation_unit_t *tu);
|
|
void scc_ast2ir_decl(scc_ast2ir_ctx_t *ctx, const scc_ast_decl_t *decl,
|
|
cbool is_global);
|
|
scc_hir_value_ref_t scc_ast2ir_expr(scc_ast2ir_ctx_t *ctx,
|
|
const scc_ast_expr_t *expr,
|
|
cbool is_lvalue);
|
|
void scc_ast2ir_stmt(scc_ast2ir_ctx_t *ctx, const scc_ast_stmt_t *stmt);
|
|
scc_hir_type_ref_t scc_ast2ir_type(scc_ast2ir_ctx_t *ctx,
|
|
const scc_ast_qual_type_t *ast_type);
|
|
|
|
#endif /* __SCC_AST2IR_H__ */
|