fix(ir): 规范ir实现

feature/antlr4
jing 1 week ago
parent 8f448df4bc
commit 11f192cd10

@ -5,6 +5,19 @@
#include "SysYParser.h"
#include "ir/IR.h"
namespace {
void VerifyFunctionStructure(const ir::Function& func) {
for (const auto& bb : func.blocks()) {
if (!bb || !bb->HasTerminator()) {
throw std::runtime_error("[irgen] 基本块未正确终结: " +
(bb ? bb->name() : std::string("<null>")));
}
}
}
} // namespace
IRGenImpl::IRGenImpl(ir::Module& module)
: module_(module), func_(nullptr), builder_(nullptr) {}
@ -28,4 +41,5 @@ void IRGenImpl::GenFuncDef(SysYParser::FuncDefContext& func) {
locals_.clear();
GenBlock(*func.block());
VerifyFunctionStructure(*func_);
}

Loading…
Cancel
Save