2002-12-28 00:05:53 +01: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 {
|
2005-12-22 06:18:34 +01: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 00:05:53 +01:00
|
|
|
started = 1;
|
|
|
|
}
|
|
|
|
|
2003-01-15 09:08:20 +01:00
|
|
|
# Separator.
|
|
|
|
$1 == "--" { next }
|
|
|
|
|
2002-12-28 00:05:53 +01:00
|
|
|
NF == 1 { sub(/^.*$/, "& &"); }
|
|
|
|
|
|
|
|
NF > 1 {
|
|
|
|
name = $1;
|
|
|
|
sub(/^[^ ]+[ ]+/, "");
|
2005-12-22 06:18:34 +01:00
|
|
|
if (test)
|
|
|
|
print " TEST (" name ", \"" FILENAME ":" FNR "\", " $0 ")";
|
|
|
|
else
|
2007-01-19 02:02:19 +01:00
|
|
|
printf "asm (\"@@@name@@@%s@@@value@@@%%0@@@end@@@\" : : \"i\" ((long) %s));\n",
|
2005-12-22 06:18:34 +01:00
|
|
|
name, $0;
|
2002-12-28 00:05:53 +01:00
|
|
|
}
|
|
|
|
|
2005-12-22 06:18:34 +01: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 "}";
|
|
|
|
}
|