lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 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 | |
| 10 | BEGIN { started = 0 } |
| 11 | |
| 12 | # cpp directives go straight through. |
| 13 | /^#/ { print; next } |
| 14 | |
| 15 | NF >= 1 && !started { |
| 16 | printf "void dummy(void);\n"; |
| 17 | print "void dummy(void) {"; |
| 18 | started = 1; |
| 19 | } |
| 20 | |
| 21 | # Separator. |
| 22 | $1 == "--" { next } |
| 23 | |
| 24 | NF == 1 { sub(/^.*$/, "& &"); } |
| 25 | |
| 26 | NF > 1 { |
| 27 | name = $1; |
| 28 | sub(/^[^ ]+[ ]+/, ""); |
| 29 | printf "__asm__ (\"@@@name@@@%s@@@value@@@%%0@@@end@@@\" : : \"i\" ((long) %s));\n", |
| 30 | name, $0; |
| 31 | } |
| 32 | |
| 33 | END { if (started) print "}" } |