feat(mir): 增加 Lab3 AArch64 MVP 后端与 --emit-asm 支持

This commit is contained in:
Lane0218
2026-03-07 22:41:53 +08:00
parent 0ff3d918d9
commit b939fc40ee
15 changed files with 592 additions and 33 deletions

View File

@@ -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";