Implement stack_addr for AArch64

This commit is contained in:
bjorn3
2020-04-15 18:28:31 +02:00
parent d2eb56c607
commit 1bee1af755
6 changed files with 95 additions and 3 deletions

View File

@@ -6,11 +6,10 @@ use crate::ir::types::*;
use crate::ir::TrapCode;
use crate::isa::aarch64::inst::*;
use core::convert::TryFrom;
use regalloc::{Reg, RegClass, Writable};
use alloc::vec::Vec;
use core::convert::TryFrom;
/// Memory label/reference finalization: convert a MemLabel to a PC-relative
/// offset, possibly emitting relocation(s) as necessary.
@@ -1275,6 +1274,40 @@ impl<O: MachSectionOutput> MachInstEmit<O> for Inst {
sink.add_reloc(srcloc, Reloc::Abs8, name, offset);
sink.put8(0);
}
&Inst::LoadAddr { rd, ref mem } => match *mem {
MemArg::FPOffset(fp_off) => {
let alu_op = if fp_off < 0 {
ALUOp::Sub64
} else {
ALUOp::Add64
};
if let Some(imm12) = Imm12::maybe_from_u64(u64::try_from(fp_off.abs()).unwrap())
{
let inst = Inst::AluRRImm12 {
alu_op,
rd,
imm12,
rn: fp_reg(),
};
inst.emit(sink);
} else {
let tmp = writable_spilltmp_reg();
let const_insts =
Inst::load_constant(tmp, u64::try_from(fp_off.abs()).unwrap());
for inst in const_insts {
inst.emit(sink);
}
let inst = Inst::AluRRR {
alu_op,
rd,
rn: fp_reg(),
rm: tmp.to_reg(),
};
inst.emit(sink);
}
}
_ => unimplemented!("{:?}", mem),
},
}
}
}