aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-11-18 20:57:27 -0500
committerAndrew Kelley <superjoe30@gmail.com>2016-11-18 20:57:27 -0500
commitbf7cde62c52b370f953db2cd6167a156771d8343 (patch)
tree4f11799818dc793db8431332537b010620aad55f /test
parented31ae8867fd2d7b5274c6b127d42360b48fc49c (diff)
downloadzig-bf7cde62c52b370f953db2cd6167a156771d8343.tar.gz
zig-bf7cde62c52b370f953db2cd6167a156771d8343.zip
IR: support setDebugSafety builtin function
Diffstat (limited to 'test')
-rw-r--r--test/self_hosted2.zig42
1 files changed, 35 insertions, 7 deletions
diff --git a/test/self_hosted2.zig b/test/self_hosted2.zig
index ba1171b57b..60b12bfac8 100644
--- a/test/self_hosted2.zig
+++ b/test/self_hosted2.zig
@@ -1,13 +1,41 @@
-fn add(a: i32, b: i32) -> i32 {
- a + b
+pub const SYS_write = 1;
+pub const SYS_exit = 60;
+pub const stdout_fileno = 1;
+const text = "hello\n";
+
+export nakedcc fn _start() -> unreachable {
+ myMain();
+}
+
+fn myMain() -> unreachable {
+ write(stdout_fileno, &text[0], text.len);
+ exit(0);
}
-fn assert(ok: bool) {
- if (!ok) @unreachable();
+pub inline fn syscall1(number: usize, arg1: usize) -> usize {
+ asm volatile ("syscall"
+ : [ret] "={rax}" (-> usize)
+ : [number] "{rax}" (number),
+ [arg1] "{rdi}" (arg1)
+ : "rcx", "r11")
}
-fn testAdd() {
- @setFnTest(this, true);
+pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
+ asm volatile ("syscall"
+ : [ret] "={rax}" (-> usize)
+ : [number] "{rax}" (number),
+ [arg1] "{rdi}" (arg1),
+ [arg2] "{rsi}" (arg2),
+ [arg3] "{rdx}" (arg3)
+ : "rcx", "r11")
+}
- assert(add(2, 3) == 5);
+pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
+ syscall3(SYS_write, usize(fd), usize(buf), count)
}
+
+pub fn exit(status: i32) -> unreachable {
+ syscall1(SYS_exit, usize(status));
+ @unreachable()
+}
+