| ... | @@ -2651,17 +2651,35 @@ pub const DeclGen = struct { | ... | @@ -2651,17 +2651,35 @@ pub const DeclGen = struct { |
| 2651 | object_ptr: IdRef, | 2651 | object_ptr: IdRef, |
| 2652 | field_index: u32, | 2652 | field_index: u32, |
| 2653 | ) !?IdRef { | 2653 | ) !?IdRef { |
| | 2654 | const result_ty_ref = try self.resolveType(result_ptr_ty, .direct); |
| | 2655 | |
| 2654 | const mod = self.module; | 2656 | const mod = self.module; |
| 2655 | const object_ty = object_ptr_ty.childType(mod); | 2657 | const object_ty = object_ptr_ty.childType(mod); |
| 2656 | switch (object_ty.zigTypeTag(mod)) { | 2658 | switch (object_ty.zigTypeTag(mod)) { |
| 2657 | .Struct => switch (object_ty.containerLayout(mod)) { | 2659 | .Struct => switch (object_ty.containerLayout(mod)) { |
| 2658 | .Packed => unreachable, // TODO | 2660 | .Packed => unreachable, // TODO |
| 2659 | else => { | 2661 | else => { |
| 2660 | const result_ty_ref = try self.resolveType(result_ptr_ty, .direct); | | |
| 2661 | return try self.accessChain(result_ty_ref, object_ptr, &.{field_index}); | 2662 | return try self.accessChain(result_ty_ref, object_ptr, &.{field_index}); |
| 2662 | }, | 2663 | }, |
| 2663 | }, | 2664 | }, |
| 2664 | else => unreachable, // TODO | 2665 | .Union => switch (object_ty.containerLayout(mod)) { |
| | 2666 | .Packed => unreachable, // TODO |
| | 2667 | else => { |
| | 2668 | const storage_class = spvStorageClass(object_ptr_ty.ptrAddressSpace(mod)); |
| | 2669 | const un_active_ty_ref = try self.resolveUnionType(object_ty, field_index); |
| | 2670 | const un_active_ptr_ty_ref = try self.spv.ptrType(un_active_ty_ref, storage_class); |
| | 2671 | |
| | 2672 | const casted_id = self.spv.allocId(); |
| | 2673 | try self.func.body.emit(self.spv.gpa, .OpBitcast, .{ |
| | 2674 | .id_result_type = self.typeId(un_active_ptr_ty_ref), |
| | 2675 | .id_result = casted_id, |
| | 2676 | .operand = object_ptr, |
| | 2677 | }); |
| | 2678 | const layout = self.unionLayout(object_ty, field_index); |
| | 2679 | return try self.accessChain(result_ty_ref, casted_id, &.{layout.active_field_index}); |
| | 2680 | }, |
| | 2681 | }, |
| | 2682 | else => unreachable, |
| 2665 | } | 2683 | } |
| 2666 | } | 2684 | } |
| 2667 | | 2685 | |