Files
scc/libs/ast2ir/include/scc_ast2ir.h
zzy b06c4fe3cc feat(ast2ir): 添加AST上下文支持并修复类型转换逻辑
- 在scc_ast2ir_ctx_t中添加ast_ctx字段用于访问AST上下文
- 修改scc_ast2ir_ctx_init函数签名以接收ast_ctx参数
- 修复enum类型的处理逻辑,使用正确的内置类型获取方式
- 修正for循环控制流中错误的跳转目标
- 移除未使用的parse_struct_union_layout函数

refactor(cfg): 优化模块接口的const正确性

- 将scc_cfg_module_unsafe_get_*系列函数的module参数标记为const
- 提高接口的安全性和一致性

refactor(lir): 简化寄存器定义宏

- 移除未使用的SCC_LIR_PREG宏定义
- 简化头文件中的冗余声明

fix(hir2lir): 修复空指针常量的表示方式

- 修正NULL值的AP整数表示,正确初始化ap结构体字段
- 确保空指针在低级IR中被正确表示

refactor(mir): 重构函数元数据结构

- 为MIR函数元数据添加栈槽位和寄存器分配相关字段
- 定义新的栈槽位数据结构scc_mir_stack_slot_t
- 添加函数元数据初始化函数scc_mir_func_meta_init

refactor(x86): 改进后端代码生成

- 修正ret指令生成,使用近返回指令RET_NEAR
- 修复伪alloca指令的形式转换问题
- 改进选择函数的const正确性
- 正确初始化函数元数据结构

style(config): 添加MIR阶段配置选项

- 为MIR各个处理阶段添加配置标志
- 包括寄存器分配、栈布局和前言后记生成的输出选项

fix(parser): 改进错误处理机制

- 修正语义分析上下文变量命名
- 添加解析错误码检查,及时返回错误状态
2026-05-01 22:51:31 +08:00

37 lines
1.4 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_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;
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__ */