[BZ #5378]
[glibc.git] / scripts / gen-as-const.awk
blobbc3c47fb73dbfd78801e2b318141ec90059e801b
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.
10 BEGIN { started = 0 }
12 # cpp directives go straight through.
13 /^#/ { print; next }
15 NF >= 1 && !started {
16 if (test) {
17 print "\n#include <stdio.h>";
18 print "\nstatic int do_test (void)\n{\n int bad = 0, good = 0;\n";
19 print "#define TEST(name, source, expr) \\\n" \
20 " if (asconst_##name != (expr)) { ++bad;" \
21 " fprintf (stderr, \"%s: %s is %ld but %s is %ld\\n\"," \
22 " source, #name, (long int) asconst_##name, #expr, (long int) (expr));" \
23 " } else ++good;\n";
25 else
26 print "void dummy(void) {";
27 started = 1;
30 # Separator.
31 $1 == "--" { next }
33 NF == 1 { sub(/^.*$/, "& &"); }
35 NF > 1 {
36 name = $1;
37 sub(/^[^ ]+[ ]+/, "");
38 if (test)
39 print " TEST (" name ", \"" FILENAME ":" FNR "\", " $0 ")";
40 else
41 printf "asm (\"@@@name@@@%s@@@value@@@%%0@@@end@@@\" : : \"i\" ((long) %s));\n",
42 name, $0;
45 END {
46 if (test) {
47 print " printf (\"%d errors in %d tests\\n\", bad, good + bad);"
48 print " return bad != 0 || good == 0;\n}\n";
49 print "#define TEST_FUNCTION do_test ()";
51 else if (started) print "}";