| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const TestContext = @import("../../src-self-hosted/test.zig").TestContext; | 2 | const TestContext = @import("../../src-self-hosted/test.zig").TestContext; |
| | 3 | const ZIRUpdate = TestContext.ZIRUpdate; |
| 3 | // self-hosted does not yet support PE executable files / COFF object files | 4 | // self-hosted does not yet support PE executable files / COFF object files |
| 4 | // or mach-o files. So we do the ZIR transform test cases cross compiling for | 5 | // or mach-o files. So we do the ZIR transform test cases cross compiling for |
| 5 | // x86_64-linux. | 6 | // x86_64-linux. |
| ... | @@ -9,86 +10,57 @@ const linux_x64 = std.zig.CrossTarget{ | ... | @@ -9,86 +10,57 @@ const linux_x64 = std.zig.CrossTarget{ |
| 9 | }; | 10 | }; |
| 10 | | 11 | |
| 11 | pub fn addCases(ctx: *TestContext) void { | 12 | pub fn addCases(ctx: *TestContext) void { |
| 12 | ctx.addZIRTransform("referencing decls which appear later in the file", linux_x64, | 13 | ctx.addZIRCase("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, &[_]ZIRUpdate{ZIRUpdate{ |
| 13 | \\@void = primitive(void) | 14 | .src = |
| 14 | \\@fnty = fntype([], @void, cc=C) | 15 | \\@void = primitive(void) |
| 15 | \\ | 16 | \\@usize = primitive(usize) |
| 16 | \\@9 = str("entry") | 17 | \\@fnty = fntype([], @void, cc=C) |
| 17 | \\@10 = ref(@9) | 18 | \\@0 = int(0) |
| 18 | \\@11 = export(@10, @entry) | 19 | \\@1 = int(1) |
| 19 | \\ | 20 | \\@2 = int(2) |
| 20 | \\@entry = fn(@fnty, { | 21 | \\@3 = int(3) |
| 21 | \\ %11 = return() | 22 | \\ |
| 22 | \\}) | 23 | \\@entry = fn(@fnty, { |
| 23 | , | 24 | \\ %a = str("\x32\x08\x01\x0a") |
| 24 | \\@void = primitive(void) | 25 | \\ %aref = ref(%a) |
| 25 | \\@fnty = fntype([], @void, cc=C) | 26 | \\ %eptr0 = elemptr(%aref, @0) |
| 26 | \\@9 = str("entry") | 27 | \\ %eptr1 = elemptr(%aref, @1) |
| 27 | \\@10 = ref(@9) | 28 | \\ %eptr2 = elemptr(%aref, @2) |
| 28 | \\@unnamed$6 = str("entry") | 29 | \\ %eptr3 = elemptr(%aref, @3) |
| 29 | \\@unnamed$7 = ref(@unnamed$6) | 30 | \\ %v0 = deref(%eptr0) |
| 30 | \\@unnamed$8 = export(@unnamed$7, @entry) | 31 | \\ %v1 = deref(%eptr1) |
| 31 | \\@unnamed$10 = fntype([], @void, cc=C) | 32 | \\ %v2 = deref(%eptr2) |
| 32 | \\@entry = fn(@unnamed$10, { | 33 | \\ %v3 = deref(%eptr3) |
| 33 | \\ %0 = return() | 34 | \\ %x0 = add(%v0, %v1) |
| 34 | \\}) | 35 | \\ %x1 = add(%v2, %v3) |
| 35 | \\ | 36 | \\ %result = add(%x0, %x1) |
| 36 | ); | 37 | \\ |
| 37 | ctx.addZIRTransform("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, | 38 | \\ %expected = int(69) |
| 38 | \\@void = primitive(void) | 39 | \\ %ok = cmp(%result, eq, %expected) |
| 39 | \\@usize = primitive(usize) | 40 | \\ %10 = condbr(%ok, { |
| 40 | \\@fnty = fntype([], @void, cc=C) | 41 | \\ %11 = return() |
| 41 | \\@0 = int(0) | 42 | \\ }, { |
| 42 | \\@1 = int(1) | 43 | \\ %12 = breakpoint() |
| 43 | \\@2 = int(2) | 44 | \\ }) |
| 44 | \\@3 = int(3) | 45 | \\}) |
| 45 | \\ | 46 | \\ |
| 46 | \\@entry = fn(@fnty, { | 47 | \\@9 = str("entry") |
| 47 | \\ %a = str("\x32\x08\x01\x0a") | 48 | \\@10 = ref(@9) |
| 48 | \\ %aref = ref(%a) | 49 | \\@11 = export(@10, @entry) |
| 49 | \\ %eptr0 = elemptr(%aref, @0) | 50 | , |
| 50 | \\ %eptr1 = elemptr(%aref, @1) | 51 | .case = .{ |
| 51 | \\ %eptr2 = elemptr(%aref, @2) | 52 | .Transformation = |
| 52 | \\ %eptr3 = elemptr(%aref, @3) | 53 | \\@0 = primitive(void) |
| 53 | \\ %v0 = deref(%eptr0) | 54 | \\@1 = fntype([], @0, cc=C) |
| 54 | \\ %v1 = deref(%eptr1) | 55 | \\@2 = fn(@1, { |
| 55 | \\ %v2 = deref(%eptr2) | 56 | \\ %0 = return() |
| 56 | \\ %v3 = deref(%eptr3) | 57 | \\}) |
| 57 | \\ %x0 = add(%v0, %v1) | 58 | \\@3 = str("entry") |
| 58 | \\ %x1 = add(%v2, %v3) | 59 | \\@4 = ref(@3) |
| 59 | \\ %result = add(%x0, %x1) | 60 | \\@5 = export(@4, @2) |
| 60 | \\ | 61 | \\ |
| 61 | \\ %expected = int(69) | 62 | }, |
| 62 | \\ %ok = cmp(%result, eq, %expected) | 63 | }}); |
| 63 | \\ %10 = condbr(%ok, { | | |
| 64 | \\ %11 = return() | | |
| 65 | \\ }, { | | |
| 66 | \\ %12 = breakpoint() | | |
| 67 | \\ }) | | |
| 68 | \\}) | | |
| 69 | \\ | | |
| 70 | \\@9 = str("entry") | | |
| 71 | \\@10 = ref(@9) | | |
| 72 | \\@11 = export(@10, @entry) | | |
| 73 | , | | |
| 74 | \\@void = primitive(void) | | |
| 75 | \\@fnty = fntype([], @void, cc=C) | | |
| 76 | \\@0 = int(0) | | |
| 77 | \\@1 = int(1) | | |
| 78 | \\@2 = int(2) | | |
| 79 | \\@3 = int(3) | | |
| 80 | \\@unnamed$7 = fntype([], @void, cc=C) | | |
| 81 | \\@entry = fn(@unnamed$7, { | | |
| 82 | \\ %0 = return() | | |
| 83 | \\}) | | |
| 84 | \\@a = str("2\x08\x01\n") | | |
| 85 | \\@9 = str("entry") | | |
| 86 | \\@10 = ref(@9) | | |
| 87 | \\@unnamed$14 = str("entry") | | |
| 88 | \\@unnamed$15 = ref(@unnamed$14) | | |
| 89 | \\@unnamed$16 = export(@unnamed$15, @entry) | | |
| 90 | \\ | | |
| 91 | ); | | |
| 92 | | 64 | |
| 93 | { | 65 | { |
| 94 | var case = ctx.addZIRMulti("reference cycle with compile error in the cycle", linux_x64); | 66 | var case = ctx.addZIRMulti("reference cycle with compile error in the cycle", linux_x64); |