Commit 7b5d139fd3

Jacob G-W <jacoblevgw@gmail.com>
2021-07-09 00:25:21
plan9 codegen, add tests
They generate an object file, but do not execute yet, since we don't have something to execute them with.
1 parent 7b8a968
Changed files (2)
test
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"
+            \\    );
+            \\}
+        , "");
+    }
+}
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);