refactor(frontend): 添加对只编译前端的支持
This commit is contained in:
@@ -4,10 +4,12 @@
|
||||
|
||||
#include "frontend/AntlrDriver.h"
|
||||
#include "frontend/SyntaxTreePrinter.h"
|
||||
#if !COMPILER_PARSE_ONLY
|
||||
#include "ir/IR.h"
|
||||
#include "irgen/IRGen.h"
|
||||
#include "mir/MIR.h"
|
||||
#include "sem/Sema.h"
|
||||
#endif
|
||||
#include "utils/CLI.h"
|
||||
#include "utils/Log.h"
|
||||
|
||||
@@ -26,6 +28,7 @@ int main(int argc, char** argv) {
|
||||
need_blank_line = true;
|
||||
}
|
||||
|
||||
#if !COMPILER_PARSE_ONLY
|
||||
auto* comp_unit = dynamic_cast<SysYParser::CompUnitContext*>(antlr.tree);
|
||||
if (!comp_unit) {
|
||||
throw std::runtime_error(FormatError("main", "语法树根节点不是 compUnit"));
|
||||
@@ -51,6 +54,12 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
mir::PrintAsm(*machine_func, std::cout);
|
||||
}
|
||||
#else
|
||||
if (opts.emit_ir || opts.emit_asm) {
|
||||
throw std::runtime_error(
|
||||
FormatError("main", "当前为 parse-only 构建;IR/汇编输出已禁用"));
|
||||
}
|
||||
#endif
|
||||
} catch (const std::exception& ex) {
|
||||
PrintException(std::cerr, ex);
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user