diff options
Diffstat (limited to 'libc/scripts/gen-as-const.awk')
-rw-r--r-- | libc/scripts/gen-as-const.awk | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/libc/scripts/gen-as-const.awk b/libc/scripts/gen-as-const.awk index bc3c47fb7..20d18c12a 100644 --- a/libc/scripts/gen-as-const.awk +++ b/libc/scripts/gen-as-const.awk @@ -14,12 +14,22 @@ BEGIN { started = 0 } NF >= 1 && !started { if (test) { + print "\n#include <inttypes.h>"; print "\n#include <stdio.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 (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));" \ + " 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 |