gensym.awk 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #
  2. # Copyright (c) 1994 The University of Utah and
  3. # the Computer Systems Laboratory (CSL). All rights reserved.
  4. #
  5. # Permission to use, copy, modify and distribute this software and its
  6. # documentation is hereby granted, provided that both the copyright
  7. # notice and this permission notice appear in all copies of the
  8. # software, derivative works or modified versions, and any portions
  9. # thereof, and that both notices appear in supporting documentation.
  10. #
  11. # THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
  12. # IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
  13. # ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  14. #
  15. # CSL requests users of this software to return to csl-dist@cs.utah.edu any
  16. # improvements that they make and grant CSL redistribution rights.
  17. #
  18. # Author: Bryan Ford, University of Utah CSL
  19. #
  20. BEGIN {
  21. bogus_printed = "no"
  22. }
  23. # Start the bogus function just before the first sym directive,
  24. # so that any #includes higher in the file don't get stuffed inside it.
  25. /^[a-z]/ {
  26. if (bogus_printed == "no")
  27. {
  28. print "void bogus() {";
  29. bogus_printed = "yes";
  30. }
  31. }
  32. # Take an arbitrarily complex C symbol or expression and constantize it.
  33. /^expr/ {
  34. print "__asm (\"\\n\\";
  35. if ($3 == "")
  36. printf "* %s mAgIc%%0\" : : \"i\" (%s));\n", $2, $2;
  37. else
  38. printf "* %s mAgIc%%0\" : : \"i\" (%s));\n", $3, $2;
  39. }
  40. # Output a symbol defining the size of a C structure.
  41. /^size/ {
  42. print "__asm (\"\\n\\";
  43. if ($4 == "")
  44. printf "* %s_SIZE mAgIc%%0\" : : \"i\" (sizeof(struct %s)));\n",
  45. toupper($3), $2;
  46. else
  47. printf "* %s mAgIc%%0\" : : \"i\" (sizeof(struct %s)));\n",
  48. $4, $2;
  49. }
  50. # Output a symbol defining the byte offset of an element of a C structure.
  51. /^offset/ {
  52. print "__asm (\"\\n\\";
  53. if ($5 == "")
  54. {
  55. printf "* %s_%s mAgIc%%0\" : : \"i\" (&((struct %s*)0)->%s));\n",
  56. toupper($3), toupper($4), $2, $4;
  57. }
  58. else
  59. {
  60. printf "* %s mAgIc%%0\" : : \"i\" (&((struct %s*)0)->%s));\n",
  61. toupper($5), $2, $4;
  62. }
  63. }
  64. # Copy through all preprocessor directives.
  65. /^#/ {
  66. print
  67. }
  68. END {
  69. print "}"
  70. }