feat(mir): 增加 Lab3 AArch64 MVP 后端与 --emit-asm 支持
This commit is contained in:
17
src/main.cpp
17
src/main.cpp
@@ -7,6 +7,7 @@
|
||||
#include "frontend/AstBuilder.h"
|
||||
#include "ir/IR.h"
|
||||
#include "irgen/IRGen.h"
|
||||
#include "mir/MIR.h"
|
||||
#include "sem/Sema.h"
|
||||
#include "utils/CLI.h"
|
||||
#include "utils/Log.h"
|
||||
@@ -21,8 +22,10 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
auto antlr = ParseFileWithAntlr(opts.input);
|
||||
auto ast = BuildAst(antlr.tree);
|
||||
bool need_blank_line = false;
|
||||
if (opts.emit_ast) {
|
||||
ast::PrintAST(*ast); // 调试 AST
|
||||
need_blank_line = true;
|
||||
}
|
||||
if (!opts.ast_dot_output.empty()) {
|
||||
std::ofstream dot_out(opts.ast_dot_output);
|
||||
@@ -38,7 +41,21 @@ int main(int argc, char** argv) {
|
||||
|
||||
if (opts.emit_ir) {
|
||||
ir::IRPrinter printer;
|
||||
if (need_blank_line) {
|
||||
std::cout << "\n";
|
||||
}
|
||||
printer.Print(*module);
|
||||
need_blank_line = true;
|
||||
}
|
||||
|
||||
if (opts.emit_asm) {
|
||||
auto machine_func = mir::LowerToMIR(*module);
|
||||
mir::RunRegAlloc(*machine_func);
|
||||
mir::RunFrameLowering(*machine_func);
|
||||
if (need_blank_line) {
|
||||
std::cout << "\n";
|
||||
}
|
||||
mir::PrintAsm(*machine_func, std::cout);
|
||||
}
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << "error: " << ex.what() << "\n";
|
||||
|
||||
Reference in New Issue
Block a user