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