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 {...@@ -2575,12 +2575,12 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2575 return self.fail(src, "TODO implement set stack variable from embedded_in_code", .{});2575 return self.fail(src, "TODO implement set stack variable from embedded_in_code", .{});
2576 },2576 },
2577 .register => |reg| {2577 .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
2583 const abi_size = ty.abiSize(self.target.*);2578 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
2584 switch (abi_size) {2584 switch (abi_size) {
2585 1 => writeInt(u32, try self.code.addManyAsArray(4), Instruction.strb(.al, reg, .fp, .{2585 1 => writeInt(u32, try self.code.addManyAsArray(4), Instruction.strb(.al, reg, .fp, .{
2586 .offset = offset,2586 .offset = offset,
...@@ -2778,21 +2778,21 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2778,21 +2778,21 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2778 writeInt(u32, try self.code.addManyAsArray(4), Instruction.ldr(.al, reg, reg, .{ .offset = Instruction.Offset.none }).toU32());2778 writeInt(u32, try self.code.addManyAsArray(4), Instruction.ldr(.al, reg, reg, .{ .offset = Instruction.Offset.none }).toU32());
2779 },2779 },
2780 .stack_offset => |unadjusted_off| {2780 .stack_offset => |unadjusted_off| {
2781 // TODO: ldrh
2782 // TODO: maybe addressing from sp instead of fp2781 // 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
2787 // TODO: supply type information to genSetReg as we do to genSetStack2782 // TODO: supply type information to genSetReg as we do to genSetStack
2788 // const abi_size = ty.abiSize(self.target.*);2783 // const abi_size = ty.abiSize(self.target.*);
2789 const abi_size = 4;2784 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
2790 switch (abi_size) {2790 switch (abi_size) {
2791 1 => writeInt(u32, try self.code.addManyAsArray(4), Instruction.ldrb(.al, reg, .fp, .{2791 1 => writeInt(u32, try self.code.addManyAsArray(4), Instruction.ldrb(.al, reg, .fp, .{
2792 .offset = offset,2792 .offset = offset,
2793 .positive = false,2793 .positive = false,
2794 }).toU32()),2794 }).toU32()),
2795 2 => return self.fail(src, "TODO implement strh", .{}),2795 2 => return self.fail(src, "TODO implement ldrh", .{}),
2796 4 => writeInt(u32, try self.code.addManyAsArray(4), Instruction.ldr(.al, reg, .fp, .{2796 4 => writeInt(u32, try self.code.addManyAsArray(4), Instruction.ldr(.al, reg, .fp, .{
2797 .offset = offset,2797 .offset = offset,
2798 .positive = false,2798 .positive = false,