Skip to content

Commit 7b5d139

Browse files
g-w1andrewrk
authored andcommitted
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 commit 7b5d139

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

test/cases.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub fn addCases(ctx: *TestContext) !void {
2020
try @import("stage2/wasm.zig").addCases(ctx);
2121
try @import("stage2/darwin.zig").addCases(ctx);
2222
try @import("stage2/riscv64.zig").addCases(ctx);
23+
try @import("stage2/plan9.zig").addCases(ctx);
2324

2425
{
2526
var case = ctx.exe("hello world with updates", linux_x64);

test/stage2/plan9.zig

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const std = @import("std");
2+
const TestContext = @import("../../src/test.zig").TestContext;
3+
4+
pub fn addCases(ctx: *TestContext) !void {
5+
const target: std.zig.CrossTarget = .{
6+
.cpu_arch = .x86_64,
7+
.os_tag = .plan9,
8+
};
9+
{
10+
var case = ctx.exe("plan9: exiting correctly", target);
11+
case.addCompareOutput("pub fn main() void {}", "");
12+
}
13+
{
14+
var case = ctx.exe("plan9: hello world", target);
15+
case.addCompareOutput(
16+
\\pub fn main() void {
17+
\\ const str = "Hello World!\n";
18+
\\ asm volatile (
19+
\\ \\push $0
20+
\\ \\push %%r10
21+
\\ \\push %%r11
22+
\\ \\push $1
23+
\\ \\push $0
24+
\\ \\syscall
25+
\\ \\pop %%r11
26+
\\ \\pop %%r11
27+
\\ \\pop %%r11
28+
\\ \\pop %%r11
29+
\\ \\pop %%r11
30+
\\ :
31+
\\ // pwrite
32+
\\ : [syscall_number] "{rbp}" (51),
33+
\\ [hey] "{r11}" (@ptrToInt(str)),
34+
\\ [strlen] "{r10}" (str.len)
35+
\\ : "rcx", "rbp", "r11", "memory"
36+
\\ );
37+
\\}
38+
, "");
39+
}
40+
}

0 commit comments

Comments
 (0)