commit 3383064b27cc8ad7aa997f6504d627af1fa8c960 (tree)
parent 78e6f9c44c054b922ed1eaafcc4534edcf2dc9ba
Author: Jakub Konka <kubkon@jakubkonka.com>
Date: Wed, 16 Feb 2022 14:05:48 +0100
x64: implement airSlice
Diffstat:
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig
@@ -1071,10 +1071,21 @@ fn airMax(self: *Self, inst: Air.Inst.Index) !void {
fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
- const result: MCValue = if (self.liveness.isUnused(inst))
- .dead
- else
- return self.fail("TODO implement slice for {}", .{self.target.cpu.arch});
+
+ if (self.liveness.isUnused(inst)) {
+ return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none });
+ }
+
+ const ptr = try self.resolveInst(bin_op.lhs);
+ const ptr_ty = self.air.typeOf(bin_op.lhs);
+ const len = try self.resolveInst(bin_op.rhs);
+ const len_ty = self.air.typeOf(bin_op.rhs);
+
+ const stack_offset = @intCast(i32, try self.allocMem(inst, 16, 16));
+ try self.genSetStack(ptr_ty, stack_offset + 8, ptr);
+ try self.genSetStack(len_ty, stack_offset, len);
+ const result = MCValue{ .stack_offset = stack_offset };
+
return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });
}