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): 改进错误处理机制

- 修正语义分析上下文变量命名
- 添加解析错误码检查,及时返回错误状态
This commit is contained in:
zzy
2026-05-01 22:51:31 +08:00
parent 85d698acdf
commit b06c4fe3cc
14 changed files with 89 additions and 39 deletions

View File

@@ -27,7 +27,7 @@ static scc_hir_type_ref_t parse_base_type(scc_ast2ir_ctx_t *ctx,
return SCC_HIR_REF_nullptr;
}
static inline void parse_struct_union_layout(scc_ast_qual_type_t *type) {}
// static inline void parse_struct_union_layout(scc_ast_qual_type_t *type) {}
// 辅助函数计算数组实际长度如果原长度为0
static void resolve_array_length(scc_ast2ir_ctx_t *ctx,
@@ -163,8 +163,7 @@ scc_hir_type_ref_t scc_ast2ir_type(scc_ast2ir_ctx_t *ctx,
// FIXME hack
ir_type.data.array.len = value.data.digit;
}
break;
}
} break;
case SCC_AST_TYPE_FUNCTION: {
scc_hir_type_init(&ir_type, SCC_HIR_TYPE_FUNC);
@@ -187,8 +186,7 @@ scc_hir_type_ref_t scc_ast2ir_type(scc_ast2ir_ctx_t *ctx,
scc_vec_push(params, tmp_type);
}
ir_type.data.function.params = params;
break;
}
} break;
case SCC_AST_TYPE_STRUCT:
case SCC_AST_TYPE_UNION: {
scc_hir_type_init(&ir_type, ast_type->base.type == SCC_AST_TYPE_STRUCT
@@ -207,15 +205,13 @@ scc_hir_type_ref_t scc_ast2ir_type(scc_ast2ir_ctx_t *ctx,
scc_ast2ir_type(ctx, decl_field->var.type);
scc_vec_push(ir_type.data.aggregate.fields, field_type);
}
break;
}
} break;
case SCC_AST_TYPE_ENUM:
scc_ast_canon_type_t int_canon_type = {
.builtin = SCC_AST_BUILTIN_TYPE_INT,
};
scc_ast_canon_type_t *int_canon_type = scc_ast_ctx_get_builtin_type(
ctx->ast_ctx, SCC_AST_BUILTIN_TYPE_INT);
scc_ast_qual_type_t int_type = {
.base.type = SCC_AST_TYPE_BUILTIN,
.type = &int_canon_type,
.type = int_canon_type,
};
return parse_base_type(ctx, &int_type);
case SCC_AST_TYPE_TYPEDEF:
@@ -883,7 +879,7 @@ void scc_ast2ir_stmt(scc_ast2ir_ctx_t *ctx, const scc_ast_stmt_t *stmt) {
if (stmt->for_stmt.incr) {
scc_ast2ir_expr(ctx, stmt->for_stmt.incr, false);
}
scc_hir_builder_jump(&ctx->builder, exit_block);
scc_hir_builder_jump(&ctx->builder, cond_block);
scc_hir_builder_set_current_bblock(&ctx->builder, exit_block);
break;
@@ -1124,9 +1120,13 @@ void scc_ast2ir_run(scc_ast2ir_ctx_t *ctx,
}
void scc_ast2ir_ctx_init(scc_ast2ir_ctx_t *ctx, const scc_abi_type_calc_t *abi,
scc_hir_cprog_t *cprog) {
scc_ast_ctx_t *ast_ctx, scc_hir_cprog_t *cprog) {
Assert(ctx != nullptr);
Assert(abi != nullptr);
Assert(ast_ctx != nullptr);
Assert(cprog != nullptr);
ctx->abi = abi;
ctx->ast_ctx = ast_ctx;
scc_hir_builder_init(&ctx->builder, cprog);
scc_hashtable_usize_init(&ctx->ast2ir_cache);
scc_hashtable_usize_init(&ctx->break_cache);