gen-as-const.awk 835 B

123456789101112131415161718192021222324252627282930313233
  1. # Script used in producing headers of assembly constants from C expressions.
  2. # The input to this script looks like:
  3. # #cpp-directive ...
  4. # NAME1
  5. # NAME2 expression ...
  6. # The output of this script is C code to be run through gcc -S and then
  7. # massaged to extract the integer constant values of the given C expressions.
  8. # A line giving just a name implies an expression consisting of just that name.
  9. BEGIN { started = 0 }
  10. # cpp directives go straight through.
  11. /^#/ { print; next }
  12. NF >= 1 && !started {
  13. printf "void dummy(void);\n";
  14. print "void dummy(void) {";
  15. started = 1;
  16. }
  17. # Separator.
  18. $1 == "--" { next }
  19. NF == 1 { sub(/^.*$/, "& &"); }
  20. NF > 1 {
  21. name = $1;
  22. sub(/^[^ ]+[ ]+/, "");
  23. printf "__asm__ (\"@@@name@@@%s@@@value@@@%%0@@@end@@@\" : : \"i\" ((long) %s));\n",
  24. name, $0;
  25. }
  26. END { if (started) print "}" }