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)); }