From f0706adcc025a66b7fbe1cb923980c4c3eacc176 Mon Sep 17 00:00:00 2001 From: mxr <> Date: Thu, 9 Apr 2026 15:18:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(mir)=E4=BF=AE=E6=94=B9=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E5=9D=97=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mir/AsmPrinter.cpp | 3 ++- src/mir/Lowering.cpp | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mir/AsmPrinter.cpp b/src/mir/AsmPrinter.cpp index 350a3b4..3ea7d37 100644 --- a/src/mir/AsmPrinter.cpp +++ b/src/mir/AsmPrinter.cpp @@ -5,7 +5,7 @@ #include "utils/Log.h" -#define DEBUG_Asm +//#define DEBUG_Asm #ifdef DEBUG_Asm #include @@ -53,6 +53,7 @@ void PrintOperand(std::ostream& os, const Operand& op) { os << CondCodeName(op.GetCondCode()); break; case Operand::Kind::Label: + DEBUG_MSG("label is" << op.GetLabel()); os << op.GetLabel(); break; } diff --git a/src/mir/Lowering.cpp b/src/mir/Lowering.cpp index 7098107..4d6f513 100644 --- a/src/mir/Lowering.cpp +++ b/src/mir/Lowering.cpp @@ -6,6 +6,14 @@ #include "ir/IR.h" #include "utils/Log.h" +#define DEBUG_Lower + +#ifdef DEBUG_Lower +#include +#define DEBUG_MSG(msg) std::cerr << "[Lower Debug] " << msg << std::endl +#else +#define DEBUG_MSG(msg) +#endif namespace mir { namespace { @@ -392,7 +400,8 @@ void LowerInstruction(const ir::Instruction& inst, MachineFunction& function, // 无条件跳转: br label %target const ir::BasicBlock* irTarget = br.GetTarget(); std::string targetLabel = GetBlockLabel(irTarget); - + DEBUG_MSG("br: targetLabel is " << GetBlockLabel(irTarget)); + // 生成 B target_label block.Append(Opcode::B, {Operand::Label(targetLabel)}); } @@ -646,8 +655,10 @@ std::unique_ptr LowerFunction(const ir::Function& func) { std::unordered_map blockMap; // 第一遍:为每个 IR 基本块创建 MIR 基本块 + std::string func_name = func.GetName(); for (const auto& bb : func.GetBlocks()) { - auto mirBB = std::make_unique(bb->GetName()); + // 格式: .L函数名_基本块名 + auto mirBB = std::make_unique(".L" + func_name + "_" + bb->GetName()); blockMap[bb.get()] = mirBB.get(); machine_func->AddBasicBlock(std::move(mirBB)); }