|
|
|
|
@ -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_);
|
|
|
|
|
}
|
|
|
|
|
|