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

@@ -80,8 +80,8 @@ scc_ir_func_ref_t scc_ir_builder_current_func(scc_ir_builder_t *builder) {
return builder->current_func;
}
scc_ir_bblock_ref_t scc_ir_builder_begin_bblock(scc_ir_builder_t *builder,
const char *label) {
scc_ir_bblock_ref_t scc_ir_builder_bblock(scc_ir_builder_t *builder,
const char *label) {
scc_ir_bblock_t bblock = {0};
if (label) {
@@ -100,16 +100,22 @@ scc_ir_bblock_ref_t scc_ir_builder_begin_bblock(scc_ir_builder_t *builder,
scc_ir_bblock_ref_t bblock_ref =
scc_ir_ctx_new_bblock(&builder->ctx, &bblock);
builder->current_bblock = bblock_ref;
return bblock_ref;
}
scc_ir_bblock_ref_t scc_ir_builder_begin_bblock(scc_ir_builder_t *builder,
const char *label) {
builder->current_bblock = scc_ir_builder_bblock(builder, label);
// 将基本块添加到当前函数
scc_ir_func_t *current_func =
scc_ir_ctx_get_func(&builder->ctx, builder->current_func);
if (current_func) {
scc_vec_push(current_func->bblocks, bblock_ref);
scc_vec_push(current_func->bblocks, builder->current_bblock);
}
return bblock_ref;
return builder->current_bblock;
}
void scc_ir_builder_end_bblock(scc_ir_builder_t *builder) {
@@ -152,13 +158,13 @@ scc_ir_node_ref_t scc_ir_builder_alloca(scc_ir_builder_t *builder,
}
scc_ir_node_ref_t scc_ir_builder_load(scc_ir_builder_t *builder,
scc_ir_node_ref_t ptr) {
scc_ir_node_ref_t target) {
scc_ir_node_t load_node = {0};
load_node.tag = SCC_IR_NODE_LOAD;
load_node.data.load.target = ptr;
load_node.data.load.target = target;
// 设置类型为指针指向的类型
scc_ir_node_t *ptr_node = scc_ir_ctx_get_node(&builder->ctx, ptr);
scc_ir_node_t *ptr_node = scc_ir_ctx_get_node(&builder->ctx, target);
if (ptr_node) {
scc_ir_type_t *ptr_type =
scc_ir_ctx_get_type(&builder->ctx, ptr_node->type);
@@ -176,11 +182,11 @@ scc_ir_node_ref_t scc_ir_builder_load(scc_ir_builder_t *builder,
}
scc_ir_node_ref_t scc_ir_builder_store(scc_ir_builder_t *builder,
scc_ir_node_ref_t ptr,
scc_ir_node_ref_t target,
scc_ir_node_ref_t value) {
scc_ir_node_t store_node = {0};
store_node.tag = SCC_IR_NODE_STORE;
store_node.data.store.target = ptr;
store_node.data.store.target = target;
store_node.data.store.value = value;
scc_ir_node_ref_t node_ref =
@@ -193,15 +199,15 @@ scc_ir_node_ref_t scc_ir_builder_store(scc_ir_builder_t *builder,
}
scc_ir_node_ref_t scc_ir_builder_get_ptr(scc_ir_builder_t *builder,
scc_ir_node_ref_t ptr,
scc_ir_node_ref_t target,
scc_ir_node_ref_t index) {
scc_ir_node_t get_ptr_node = {0};
get_ptr_node.tag = SCC_IR_NODE_GET_PTR;
get_ptr_node.data.get_ptr.src_addr = ptr;
get_ptr_node.data.get_ptr.src_addr = target;
get_ptr_node.data.get_ptr.index = index;
// 类型应与源地址相同(都是指针)
scc_ir_node_t *src_node = scc_ir_ctx_get_node(&builder->ctx, ptr);
scc_ir_node_t *src_node = scc_ir_ctx_get_node(&builder->ctx, target);
if (src_node) {
get_ptr_node.type = src_node->type;
}