authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-15 17:55:24-04:00
committergravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-15 20:33:25-04:00
logb6bd51ed69f75930bbf9a80b5b8841d1517a6828
treebeb52b091d1b44cef788447ded8b0ca3b75e4aab
parente77fc7fe7e3d6e5e4dc89bbc8fa95e65d4134b9f
signature Commit is signed but in an unrecognized format.

Stage2/Testing: Move Transformation case to ZIRCase


2 files changed, 57 insertions(+), 85 deletions(-)

src-self-hosted/test.zig+5-5
...@@ -141,21 +141,21 @@ pub const TestContext = struct {...@@ -141,21 +141,21 @@ pub const TestContext = struct {
141 /// such as QEMU is required for tests to complete.141 /// such as QEMU is required for tests to complete.
142 ///142 ///
143 target: std.zig.CrossTarget,143 target: std.zig.CrossTarget,
144 stages: []ZIRUpdate,144 stages: []const ZIRUpdate,
145 };145 };
146146
147 pub fn addZIRCase(147 pub fn addZIRCase(
148 ctx: *TestContext,148 ctx: *TestContext,
149 name: []const u8,149 name: []const u8,
150 target: std.zig.CrossTarget,150 target: std.zig.CrossTarget,
151 stages: []ZIRUpdate,151 stages: []const ZIRUpdate,
152 ) !void {152 ) void {
153 const case = .{153 const case = ZIRCase{
154 .name = name,154 .name = name,
155 .target = target,155 .target = target,
156 .stages = stages,156 .stages = stages,
157 };157 };
158 try ctx.cases.append(case);158 ctx.zir_cases.append(case) catch |err| std.debug.panic("Error: {}", .{err});
159 }159 }
160160
161 pub fn addZIRCompareOutput(161 pub fn addZIRCompareOutput(
test/stage2/zir.zig+52-80
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const TestContext = @import("../../src-self-hosted/test.zig").TestContext;2const TestContext = @import("../../src-self-hosted/test.zig").TestContext;
3const ZIRUpdate = TestContext.ZIRUpdate;
3// self-hosted does not yet support PE executable files / COFF object files4// 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 for5// 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};
1011
11pub fn addCases(ctx: *TestContext) void {12pub 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 );
9264
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);