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

@@ -1,4 +1,33 @@
// 寄存器分配:
// - 将虚拟寄存器分配到物理寄存器
// - 处理 spill/reload并为后续栈帧布局提供栈槽需求信息
#include "mir/MIR.h"
#include <stdexcept>
namespace mir {
namespace {
bool IsAllowedReg(PhysReg reg) {
switch (reg) {
case PhysReg::W0:
case PhysReg::W8:
case PhysReg::W9:
case PhysReg::X29:
case PhysReg::X30:
case PhysReg::SP:
return true;
}
return false;
}
} // namespace
void RunRegAlloc(MachineFunction& function) {
for (const auto& inst : function.entry().instructions()) {
for (const auto& operand : inst.operands()) {
if (operand.kind() == Operand::Kind::Reg && !IsAllowedReg(operand.reg())) {
throw std::runtime_error("Lab3 MVP 后端发现未预着色的寄存器");
}
}
}
}
} // namespace mir