| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const TestContext = @import("../../src-self-hosted/test.zig").TestContext; |
| 3 | | const ZIRUpdate = TestContext.ZIRUpdate; |
| 4 | 3 | // self-hosted does not yet support PE executable files / COFF object files |
| 5 | 4 | // or mach-o files. So we do the ZIR transform test cases cross compiling for |
| 6 | 5 | // x86_64-linux. |
| ... | ... | @@ -10,61 +9,90 @@ const linux_x64 = std.zig.CrossTarget{ |
| 10 | 9 | }; |
| 11 | 10 | |
| 12 | 11 | pub fn addCases(ctx: *TestContext) void { |
| 13 | | ctx.addZIRCase("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, &[_]ZIRUpdate{ZIRUpdate{ |
| 14 | | .src = |
| 15 | | \\@void = primitive(void) |
| 16 | | \\@usize = primitive(usize) |
| 17 | | \\@fnty = fntype([], @void, cc=C) |
| 18 | | \\@0 = int(0) |
| 19 | | \\@1 = int(1) |
| 20 | | \\@2 = int(2) |
| 21 | | \\@3 = int(3) |
| 22 | | \\ |
| 23 | | \\@entry = fn(@fnty, { |
| 24 | | \\ %a = str("\x32\x08\x01\x0a") |
| 25 | | \\ %aref = ref(%a) |
| 26 | | \\ %eptr0 = elemptr(%aref, @0) |
| 27 | | \\ %eptr1 = elemptr(%aref, @1) |
| 28 | | \\ %eptr2 = elemptr(%aref, @2) |
| 29 | | \\ %eptr3 = elemptr(%aref, @3) |
| 30 | | \\ %v0 = deref(%eptr0) |
| 31 | | \\ %v1 = deref(%eptr1) |
| 32 | | \\ %v2 = deref(%eptr2) |
| 33 | | \\ %v3 = deref(%eptr3) |
| 34 | | \\ %x0 = add(%v0, %v1) |
| 35 | | \\ %x1 = add(%v2, %v3) |
| 36 | | \\ %result = add(%x0, %x1) |
| 37 | | \\ |
| 38 | | \\ %expected = int(69) |
| 39 | | \\ %ok = cmp(%result, eq, %expected) |
| 40 | | \\ %10 = condbr(%ok, { |
| 41 | | \\ %11 = return() |
| 42 | | \\ }, { |
| 43 | | \\ %12 = breakpoint() |
| 44 | | \\ }) |
| 45 | | \\}) |
| 46 | | \\ |
| 47 | | \\@9 = str("entry") |
| 48 | | \\@10 = ref(@9) |
| 49 | | \\@11 = export(@10, @entry) |
| 50 | | , |
| 51 | | .case = .{ |
| 52 | | .Transformation = |
| 53 | | \\@0 = primitive(void) |
| 54 | | \\@1 = fntype([], @0, cc=C) |
| 55 | | \\@2 = fn(@1, { |
| 56 | | \\ %0 = return() |
| 57 | | \\}) |
| 58 | | \\@3 = str("entry") |
| 59 | | \\@4 = ref(@3) |
| 60 | | \\@5 = export(@4, @2) |
| 61 | | \\ |
| 62 | | }, |
| 63 | | }}); |
| 12 | ctx.addZIRTransform("referencing decls which appear later in the file", linux_x64, |
| 13 | \\@void = primitive(void) |
| 14 | \\@fnty = fntype([], @void, cc=C) |
| 15 | \\ |
| 16 | \\@9 = str("entry") |
| 17 | \\@10 = ref(@9) |
| 18 | \\@11 = export(@10, @entry) |
| 19 | \\ |
| 20 | \\@entry = fn(@fnty, { |
| 21 | \\ %11 = return() |
| 22 | \\}) |
| 23 | , |
| 24 | \\@void = primitive(void) |
| 25 | \\@fnty = fntype([], @void, cc=C) |
| 26 | \\@9 = str("entry") |
| 27 | \\@10 = ref(@9) |
| 28 | \\@unnamed$6 = str("entry") |
| 29 | \\@unnamed$7 = ref(@unnamed$6) |
| 30 | \\@unnamed$8 = export(@unnamed$7, @entry) |
| 31 | \\@unnamed$10 = fntype([], @void, cc=C) |
| 32 | \\@entry = fn(@unnamed$10, { |
| 33 | \\ %0 = return() |
| 34 | \\}) |
| 35 | \\ |
| 36 | ); |
| 37 | ctx.addZIRTransform("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, |
| 38 | \\@void = primitive(void) |
| 39 | \\@usize = primitive(usize) |
| 40 | \\@fnty = fntype([], @void, cc=C) |
| 41 | \\@0 = int(0) |
| 42 | \\@1 = int(1) |
| 43 | \\@2 = int(2) |
| 44 | \\@3 = int(3) |
| 45 | \\ |
| 46 | \\@entry = fn(@fnty, { |
| 47 | \\ %a = str("\x32\x08\x01\x0a") |
| 48 | \\ %aref = ref(%a) |
| 49 | \\ %eptr0 = elemptr(%aref, @0) |
| 50 | \\ %eptr1 = elemptr(%aref, @1) |
| 51 | \\ %eptr2 = elemptr(%aref, @2) |
| 52 | \\ %eptr3 = elemptr(%aref, @3) |
| 53 | \\ %v0 = deref(%eptr0) |
| 54 | \\ %v1 = deref(%eptr1) |
| 55 | \\ %v2 = deref(%eptr2) |
| 56 | \\ %v3 = deref(%eptr3) |
| 57 | \\ %x0 = add(%v0, %v1) |
| 58 | \\ %x1 = add(%v2, %v3) |
| 59 | \\ %result = add(%x0, %x1) |
| 60 | \\ |
| 61 | \\ %expected = int(69) |
| 62 | \\ %ok = cmp(%result, eq, %expected) |
| 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 | ); |
| 64 | 92 | |
| 65 | 93 | { |
| 66 | 94 | var case = ctx.addZIRMulti("reference cycle with compile error in the cycle", linux_x64); |
| 67 | | case.addZIR( |
| 95 | case.addTransform( |
| 68 | 96 | \\@void = primitive(void) |
| 69 | 97 | \\@fnty = fntype([], @void, cc=C) |
| 70 | 98 | \\ |
| ... | ... | @@ -143,7 +171,7 @@ pub fn addCases(ctx: *TestContext) void { |
| 143 | 171 | // Now we remove the call to `a`. `a` and `b` form a cycle, but no entry points are |
| 144 | 172 | // referencing either of them. This tests that the cycle is detected, and the error |
| 145 | 173 | // goes away. |
| 146 | | case.addZIR( |
| 174 | case.addTransform( |
| 147 | 175 | \\@void = primitive(void) |
| 148 | 176 | \\@fnty = fntype([], @void, cc=C) |
| 149 | 177 | \\ |