authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-16 12:19:31-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-16 12:19:31-04:00
logcd5f69794d63ece18cd8f8aa0e2ce8bc16a31ab7
tree8874dcf7f2ddade357cff053eaad230dcde834a5
parent69a5f0d7973f2a3fefb69bc30c7dc1f0b430bba2

cross compile the stage2 tests for the target that they work for


2 files changed, 16 insertions(+), 4 deletions(-)

src-self-hosted/test.zig+5-1
...@@ -29,6 +29,7 @@ pub const TestContext = struct {...@@ -29,6 +29,7 @@ pub const TestContext = struct {
29 name: []const u8,29 name: []const u8,
30 src: [:0]const u8,30 src: [:0]const u8,
31 expected_zir: []const u8,31 expected_zir: []const u8,
32 cross_target: std.zig.CrossTarget,
32 };33 };
3334
34 pub fn addZIRCompareOutput(35 pub fn addZIRCompareOutput(
...@@ -47,6 +48,7 @@ pub const TestContext = struct {...@@ -47,6 +48,7 @@ pub const TestContext = struct {
47 pub fn addZIRTransform(48 pub fn addZIRTransform(
48 ctx: *TestContext,49 ctx: *TestContext,
49 name: []const u8,50 name: []const u8,
51 cross_target: std.zig.CrossTarget,
50 src: [:0]const u8,52 src: [:0]const u8,
51 expected_zir: []const u8,53 expected_zir: []const u8,
52 ) void {54 ) void {
...@@ -54,6 +56,7 @@ pub const TestContext = struct {...@@ -54,6 +56,7 @@ pub const TestContext = struct {
54 .name = name,56 .name = name,
55 .src = src,57 .src = src,
56 .expected_zir = expected_zir,58 .expected_zir = expected_zir,
59 .cross_target = cross_target,
57 }) catch unreachable;60 }) catch unreachable;
58 }61 }
5962
...@@ -85,7 +88,8 @@ pub const TestContext = struct {...@@ -85,7 +88,8 @@ pub const TestContext = struct {
85 }88 }
86 for (self.zir_transform_cases.items) |case| {89 for (self.zir_transform_cases.items) |case| {
87 std.testing.base_allocator_instance.reset();90 std.testing.base_allocator_instance.reset();
88 try self.runOneZIRTransformCase(std.testing.allocator, root_node, case, native_info.target);91 const info = try std.zig.system.NativeTargetInfo.detect(std.testing.allocator, case.cross_target);
92 try self.runOneZIRTransformCase(std.testing.allocator, root_node, case, info.target);
89 try std.testing.allocator_instance.validate();93 try std.testing.allocator_instance.validate();
90 }94 }
91 }95 }
test/stage2/zir.zig+11-3
...@@ -1,7 +1,15 @@...@@ -1,7 +1,15 @@
1const std = @import("std");
1const TestContext = @import("../../src-self-hosted/test.zig").TestContext;2const TestContext = @import("../../src-self-hosted/test.zig").TestContext;
3// 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// x86_64-linux.
6const linux_x64 = std.zig.CrossTarget{
7 .cpu_arch = .x86_64,
8 .os_tag = .linux,
9};
210
3pub fn addCases(ctx: *TestContext) void {11pub fn addCases(ctx: *TestContext) void {
4 ctx.addZIRTransform("elemptr, add, cmp, condbr, return, breakpoint",12 ctx.addZIRTransform("elemptr, add, cmp, condbr, return, breakpoint", linux_x64,
5 \\@void = primitive(void)13 \\@void = primitive(void)
6 \\@usize = primitive(usize)14 \\@usize = primitive(usize)
7 \\@fnty = fntype([], @void, cc=C)15 \\@fnty = fntype([], @void, cc=C)
...@@ -49,8 +57,8 @@ pub fn addCases(ctx: *TestContext) void {...@@ -49,8 +57,8 @@ pub fn addCases(ctx: *TestContext) void {
49 \\57 \\
50 );58 );
5159
52 if (@import("std").Target.current.os.tag != .linux or60 if (std.Target.current.os.tag != .linux or
53 @import("std").Target.current.cpu.arch != .x86_64)61 std.Target.current.cpu.arch != .x86_64)
54 {62 {
55 // TODO implement self-hosted PE (.exe file) linking63 // TODO implement self-hosted PE (.exe file) linking
56 // TODO implement more ZIR so we don't depend on x86_64-linux64 // TODO implement more ZIR so we don't depend on x86_64-linux