zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit a75300c8d8cfe21647db1d50f77a9a1ee8d62a0e (tree)
parent 8895025688b599a7082669234d40b26001bd9ed0
Author: Robin Voetter <robin@voetter.nl>
Date:   Tue, 19 Sep 2023 23:32:49 +0200

spirv: air slice

Diffstat:
Msrc/codegen/spirv.zig | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig @@ -1683,6 +1683,7 @@ pub const DeclGen = struct { .not => try self.airNot(inst), .array_to_slice => try self.airArrayToSlice(inst), + .slice => try self.airSlice(inst), .aggregate_init => try self.airAggregateInit(inst), .slice_ptr => try self.airSliceField(inst, 0), @@ -2462,6 +2463,22 @@ pub const DeclGen = struct { return try self.constructStruct(slice_ty_ref, &.{ elem_ptr_id, len_id }); } + fn airSlice(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { + if (self.liveness.isUnused(inst)) return null; + + const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; + const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; + const ptr_id = try self.resolve(bin_op.lhs); + const len_id = try self.resolve(bin_op.rhs); + const slice_ty = self.typeOfIndex(inst); + const slice_ty_ref = try self.resolveType(slice_ty, .direct); + + return try self.constructStruct(slice_ty_ref, &.{ + ptr_id, // Note: Type should not need to be converted to direct. + len_id, // Note: Type should not need to be converted to direct. + }); + } + fn airAggregateInit(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { if (self.liveness.isUnused(inst)) return null;