aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-02-04 06:16:18 -0500
committerMustafa Quraish <[email protected]>2022-02-05 08:56:15 -0500
commit8fd0a145947011f113abaab245e35f1adfb6eb48 (patch)
tree957bcf38c33d697c2fe5dd997bc294ae28adcaec /src/utils.c
parentUpdate README.md (diff)
downloadcup-8fd0a145947011f113abaab245e35f1adfb6eb48.tar.xz
cup-8fd0a145947011f113abaab245e35f1adfb6eb48.zip
Allow `builtins.c` to inject constants into program, use for syscalls
We can now directly expose the `syscallN()` APIs to the program and define the `open()`, `write()` etc syscalls in the stdlib. This simplifies the implementation a decent bunch :^)
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 939021a..050c654 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -29,6 +29,15 @@ void _die_location(char *file, int line, Location loc, const char *fmt, ...)
i64 i64max(i64 a, i64 b) { return a > b ? a : b; }
i64 i64min(i64 a, i64 b) { return a < b ? a : b; }
+
+i64 get_syscall_num(i64 orig_syscall) {
+#if __APPLE__
+ return orig_syscall + 0x2000000;
+#else
+ return orig_syscall;
+#endif
+}
+
i64 align_up(i64 val, i64 align)
{
return (val + align - 1) & ~(align - 1);