fix(dev): 统一 IR/MIR 异常前缀

This commit is contained in:
Lane0218
2026-03-12 15:01:19 +08:00
parent f3d0102376
commit a7779038ca
6 changed files with 53 additions and 32 deletions

View File

@@ -3,13 +3,15 @@
#include <ostream>
#include <stdexcept>
#include "utils/Log.h"
namespace mir {
namespace {
const FrameSlot& GetFrameSlot(const MachineFunction& function,
const Operand& operand) {
if (operand.kind() != Operand::Kind::FrameIndex) {
throw std::runtime_error("期望 FrameIndex 操作数");
throw std::runtime_error(FormatError("mir", "期望 FrameIndex 操作数"));
}
return function.frame_slot(operand.frame_index());
}

View File

@@ -3,6 +3,8 @@
#include <stdexcept>
#include <utility>
#include "utils/Log.h"
namespace mir {
MachineFunction::MachineFunction(std::string name)
@@ -16,14 +18,14 @@ int MachineFunction::CreateFrameIndex(int size) {
FrameSlot& MachineFunction::frame_slot(int index) {
if (index < 0 || index >= static_cast<int>(frame_slots_.size())) {
throw std::runtime_error("非法 FrameIndex");
throw std::runtime_error(FormatError("mir", "非法 FrameIndex"));
}
return frame_slots_[index];
}
const FrameSlot& MachineFunction::frame_slot(int index) const {
if (index < 0 || index >= static_cast<int>(frame_slots_.size())) {
throw std::runtime_error("非法 FrameIndex");
throw std::runtime_error(FormatError("mir", "非法 FrameIndex"));
}
return frame_slots_[index];
}

View File

@@ -2,6 +2,8 @@
#include <stdexcept>
#include "utils/Log.h"
namespace mir {
const char* PhysRegName(PhysReg reg) {
@@ -19,7 +21,7 @@ const char* PhysRegName(PhysReg reg) {
case PhysReg::SP:
return "sp";
}
throw std::runtime_error("未知物理寄存器");
throw std::runtime_error(FormatError("mir", "未知物理寄存器"));
}
} // namespace mir