authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2022-01-18 19:28:39+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-01-19 01:33:18+01:00
logcd594d10bdb930afe0cd05f1fcc8a7ecf2af4554
tree648cd9f223ddc10f2529221da0ceec5d0c4e60c6
parente80ebc6740d6bbe4b9b1958180a337804ff98450

stage2 ARM: basic implementation of ptr_slice_{len,ptr}_ptr


1 files changed, 33 insertions(+), 7 deletions(-)

src/arch/arm/CodeGen.zig+33-7
...@@ -795,11 +795,7 @@ fn spillCompareFlagsIfOccupied(self: *Self) !void {...@@ -795,11 +795,7 @@ fn spillCompareFlagsIfOccupied(self: *Self) !void {
795 assert(mcv == .compare_flags_signed or mcv == .compare_flags_unsigned);795 assert(mcv == .compare_flags_signed or mcv == .compare_flags_unsigned);
796796
797 const new_mcv = try self.allocRegOrMem(inst_to_save, true);797 const new_mcv = try self.allocRegOrMem(inst_to_save, true);
798 switch (new_mcv) {798 try self.setRegOrMem(self.air.typeOfIndex(inst_to_save), new_mcv, mcv);
799 .register => |reg| try self.genSetReg(self.air.typeOfIndex(inst_to_save), reg, mcv),
800 .stack_offset => |offset| try self.genSetStack(self.air.typeOfIndex(inst_to_save), offset, mcv),
801 else => unreachable,
802 }
803 log.debug("spilling {d} to mcv {any}", .{ inst_to_save, new_mcv });799 log.debug("spilling {d} to mcv {any}", .{ inst_to_save, new_mcv });
804800
805 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];801 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
...@@ -1172,9 +1168,14 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -1172,9 +1168,14 @@ fn airSlicePtr(self: *Self, inst: Air.Inst.Index) !void {
1172 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1168 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1173 const mcv = try self.resolveInst(ty_op.operand);1169 const mcv = try self.resolveInst(ty_op.operand);
1174 switch (mcv) {1170 switch (mcv) {
1171 .dead, .unreach => unreachable,
1172 .register => unreachable, // a slice doesn't fit in one register
1175 .stack_offset => |off| {1173 .stack_offset => |off| {
1176 break :result MCValue{ .stack_offset = off };1174 break :result MCValue{ .stack_offset = off };
1177 },1175 },
1176 .memory => |addr| {
1177 break :result MCValue{ .memory = addr };
1178 },
1178 else => return self.fail("TODO implement slice_ptr for {}", .{mcv}),1179 else => return self.fail("TODO implement slice_ptr for {}", .{mcv}),
1179 }1180 }
1180 };1181 };
...@@ -1186,9 +1187,14 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -1186,9 +1187,14 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
1186 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1187 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1187 const mcv = try self.resolveInst(ty_op.operand);1188 const mcv = try self.resolveInst(ty_op.operand);
1188 switch (mcv) {1189 switch (mcv) {
1190 .dead, .unreach => unreachable,
1191 .register => unreachable, // a slice doesn't fit in one register
1189 .stack_offset => |off| {1192 .stack_offset => |off| {
1190 break :result MCValue{ .stack_offset = off + 4 };1193 break :result MCValue{ .stack_offset = off + 4 };
1191 },1194 },
1195 .memory => |addr| {
1196 break :result MCValue{ .memory = addr + 4 };
1197 },
1192 else => return self.fail("TODO implement slice_len for {}", .{mcv}),1198 else => return self.fail("TODO implement slice_len for {}", .{mcv}),
1193 }1199 }
1194 };1200 };
...@@ -1197,13 +1203,33 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {...@@ -1197,13 +1203,33 @@ fn airSliceLen(self: *Self, inst: Air.Inst.Index) !void {
11971203
1198fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {1204fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
1199 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1205 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1200 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_slice_len_ptr for {}", .{self.target.cpu.arch});1206 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1207 const mcv = try self.resolveInst(ty_op.operand);
1208 switch (mcv) {
1209 .dead, .unreach => unreachable,
1210 .register => unreachable, // a slice doesn't fit in one register
1211 .ptr_stack_offset => |off| {
1212 break :result MCValue{ .ptr_stack_offset = off + 4 };
1213 },
1214 else => return self.fail("TODO implement ptr_slice_len_ptr for {}", .{mcv}),
1215 }
1216 };
1201 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1217 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1202}1218}
12031219
1204fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {1220fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
1205 const ty_op = self.air.instructions.items(.data)[inst].ty_op;1221 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1206 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement ptr_slice_ptr_ptr for {}", .{self.target.cpu.arch});1222 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1223 const mcv = try self.resolveInst(ty_op.operand);
1224 switch (mcv) {
1225 .dead, .unreach => unreachable,
1226 .register => unreachable, // a slice doesn't fit in one register
1227 .ptr_stack_offset => |off| {
1228 break :result MCValue{ .ptr_stack_offset = off };
1229 },
1230 else => return self.fail("TODO implement ptr_slice_ptr_ptr for {}", .{mcv}),
1231 }
1232 };
1207 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });1233 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
1208}1234}
12091235