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 {...@@ -369,6 +369,17 @@ pub const DeclGen = struct {
369 .composite_integer,369 .composite_integer,
370 };370 };
371 },371 },
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 },
372 // As of yet, there is no vector support in the self-hosted compiler.383 // As of yet, there is no vector support in the self-hosted compiler.
373 .Vector => self.todo("implement arithmeticTypeInfo for Vector", .{}),384 .Vector => self.todo("implement arithmeticTypeInfo for Vector", .{}),
374 // TODO: For which types is this the case?385 // 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 };...@@ -27,7 +27,6 @@ const IntToEnumNumber = enum { Zero, One, Two, Three, Four };
27test "int to enum" {27test "int to enum" {
28 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;28 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
29 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO29 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
30 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
3130
32 try testIntToEnumEval(3);31 try testIntToEnumEval(3);
33}32}
...@@ -576,8 +575,6 @@ test "enum literal equality" {...@@ -576,8 +575,6 @@ test "enum literal equality" {
576}575}
577576
578test "enum literal cast to enum" {577test "enum literal cast to enum" {
579 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
580
581 const Color = enum { Auto, Off, On };578 const Color = enum { Auto, Off, On };
582579
583 var color1: Color = .Auto;580 var color1: Color = .Auto;
...@@ -874,8 +871,6 @@ test "switch on enum with one member is comptime-known" {...@@ -874,8 +871,6 @@ test "switch on enum with one member is comptime-known" {
874}871}
875872
876test "method call on an enum" {873test "method call on an enum" {
877 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
878
879 const S = struct {874 const S = struct {
880 const E = enum {875 const E = enum {
881 one,876 one,
test/behavior/union.zig-1
...@@ -366,7 +366,6 @@ test "simple union(enum(u32))" {...@@ -366,7 +366,6 @@ test "simple union(enum(u32))" {
366 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;366 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
367 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;367 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
368 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO368 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
369 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
370369
371 var x = MultipleChoice.C;370 var x = MultipleChoice.C;
372 try expect(x == MultipleChoice.C);371 try expect(x == MultipleChoice.C);