refactor(dev): unify user-facing diagnostics
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "SysYParser.h"
|
||||
#include "ir/IR.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -11,8 +12,9 @@ void VerifyFunctionStructure(const ir::Function& func) {
|
||||
// 当前 IRGen 仍是单入口、顺序生成;这里在生成结束后补一层块终结校验。
|
||||
for (const auto& bb : func.blocks()) {
|
||||
if (!bb || !bb->HasTerminator()) {
|
||||
throw std::runtime_error("[irgen] 基本块未正确终结: " +
|
||||
(bb ? bb->name() : std::string("<null>")));
|
||||
throw std::runtime_error(
|
||||
FormatError("irgen", "基本块未正确终结: " +
|
||||
(bb ? bb->name() : std::string("<null>"))));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,17 +26,17 @@ IRGenImpl::IRGenImpl(ir::Module& module)
|
||||
|
||||
void IRGenImpl::Gen(SysYParser::CompUnitContext& cu) {
|
||||
if (!cu.funcDef()) {
|
||||
throw std::runtime_error("[irgen] 缺少 main 定义");
|
||||
throw std::runtime_error(FormatError("irgen", "缺少 main 定义"));
|
||||
}
|
||||
GenFuncDef(*cu.funcDef());
|
||||
}
|
||||
|
||||
void IRGenImpl::GenFuncDef(SysYParser::FuncDefContext& func) {
|
||||
if (!func.block()) {
|
||||
throw std::runtime_error("[irgen] 函数体为空");
|
||||
throw std::runtime_error(FormatError("irgen", "函数体为空"));
|
||||
}
|
||||
if (!func.Ident()) {
|
||||
throw std::runtime_error("[irgen] 缺少函数名");
|
||||
throw std::runtime_error(FormatError("irgen", "缺少函数名"));
|
||||
}
|
||||
|
||||
func_ = module_.CreateFunction(func.Ident()->getText(), ir::Type::Int32());
|
||||
|
||||
Reference in New Issue
Block a user