fix(mir)修复Ret返回void问题

mxr 1 month ago
parent 8b4ffdde44
commit 4f00d05c86

@ -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");
// 遍历所有函数,输出汇编

@ -5,7 +5,7 @@
#include "utils/Log.h"
#define DEBUG_Frame
//#define DEBUG_Frame
#ifdef DEBUG_Frame
#include <iostream>

@ -7,7 +7,7 @@
#include "ir/IR.h"
#include "utils/Log.h"
#define DEBUG_Lower
//#define DEBUG_Lower
#ifdef DEBUG_Lower
#include <iostream>
@ -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<const ir::ConstantInt*>(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<int>(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<const ir::ReturnInst&>(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;
}

Loading…
Cancel
Save