diff options
author | dzwdz | 2022-05-02 21:47:11 +0200 |
---|---|---|
committer | dzwdz | 2022-05-02 21:47:11 +0200 |
commit | 8e276c64c9394d0964506bd6eaa7d4e0547d1ead (patch) | |
tree | 4ebefd7507061a04128764f84b56a60b76b7c521 /tools | |
parent | 577ed9e01a83c13bf151b5137e6fe1eace1c4f7c (diff) |
meta: write a script to generate `src/init/syscalls.c`
Diffstat (limited to 'tools')
-rw-r--r-- | tools/syscall_wrappers.awk | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/syscall_wrappers.awk b/tools/syscall_wrappers.awk new file mode 100644 index 0000000..c1f980e --- /dev/null +++ b/tools/syscall_wrappers.awk @@ -0,0 +1,44 @@ +BEGIN { + print "\ +/* generated by tools/syscall_wrappers.awk\n\ + * don't modify manually, instead run:\n\ + * make src/init/syscalls.c\n\ + */\n\ +#include <shared/syscalls.h>\n\ +\n"; +} + +/_syscall\(/ { next; } # skipping _syscall(), it's implemented elsewhere + +/\);/ { + sub(/;/, " {"); + print $0; + + name = substr($0, match($0, /_syscall_[^(]+/), RLENGTH); + params = substr($0, match($0, /\(.+\)/) + 1, RLENGTH - 2); + if (params == "void") params = "" + + split(params, p, /,/); + for (i = 0; i <= 4; i += 1) { + if (p[i]) { + # p[i] is a parameter, convert it into an expression to pass to _syscall() + sub(/^ */, "", p[i]); # strip + split(p[i], words, / /); + if (length(words) != 1) { + var = words[length(words)]; + sub(/\*/, "", var); + if (words[1] != "int") var = "(int)" var; + } + p[i] = var; + } else { + p[i] = 0; + } + } + + printf "\t"; + if (!index($0, "_Noreturn")) printf "return "; + printf "_syscall(%s, %s, %s, %s, %s);\n", toupper(name), p[1], p[2], p[3], p[4]; + if (index($0, "_Noreturn")) print "\t__builtin_unreachable();"; + + print "}\n"; +} |