authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2021-01-03 21:57:41+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-06 15:53:10-08:00
logbe6ac82ee1dc6619576da6dc7ba04213faea998d
treefdf527dc1676dedc6e45831db6f94d1e60862c95
parent480d6182ad543ea9e2d7cf0897f6fad7cbefc572

stage2 ARM: fix stack offsets for genSetReg and genSetStack


1 files changed, 11 insertions(+), 11 deletions(-)

src/codegen.zig+11-11
......@@ -2575,12 +2575,12 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
25752575 return self.fail(src, "TODO implement set stack variable from embedded_in_code", .{});
25762576 },
25772577 .register => |reg| {
2578 // TODO: strh
2579 const offset = if (stack_offset <= math.maxInt(u12)) blk: {
2580 break :blk Instruction.Offset.imm(@intCast(u12, stack_offset));
2581 } else Instruction.Offset.reg(try self.copyToTmpRegister(src, MCValue{ .immediate = stack_offset }), 0);
2582
25832578 const abi_size = ty.abiSize(self.target.*);
2579 const adj_off = stack_offset + abi_size;
2580 const offset = if (adj_off <= math.maxInt(u12)) blk: {
2581 break :blk Instruction.Offset.imm(@intCast(u12, adj_off));
2582 } else Instruction.Offset.reg(try self.copyToTmpRegister(src, MCValue{ .immediate = adj_off }), 0);
2583
25842584 switch (abi_size) {
25852585 1 => writeInt(u32, try self.code.addManyAsArray(4), Instruction.strb(.al, reg, .fp, .{
25862586 .offset = offset,
......@@ -2778,21 +2778,21 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
27782778 writeInt(u32, try self.code.addManyAsArray(4), Instruction.ldr(.al, reg, reg, .{ .offset = Instruction.Offset.none }).toU32());
27792779 },
27802780 .stack_offset => |unadjusted_off| {
2781 // TODO: ldrh
27822781 // TODO: maybe addressing from sp instead of fp
2783 const offset = if (unadjusted_off <= math.maxInt(u12)) blk: {
2784 break :blk Instruction.Offset.imm(@intCast(u12, unadjusted_off));
2785 } else Instruction.Offset.reg(try self.copyToTmpRegister(src, MCValue{ .immediate = unadjusted_off }), 0);
2786
27872782 // TODO: supply type information to genSetReg as we do to genSetStack
27882783 // const abi_size = ty.abiSize(self.target.*);
27892784 const abi_size = 4;
2785 const adj_off = unadjusted_off + abi_size;
2786 const offset = if (adj_off <= math.maxInt(u12)) blk: {
2787 break :blk Instruction.Offset.imm(@intCast(u12, adj_off));
2788 } else Instruction.Offset.reg(try self.copyToTmpRegister(src, MCValue{ .immediate = adj_off }), 0);
2789
27902790 switch (abi_size) {
27912791 1 => writeInt(u32, try self.code.addManyAsArray(4), Instruction.ldrb(.al, reg, .fp, .{
27922792 .offset = offset,
27932793 .positive = false,
27942794 }).toU32()),
2795 2 => return self.fail(src, "TODO implement strh", .{}),
2795 2 => return self.fail(src, "TODO implement ldrh", .{}),
27962796 4 => writeInt(u32, try self.code.addManyAsArray(4), Instruction.ldr(.al, reg, .fp, .{
27972797 .offset = offset,
27982798 .positive = false,