authorgravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2023-05-15 14:22:40+03:30
committergravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2023-05-15 14:22:40+03:30
logf8de4db8731e20995d16ec29bc0fb553e7d6f5bf
tree188a3e11471df9f7c31bdb3a23a232b38c810adb
parent9c550721e40f50b2ee44a5b1bf633ebdd50d5fd2

spirv: implement arithmeticTypeInfo for Enum (`@intToEnum`)


3 files changed, 11 insertions(+), 6 deletions(-)

src/codegen/spirv.zig+11
......@@ -369,6 +369,17 @@ pub const DeclGen = struct {
369369 .composite_integer,
370370 };
371371 },
372 .Enum => blk: {
373 var buffer: Type.Payload.Bits = undefined;
374 const int_ty = ty.intTagType(&buffer);
375 const int_info = int_ty.intInfo(target);
376 break :blk ArithmeticTypeInfo{
377 .bits = int_info.bits,
378 .is_vector = false,
379 .signedness = int_info.signedness,
380 .class = .integer,
381 };
382 },
372383 // As of yet, there is no vector support in the self-hosted compiler.
373384 .Vector => self.todo("implement arithmeticTypeInfo for Vector", .{}),
374385 // TODO: For which types is this the case?
test/behavior/enum.zig-5
......@@ -27,7 +27,6 @@ const IntToEnumNumber = enum { Zero, One, Two, Three, Four };
2727test "int to enum" {
2828 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
2929 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
30 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
3130
3231 try testIntToEnumEval(3);
3332}
......@@ -576,8 +575,6 @@ test "enum literal equality" {
576575}
577576
578577test "enum literal cast to enum" {
579 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
580
581578 const Color = enum { Auto, Off, On };
582579
583580 var color1: Color = .Auto;
......@@ -874,8 +871,6 @@ test "switch on enum with one member is comptime-known" {
874871}
875872
876873test "method call on an enum" {
877 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
878
879874 const S = struct {
880875 const E = enum {
881876 one,
test/behavior/union.zig-1
......@@ -366,7 +366,6 @@ test "simple union(enum(u32))" {
366366 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
367367 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
368368 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
369 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
370369
371370 var x = MultipleChoice.C;
372371 try expect(x == MultipleChoice.C);