| ... | ... | @@ -1752,7 +1752,7 @@ pub const DeclGen = struct { |
| 1752 | 1752 | |
| 1753 | 1753 | .shl => try self.airShift(inst, .OpShiftLeftLogical), |
| 1754 | 1754 | |
| 1755 | | .bitcast => try self.airBitcast(inst), |
| 1755 | .bitcast => try self.airBitCast(inst), |
| 1756 | 1756 | .intcast, .trunc => try self.airIntCast(inst), |
| 1757 | 1757 | .ptrtoint => try self.airPtrToInt(inst), |
| 1758 | 1758 | .int_to_float => try self.airIntToFloat(inst), |
| ... | ... | @@ -2269,22 +2269,41 @@ pub const DeclGen = struct { |
| 2269 | 2269 | return try self.cmp(op, bool_ty_id, ty, lhs_id, rhs_id); |
| 2270 | 2270 | } |
| 2271 | 2271 | |
| 2272 | | fn bitcast(self: *DeclGen, target_type_id: IdResultType, value_id: IdRef) !IdRef { |
| 2272 | fn bitCast( |
| 2273 | self: *DeclGen, |
| 2274 | dst_ty: Type, |
| 2275 | src_ty: Type, |
| 2276 | src_id: IdRef, |
| 2277 | ) !IdRef { |
| 2278 | const dst_ty_ref = try self.resolveType(dst_ty, .direct); |
| 2273 | 2279 | const result_id = self.spv.allocId(); |
| 2274 | | try self.func.body.emit(self.spv.gpa, .OpBitcast, .{ |
| 2275 | | .id_result_type = target_type_id, |
| 2276 | | .id_result = result_id, |
| 2277 | | .operand = value_id, |
| 2278 | | }); |
| 2280 | |
| 2281 | // TODO: Some more cases are missing here |
| 2282 | // See fn bitCast in llvm.zig |
| 2283 | |
| 2284 | if (src_ty.zigTypeTag() == .Int and dst_ty.isPtrAtRuntime()) { |
| 2285 | try self.func.body.emit(self.spv.gpa, .OpConvertUToPtr, .{ |
| 2286 | .id_result_type = self.typeId(dst_ty_ref), |
| 2287 | .id_result = result_id, |
| 2288 | .integer_value = src_id, |
| 2289 | }); |
| 2290 | } else { |
| 2291 | try self.func.body.emit(self.spv.gpa, .OpBitcast, .{ |
| 2292 | .id_result_type = self.typeId(dst_ty_ref), |
| 2293 | .id_result = result_id, |
| 2294 | .operand = src_id, |
| 2295 | }); |
| 2296 | } |
| 2279 | 2297 | return result_id; |
| 2280 | 2298 | } |
| 2281 | 2299 | |
| 2282 | | fn airBitcast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 2300 | fn airBitCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 2283 | 2301 | if (self.liveness.isUnused(inst)) return null; |
| 2284 | 2302 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; |
| 2285 | 2303 | const operand_id = try self.resolve(ty_op.operand); |
| 2286 | | const result_type_id = try self.resolveTypeId(self.air.typeOfIndex(inst)); |
| 2287 | | return try self.bitcast(result_type_id, operand_id); |
| 2304 | const operand_ty = self.air.typeOf(ty_op.operand); |
| 2305 | const result_ty = self.air.typeOfIndex(inst); |
| 2306 | return try self.bitCast(result_ty, operand_ty, operand_id); |
| 2288 | 2307 | } |
| 2289 | 2308 | |
| 2290 | 2309 | fn airIntCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |