gen_wrappers.awk 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. BEGIN {
  2. FS = ",[ ]*";
  3. print "/*";
  4. print " * wrappers.c (Automatically generated)";
  5. print " *";
  6. print " * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>";
  7. print " *";
  8. print " * This program is free software: you can redistribute it and/or modify";
  9. print " * it under the terms of the GNU Affero General Public License as";
  10. print " * published by the Free Software Foundation, either version 3 of the";
  11. print " * License, or (at your option) any later version.";
  12. print " *";
  13. print " * This program is distributed in the hope that it will be useful,";
  14. print " * but WITHOUT ANY WARRANTY; without even the implied warranty of";
  15. print " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the";
  16. print " * GNU Affero General Public License for more details.";
  17. print " *";
  18. print " * You should have received a copy of the GNU Affero General Public License";
  19. print " * along with this program. If not, see <http://www.gnu.org/licenses/>.";
  20. print " */";
  21. print "";
  22. print "#include <sdk/monolithium.h>";
  23. print "";
  24. }
  25. /sysret_t syscall_[a-zA-Z0-9_]+\(.*\);/ {
  26. print substr($0, 1, length - 1);
  27. print "{";
  28. match($0, /\(.*\)/);
  29. printf " return syscall(" toupper(substr($0, 10, RSTART - 10));
  30. $0 = substr($0, RSTART + 1, RLENGTH - 2);
  31. if ($0 != "void") {
  32. for (i = 1; i <= NF; i++) {
  33. match($i, /[a-zA-Z0-9_]*$/);
  34. printf ", " substr($i, RSTART);
  35. }
  36. }
  37. print ");";
  38. print "}";
  39. print "";
  40. }