aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2023-05-18 12:27:16 +0200
committerRobin Voetter <robin@voetter.nl>2023-05-20 17:30:21 +0200
commit7d519b3383431df48a41d6b32520e5c5e3d77612 (patch)
tree00bee0e877593683b7906ef348e40872db4dd30a /src/codegen/spirv.zig
parent6e3770e970dbf460271a0e0cb60c2bf40a7c861e (diff)
downloadzig-7d519b3383431df48a41d6b32520e5c5e3d77612.tar.gz
zig-7d519b3383431df48a41d6b32520e5c5e3d77612.zip
spirv: use intInfo instead of arithmeticTypeInfo in airIntCast
This ensures that we can also cast enums and error sets here. In the future this function will need to be changed to support composite and strange integers, but that is fine.
Diffstat (limited to 'src/codegen/spirv.zig')
-rw-r--r--src/codegen/spirv.zig13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig
index 9cfac608a1..5edafc5037 100644
--- a/src/codegen/spirv.zig
+++ b/src/codegen/spirv.zig
@@ -372,7 +372,8 @@ pub const DeclGen = struct {
// As of yet, there is no vector support in the self-hosted compiler.
.Vector => self.todo("implement arithmeticTypeInfo for Vector", .{}),
// TODO: For which types is this the case?
- else => self.todo("implement arithmeticTypeInfo for {}", .{ty.fmt(self.module)}),
+ // else => self.todo("implement arithmeticTypeInfo for {}", .{ty.fmt(self.module)}),
+ else => unreachable,
};
}
@@ -1712,7 +1713,7 @@ pub const DeclGen = struct {
.shl => try self.airShift(inst, .OpShiftLeftLogical),
.bitcast => try self.airBitcast(inst),
- .intcast, .trunc => try self.airIntcast(inst),
+ .intcast, .trunc => try self.airIntCast(inst),
.ptrtoint => try self.airPtrToInt(inst),
.int_to_float => try self.airIntToFloat(inst),
.float_to_int => try self.airFloatToInt(inst),
@@ -2162,15 +2163,19 @@ pub const DeclGen = struct {
return try self.bitcast(result_type_id, operand_id);
}
- fn airIntcast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
+ fn airIntCast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
if (self.liveness.isUnused(inst)) return null;
const ty_op = self.air.instructions.items(.data)[inst].ty_op;
const operand_id = try self.resolve(ty_op.operand);
const dest_ty = self.air.typeOfIndex(inst);
- const dest_info = try self.arithmeticTypeInfo(dest_ty);
const dest_ty_id = try self.resolveTypeId(dest_ty);
+ const target = self.getTarget();
+ const dest_info = dest_ty.intInfo(target);
+
+ // TODO: Masking?
+
const result_id = self.spv.allocId();
switch (dest_info.signedness) {
.signed => try self.func.body.emit(self.spv.gpa, .OpSConvert, .{