1 # Script used in producing headers of assembly constants from C expressions.
2 # The input to this script looks like:
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.
12 # cpp directives go straight through.
17 print "\n#include <inttypes.h>";
18 print "\n#include <stdio.h>";
19 print "\n#if __WORDSIZE__ == 64";
20 print "\ntypedef uint64_t c_t;";
21 print "\n#define U(n) UINT64_C (n)";
22 print "\n#define PRI PRId64";
24 print "\ntypedef uint32_t c_t;";
25 print "\n#define U(n) UINT32_C (n)";
26 print "\n#define PRI PRId32";
28 print "\nstatic int do_test (void)\n{\n int bad = 0, good = 0;\n";
29 print "#define TEST(name, source, expr) \\\n" \
30 " if (U (asconst_##name) != (c_t) (expr)) { ++bad;" \
31 " fprintf (stderr, \"%s: %s is %\" PRI
\" but %s is
%\"PRI \"\\n\"," \
32 " source, #name, U (asconst_##name), #expr, (c_t) (expr));" \
36 print "void dummy(void) {";
43 NF ==
1 { sub(/^.
*$
/, "& &"); }
47 sub(/^
[^
]+[ ]+/, "");
49 print " TEST (" name
", \"" FILENAME ":" FNR "\", " $
0 ")";
51 printf "asm (\"@@@name@@@%s@@@value@@@%%0@@@end@@@\" : : \"i\" ((long) %s));\n",
57 print " printf (\"%d errors in %d tests\\n\", bad, good + bad);"
58 print " return bad != 0 || good == 0;\n}\n";
59 print "#define TEST_FUNCTION do_test ()";
61 else if (started
) print "}";