fix(irgen): 规范irgen实现

This commit is contained in:
jing
2026-03-11 01:15:13 +08:00
parent 11f192cd10
commit a44a409d16
7 changed files with 51 additions and 44 deletions

View File

@@ -8,6 +8,7 @@
namespace {
void VerifyFunctionStructure(const ir::Function& func) {
// 当前 IRGen 仍是单入口、顺序生成;这里在生成结束后补一层块终结校验。
for (const auto& bb : func.blocks()) {
if (!bb || !bb->HasTerminator()) {
throw std::runtime_error("[irgen] 基本块未正确终结: " +
@@ -41,5 +42,6 @@ void IRGenImpl::GenFuncDef(SysYParser::FuncDefContext& func) {
locals_.clear();
GenBlock(*func.block());
// 语义正确性主要由 sema 保证,这里只兜底检查 IR 结构是否合法。
VerifyFunctionStructure(*func_);
}