fix(ir): 规范ir实现
This commit is contained in:
@@ -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_);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user