Stage2/Testing: Move Transformation case to ZIRCase

master
Noam Preil 2020-06-15 17:55:24 -04:00
parent e77fc7fe7e
commit b6bd51ed69
No known key found for this signature in database
GPG Key ID: FC347E7C85BE8238
2 changed files with 57 additions and 85 deletions

View File

@ -141,21 +141,21 @@ pub const TestContext = struct {
/// such as QEMU is required for tests to complete. /// such as QEMU is required for tests to complete.
/// ///
target: std.zig.CrossTarget, target: std.zig.CrossTarget,
stages: []ZIRUpdate, stages: []const ZIRUpdate,
}; };
pub fn addZIRCase( pub fn addZIRCase(
ctx: *TestContext, ctx: *TestContext,
name: []const u8, name: []const u8,
target: std.zig.CrossTarget, target: std.zig.CrossTarget,
stages: []ZIRUpdate, stages: []const ZIRUpdate,
) !void { ) void {
const case = .{ const case = ZIRCase{
.name = name, .name = name,
.target = target, .target = target,
.stages = stages, .stages = stages,
}; };
try ctx.cases.append(case); ctx.zir_cases.append(case) catch |err| std.debug.panic("Error: {}", .{err});
} }
pub fn addZIRCompareOutput( pub fn addZIRCompareOutput(

View File

@ -1,5 +1,6 @@
const std = @import("std"); const std = @import("std");
const TestContext = @import("../../src-self-hosted/test.zig").TestContext; const TestContext = @import("../../src-self-hosted/test.zig").TestContext;
const ZIRUpdate = TestContext.ZIRUpdate;
// self-hosted does not yet support PE executable files / COFF object files // self-hosted does not yet support PE executable files / COFF object files
// or mach-o files. So we do the ZIR transform test cases cross compiling for // or mach-o files. So we do the ZIR transform test cases cross compiling for
// x86_64-linux. // x86_64-linux.
@ -9,86 +10,57 @@ const linux_x64 = std.zig.CrossTarget{
}; };
pub fn addCases(ctx: *TestContext) void { pub fn addCases(ctx: *TestContext) void {
ctx.addZIRTransform("referencing decls which appear later in the file", linux_x64, ctx.addZIRCase("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, &[_]ZIRUpdate{ZIRUpdate{
\\@void = primitive(void) .src =
\\@fnty = fntype([], @void, cc=C) \\@void = primitive(void)
\\ \\@usize = primitive(usize)
\\@9 = str("entry") \\@fnty = fntype([], @void, cc=C)
\\@10 = ref(@9) \\@0 = int(0)
\\@11 = export(@10, @entry) \\@1 = int(1)
\\ \\@2 = int(2)
\\@entry = fn(@fnty, { \\@3 = int(3)
\\ %11 = return() \\
\\}) \\@entry = fn(@fnty, {
, \\ %a = str("\x32\x08\x01\x0a")
\\@void = primitive(void) \\ %aref = ref(%a)
\\@fnty = fntype([], @void, cc=C) \\ %eptr0 = elemptr(%aref, @0)
\\@9 = str("entry") \\ %eptr1 = elemptr(%aref, @1)
\\@10 = ref(@9) \\ %eptr2 = elemptr(%aref, @2)
\\@unnamed$6 = str("entry") \\ %eptr3 = elemptr(%aref, @3)
\\@unnamed$7 = ref(@unnamed$6) \\ %v0 = deref(%eptr0)
\\@unnamed$8 = export(@unnamed$7, @entry) \\ %v1 = deref(%eptr1)
\\@unnamed$10 = fntype([], @void, cc=C) \\ %v2 = deref(%eptr2)
\\@entry = fn(@unnamed$10, { \\ %v3 = deref(%eptr3)
\\ %0 = return() \\ %x0 = add(%v0, %v1)
\\}) \\ %x1 = add(%v2, %v3)
\\ \\ %result = add(%x0, %x1)
); \\
ctx.addZIRTransform("elemptr, add, cmp, condbr, return, breakpoint", linux_x64, \\ %expected = int(69)
\\@void = primitive(void) \\ %ok = cmp(%result, eq, %expected)
\\@usize = primitive(usize) \\ %10 = condbr(%ok, {
\\@fnty = fntype([], @void, cc=C) \\ %11 = return()
\\@0 = int(0) \\ }, {
\\@1 = int(1) \\ %12 = breakpoint()
\\@2 = int(2) \\ })
\\@3 = int(3) \\})
\\ \\
\\@entry = fn(@fnty, { \\@9 = str("entry")
\\ %a = str("\x32\x08\x01\x0a") \\@10 = ref(@9)
\\ %aref = ref(%a) \\@11 = export(@10, @entry)
\\ %eptr0 = elemptr(%aref, @0) ,
\\ %eptr1 = elemptr(%aref, @1) .case = .{
\\ %eptr2 = elemptr(%aref, @2) .Transformation =
\\ %eptr3 = elemptr(%aref, @3) \\@0 = primitive(void)
\\ %v0 = deref(%eptr0) \\@1 = fntype([], @0, cc=C)
\\ %v1 = deref(%eptr1) \\@2 = fn(@1, {
\\ %v2 = deref(%eptr2) \\ %0 = return()
\\ %v3 = deref(%eptr3) \\})
\\ %x0 = add(%v0, %v1) \\@3 = str("entry")
\\ %x1 = add(%v2, %v3) \\@4 = ref(@3)
\\ %result = add(%x0, %x1) \\@5 = export(@4, @2)
\\ \\
\\ %expected = int(69) },
\\ %ok = cmp(%result, eq, %expected) }});
\\ %10 = condbr(%ok, {
\\ %11 = return()
\\ }, {
\\ %12 = breakpoint()
\\ })
\\})
\\
\\@9 = str("entry")
\\@10 = ref(@9)
\\@11 = export(@10, @entry)
,
\\@void = primitive(void)
\\@fnty = fntype([], @void, cc=C)
\\@0 = int(0)
\\@1 = int(1)
\\@2 = int(2)
\\@3 = int(3)
\\@unnamed$7 = fntype([], @void, cc=C)
\\@entry = fn(@unnamed$7, {
\\ %0 = return()
\\})
\\@a = str("2\x08\x01\n")
\\@9 = str("entry")
\\@10 = ref(@9)
\\@unnamed$14 = str("entry")
\\@unnamed$15 = ref(@unnamed$14)
\\@unnamed$16 = export(@unnamed$15, @entry)
\\
);
{ {
var case = ctx.addZIRMulti("reference cycle with compile error in the cycle", linux_x64); var case = ctx.addZIRMulti("reference cycle with compile error in the cycle", linux_x64);