From 52ed513ddaf51e44bd220a9ea07cede2f5da4344 Mon Sep 17 00:00:00 2001 From: Jacob G-W Date: Thu, 8 Jul 2021 18:25:21 -0400 Subject: [PATCH] plan9 codegen, add tests They generate an object file, but do not execute yet, since we don't have something to execute them with. --- test/cases.zig | 1 + test/stage2/plan9.zig | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test/stage2/plan9.zig diff --git a/test/cases.zig b/test/cases.zig index 37683072a2ba..ef8c1fd24f1b 100644 --- a/test/cases.zig +++ b/test/cases.zig @@ -20,6 +20,7 @@ pub fn addCases(ctx: *TestContext) !void { try @import("stage2/wasm.zig").addCases(ctx); try @import("stage2/darwin.zig").addCases(ctx); try @import("stage2/riscv64.zig").addCases(ctx); + try @import("stage2/plan9.zig").addCases(ctx); { var case = ctx.exe("hello world with updates", linux_x64); diff --git a/test/stage2/plan9.zig b/test/stage2/plan9.zig new file mode 100644 index 000000000000..22fa8253dcd5 --- /dev/null +++ b/test/stage2/plan9.zig @@ -0,0 +1,40 @@ +const std = @import("std"); +const TestContext = @import("../../src/test.zig").TestContext; + +pub fn addCases(ctx: *TestContext) !void { + const target: std.zig.CrossTarget = .{ + .cpu_arch = .x86_64, + .os_tag = .plan9, + }; + { + var case = ctx.exe("plan9: exiting correctly", target); + case.addCompareOutput("pub fn main() void {}", ""); + } + { + var case = ctx.exe("plan9: hello world", target); + case.addCompareOutput( + \\pub fn main() void { + \\ const str = "Hello World!\n"; + \\ asm volatile ( + \\ \\push $0 + \\ \\push %%r10 + \\ \\push %%r11 + \\ \\push $1 + \\ \\push $0 + \\ \\syscall + \\ \\pop %%r11 + \\ \\pop %%r11 + \\ \\pop %%r11 + \\ \\pop %%r11 + \\ \\pop %%r11 + \\ : + \\ // pwrite + \\ : [syscall_number] "{rbp}" (51), + \\ [hey] "{r11}" (@ptrToInt(str)), + \\ [strlen] "{r10}" (str.len) + \\ : "rcx", "rbp", "r11", "memory" + \\ ); + \\} + , ""); + } +}