| ... | ... | @@ -1738,6 +1738,8 @@ pub const DeclGen = struct { |
| 1738 | 1738 | |
| 1739 | 1739 | .shuffle => try self.airShuffle(inst), |
| 1740 | 1740 | |
| 1741 | .ptr_add => try self.airPtrAdd(inst), |
| 1742 | |
| 1741 | 1743 | .bit_and => try self.airBinOpSimple(inst, .OpBitwiseAnd), |
| 1742 | 1744 | .bit_or => try self.airBinOpSimple(inst, .OpBitwiseOr), |
| 1743 | 1745 | .xor => try self.airBinOpSimple(inst, .OpBitwiseXor), |
| ... | ... | @@ -2120,6 +2122,33 @@ pub const DeclGen = struct { |
| 2120 | 2122 | return result_id; |
| 2121 | 2123 | } |
| 2122 | 2124 | |
| 2125 | fn airPtrAdd(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 2126 | if (self.liveness.isUnused(inst)) return null; |
| 2127 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; |
| 2128 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2129 | const ptr_id = try self.resolve(bin_op.lhs); |
| 2130 | const offset_id = try self.resolve(bin_op.rhs); |
| 2131 | const ptr_ty = self.air.typeOf(bin_op.lhs); |
| 2132 | const result_ty = self.air.typeOfIndex(inst); |
| 2133 | const result_ty_ref = try self.resolveType(result_ty, .direct); |
| 2134 | |
| 2135 | switch (ptr_ty.ptrSize()) { |
| 2136 | .One => { |
| 2137 | // Pointer to array |
| 2138 | // TODO: Is this correct? |
| 2139 | return try self.accessChain(result_ty_ref, ptr_id, &.{offset_id}); |
| 2140 | }, |
| 2141 | .C, .Many => { |
| 2142 | return try self.ptrAccessChain(result_ty_ref, ptr_id, offset_id, &.{}); |
| 2143 | }, |
| 2144 | .Slice => { |
| 2145 | // TODO: This is probably incorrect. A slice should be returned here, though this is what llvm does. |
| 2146 | const slice_ptr_id = try self.extractField(result_ty, ptr_id, 0); |
| 2147 | return try self.ptrAccessChain(result_ty_ref, slice_ptr_id, offset_id, &.{}); |
| 2148 | }, |
| 2149 | } |
| 2150 | } |
| 2151 | |
| 2123 | 2152 | fn cmp( |
| 2124 | 2153 | self: *DeclGen, |
| 2125 | 2154 | comptime op: std.math.CompareOperator, |