about summary refs log tree commit diff
path: root/scripts/gen-as-const.awk
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2018-11-30 15:20:41 +0000
committerJoseph Myers <joseph@codesourcery.com>2018-11-30 15:20:41 +0000
commit7e1d42400c1b8f03316fe14176133c8853cd3bbe (patch)
treec34eb3317fd3d98b8e4ca27b409621e9238d9a24 /scripts/gen-as-const.awk
parentce7387cc250a408d3fbb7a6fff7ad4d977166b00 (diff)
downloadglibc-7e1d42400c1b8f03316fe14176133c8853cd3bbe.tar.gz
glibc-7e1d42400c1b8f03316fe14176133c8853cd3bbe.tar.xz
glibc-7e1d42400c1b8f03316fe14176133c8853cd3bbe.zip
Replace gen-as-const.awk by gen-as-const.py.
This patch replaces gen-as-const.awk, and some fragments of the
Makefile code that used it, by a Python script.  The point is not such
much that awk is problematic for this particular script, as that I'd
like to build up a general Python infrastructure for extracting
information from C headers, for use in writing tests of such headers.
Thus, although this patch does not set up such infrastructure, the
compute_c_consts function in gen-as-const.py might be moved to a
separate Python module in a subsequent patch as a starting point for
such infrastructure.

The general idea of the code is the same as in the awk version, but no
attempt is made to make the output files textually identical.  When
generating a header, a dict of constant names and values is generated
internally then defines are printed in sorted order (rather than the
order in the .sym file, which would have been used before).  When
generating a test that the values computed match those from a normal
header inclusion, the test code is made into a compilation test using
_Static_assert, where previously the comparisons were done only when
the test was executed.  One fragment of test generation (converting
the previously generated header to use asconst_* prefixes on its macro
names) is still in awk code in the makefiles; only the .sym processing
and subsequent execution of the compiler to extract constants have
moved to the Python script.

Tested for x86_64, and with build-many-glibcs.py.

	* scripts/gen-as-const.py: New file.
	* scripts/gen-as-const.awk: Remove.
	* Makerules ($(common-objpfx)%.h $(common-objpfx)%.h.d): Use
	gen-as-const.py.
	($(objpfx)test-as-const-%.c): Likewise.
Diffstat (limited to 'scripts/gen-as-const.awk')
-rw-r--r--scripts/gen-as-const.awk63
1 files changed, 0 insertions, 63 deletions
diff --git a/scripts/gen-as-const.awk b/scripts/gen-as-const.awk
deleted file mode 100644
index 1ffd5f2c1c..0000000000
--- a/scripts/gen-as-const.awk
+++ /dev/null
@@ -1,63 +0,0 @@
-# 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 {
-  if (test) {
-    print "\n#include <inttypes.h>";
-    print "\n#include <stdio.h>";
-    print "\n#include <bits/wordsize.h>";
-    print "\n#if __WORDSIZE == 64";
-    print "\ntypedef uint64_t c_t;";
-    print "\n#define U(n) UINT64_C (n)";
-    print "\n#define PRI PRId64";
-    print "\n#else";
-    print "\ntypedef uint32_t c_t;";
-    print "\n#define U(n) UINT32_C (n)";
-    print "\n#define PRI PRId32";
-    print "\n#endif";
-    print "\nstatic int do_test (void)\n{\n  int bad = 0, good = 0;\n";
-    print "#define TEST(name, source, expr) \\\n" \
-      "  if (U (asconst_##name) != (c_t) (expr)) { ++bad;" \
-      " fprintf (stderr, \"%s: %s is %\" PRI \" but %s is %\"PRI \"\\n\"," \
-      " source, #name, U (asconst_##name), #expr, (c_t) (expr));" \
-      " } else ++good;\n";
-  }
-  else
-    print "void dummy(void) {";
-  started = 1;
-}
-
-# Separator.
-$1 == "--" { next }
-
-NF == 1 { sub(/^.*$/, "& &"); }
-
-NF > 1 {
-  name = $1;
-  sub(/^[^ 	]+[ 	]+/, "");
-  if (test)
-    print "  TEST (" name ", \"" FILENAME ":" FNR "\", " $0 ")";
-  else
-    printf "asm (\"@@@name@@@%s@@@value@@@%%0@@@end@@@\" : : \"i\" ((long) %s));\n",
-      name, $0;
-}
-
-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 "}";
-}