feat(ast): 添加汇编器模块并改进AST定义和IR转换

- 在README.md中添加asm汇编器模块说明
- 更新ast_def.h中的枚举注释,添加sema相关信息以明确语义分析作用域
- 重命名函数参数param_types为params,使命名更清晰
- 移除call表达式中的_target字段,简化结构
- 为member、identifier等字段添加///< fill by sema注释说明填充时机
- 为jump语句添加_target字段用于语义分析
- 更新所有AST初始化函数,接受位置信息参数以改进错误定位
- 修复alignof表达式的类型应为ALIGN_OF而非SIZE_OF的问题
- 重构ast2ir.h,引入scc_ast2ir_ctx_t上下文结构体统一管理转换状态
- 添加符号表、节点到IR映射等必要的转换上下文信息
This commit is contained in:
zzy
2026-03-17 20:29:40 +08:00
parent cabd1710ed
commit 2e5e98868d
29 changed files with 1289 additions and 1000 deletions

View File

@@ -10,7 +10,7 @@
typedef enum {
SCC_AST_UNKNOWN,
// 声明
scc_ast_decl_t_BEGIN, // 声明开始
scc_ast_decl_t_BEGIN, // 声明开始 sema 函数作用域开始
SCC_AST_DECL_LIST, // 声明列表
SCC_AST_DECL_VAR, // 变量声明
SCC_AST_DECL_FUNC, // 函数声明
@@ -19,10 +19,10 @@ typedef enum {
SCC_AST_DECL_UNION, // 联合声明
SCC_AST_DECL_ENUM, // 枚举声明
SCC_AST_DECL_TYPEDEF, // typedef 声明
scc_ast_decl_t_END, // 声明结束
scc_ast_decl_t_END, // 声明结束 sema 函数作用域结束
// 语句
scc_ast_stmt_t_BEGIN, // 语句开始
scc_ast_stmt_t_BEGIN, // 语句开始 sema 作用域开始
SCC_AST_STMT_COMPOUND, // 复合语句 { ... }
SCC_AST_STMT_EXPR, // 表达式语句
SCC_AST_STMT_IF, // if 语句
@@ -37,7 +37,7 @@ typedef enum {
SCC_AST_STMT_RETURN, // return 语句
SCC_AST_STMT_GOTO, // goto 语句
SCC_AST_STMT_LABEL, // 标签语句
scc_ast_stmt_t_END, // 结束语句
scc_ast_stmt_t_END, // 结束语句 sema 作用域结束
// 表达式
scc_ast_expr_t_BEGIN, // 表达式开始
@@ -180,7 +180,7 @@ struct scc_ast_type {
} array;
struct {
scc_ast_type_t *return_type;
scc_ast_decl_vec_t param_types; // va_list <=> ...
scc_ast_decl_vec_t params; // va_list <=> ...
} function;
struct {
const char *name;
@@ -294,7 +294,6 @@ struct scc_ast_expr {
struct {
const char *name;
scc_ast_expr_t *callee;
scc_ast_expr_t *_target;
scc_ast_expr_vec_t args;
} call;
// 数组下标
@@ -306,7 +305,7 @@ struct scc_ast_expr {
struct {
scc_ast_expr_t *base;
const char *name;
usize _target_idx;
usize _target_idx; ///< fill by sema
} member;
// cast 类型转换
struct {
@@ -332,7 +331,7 @@ struct scc_ast_expr {
// 标识符
struct {
const char *name;
scc_ast_decl_t *_target;
scc_ast_decl_t *_target; ///< fill by sema
} identifier;
struct {
scc_ast_type_t *type;
@@ -393,6 +392,7 @@ struct scc_ast_stmt {
} default_stmt;
// break/continue
struct {
scc_ast_stmt_t *_target; // fill by sema
} jump;
// return 语句
struct {