diff --git a/src/mir/AsmPrinter.cpp b/src/mir/AsmPrinter.cpp index 6d8ca3c..4550730 100644 --- a/src/mir/AsmPrinter.cpp +++ b/src/mir/AsmPrinter.cpp @@ -314,7 +314,6 @@ void PrintAsm(const MachineFunction& function, std::ostream& os) { void PrintAsm(const MachineModule& module, std::ostream& os) { // 输出文件头 os << ".arch armv8-a\n"; - os << ".text\n"; DEBUG_MSG("module"); // 遍历所有函数,输出汇编 diff --git a/src/mir/FrameLowering.cpp b/src/mir/FrameLowering.cpp index b9fa84e..6758105 100644 --- a/src/mir/FrameLowering.cpp +++ b/src/mir/FrameLowering.cpp @@ -5,7 +5,7 @@ #include "utils/Log.h" -#define DEBUG_Frame +//#define DEBUG_Frame #ifdef DEBUG_Frame #include diff --git a/src/mir/Lowering.cpp b/src/mir/Lowering.cpp index 3365385..013aa26 100644 --- a/src/mir/Lowering.cpp +++ b/src/mir/Lowering.cpp @@ -7,7 +7,7 @@ #include "ir/IR.h" #include "utils/Log.h" -#define DEBUG_Lower +//#define DEBUG_Lower #ifdef DEBUG_Lower #include @@ -125,6 +125,9 @@ void EmitValueToReg(const ir::Value* value, PhysReg target, const ValueSlotMap& slots, MachineBasicBlock& block, MachineFunction& function) { // 处理整数常量 + if (value == nullptr) { + DEBUG_MSG( "EmitValueToReg called with null value\n"); + } if (auto* constant = dynamic_cast(value)) { block.Append(Opcode::MovImm, {Operand::Reg(target), Operand::Imm(constant->GetValue())}); @@ -219,7 +222,6 @@ void LowerInstruction(const ir::Instruction& inst, MachineFunction& function, //auto& block = function.GetEntry(); DEBUG_MSG("Processing instruction: " << inst.GetName() << " (opcode: " << static_cast(inst.GetOpcode()) << ")"); - switch (inst.GetOpcode()) { case ir::Opcode::Alloca: { slots.emplace(&inst, function.CreateFrameIndex(GetTypeSize(inst.GetType().get()))); @@ -326,7 +328,10 @@ void LowerInstruction(const ir::Instruction& inst, MachineFunction& function, } case ir::Opcode::Ret: { auto& ret = static_cast(inst); - EmitValueToReg(ret.GetValue(), PhysReg::W0, slots, block, function); + const ir::Value* retVal = ret.GetValue(); + if (retVal != nullptr) { + EmitValueToReg(retVal, PhysReg::W0, slots, block, function); + } block.Append(Opcode::Ret); return; }