2002-12-28 07:05:53 +08:00
|
|
|
# Script used in producing headers of assembly constants from C expressions.
|
|
|
|
# The input to this script looks like:
|
|
|
|
# #cpp-directive ...
|
|
|
|
# NAME1
|
|
|
|
# NAME2 expression ...
|
|
|
|
# The output of this script is C code to be run through gcc -S and then
|
|
|
|
# massaged to extract the integer constant values of the given C expressions.
|
|
|
|
# A line giving just a name implies an expression consisting of just that name.
|
|
|
|
|
|
|
|
BEGIN { started = 0 }
|
|
|
|
|
|
|
|
# cpp directives go straight through.
|
|
|
|
/^#/ { print; next }
|
|
|
|
|
|
|
|
NF >= 1 && !started {
|
2007-07-13 02:26:36 +08:00
|
|
|
if (test) {
|
|
|
|
print "\n#include <stdio.h>";
|
|
|
|
print "\nstatic int do_test (void)\n{\n int bad = 0, good = 0;\n";
|
|
|
|
print "#define TEST(name, source, expr) \\\n" \
|
|
|
|
" if (asconst_##name != (expr)) { ++bad;" \
|
|
|
|
" fprintf (stderr, \"%s: %s is %ld but %s is %ld\\n\"," \
|
|
|
|
" source, #name, (long int) asconst_##name, #expr, (long int) (expr));" \
|
|
|
|
" } else ++good;\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
print "void dummy(void) {";
|
2002-12-28 07:05:53 +08:00
|
|
|
started = 1;
|
|
|
|
}
|
|
|
|
|
2003-01-15 16:08:20 +08:00
|
|
|
# Separator.
|
|
|
|
$1 == "--" { next }
|
|
|
|
|
2002-12-28 07:05:53 +08:00
|
|
|
NF == 1 { sub(/^.*$/, "& &"); }
|
|
|
|
|
|
|
|
NF > 1 {
|
|
|
|
name = $1;
|
|
|
|
sub(/^[^ ]+[ ]+/, "");
|
2007-07-13 02:26:36 +08:00
|
|
|
if (test)
|
|
|
|
print " TEST (" name ", \"" FILENAME ":" FNR "\", " $0 ")";
|
|
|
|
else
|
|
|
|
printf "asm (\"@@@name@@@%s@@@value@@@%%0@@@end@@@\" : : \"i\" (%s));\n",
|
|
|
|
name, $0;
|
2002-12-28 07:05:53 +08:00
|
|
|
}
|
|
|
|
|
2007-07-13 02:26:36 +08:00
|
|
|
END {
|
|
|
|
if (test) {
|
|
|
|
print " printf (\"%d errors in %d tests\\n\", bad, good + bad);"
|
|
|
|
print " return bad != 0 || good == 0;\n}\n";
|
|
|
|
print "#define TEST_FUNCTION do_test ()";
|
|
|
|
}
|
|
|
|
else if (started) print "}";
|
|
|
|
}
|