X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/566e87bb15a98ed499e79b45f6c834ad0ffdc3b7..4c819e9466a0573afae0f9787a4704a479517624:/src/gen-specstr.awk diff --git a/src/gen-specstr.awk b/src/gen-specstr.awk index c07856e..0bc8278 100755 --- a/src/gen-specstr.awk +++ b/src/gen-specstr.awk @@ -1,6 +1,6 @@ #!/bin/awk -f # -# Copyright © 2021, 2023 Nick Bowler +# Copyright © 2021, 2023-2024 Nick Bowler # # Generate a function to return the C keyword corresponding to a specifier # type as a string, for internal use by the output routines. @@ -22,7 +22,7 @@ END { BEGIN { kinds["TYPE"] = kinds["STOR"] = kinds["QUAL"] = kinds["FUNC"] = 1; - count = maxwidth = 0; + count = 0; } # Locate all the relevant identifiers in cdecl.h. We assume everything @@ -48,9 +48,6 @@ $1 ~ /^CDECL_/ { if (parts[2] in kinds) { kind_counts[parts[2]]++; specs[count++] = parts[3]; - - if (length(parts[3]) > maxwidth) - maxwidth = length(parts[3]); } } @@ -79,13 +76,13 @@ END { if (specs[i] == "IDENT") s = "0"; else - s = "T_" substr(specs[i] " ", 1, maxwidth) " - 256"; + s = "PACK_TOKEN(T_" specs[i] ")"; offset_table = offset_table s suffix; } print "static const char *spec_string(unsigned type)" print "{" - print "\tstatic const uint_least8_t idx[] = {"; + print "\tstatic const unsigned char _Alignas(1) idx[] = {"; print "\t\t" offset_table; print "\t};\n"; @@ -93,6 +90,6 @@ END { print "\tassert(x < sizeof idx);"; print "\tif (!(x = idx[x]))"; print "\t\treturn \"\";"; - print "\treturn cdecl__token_name(x + 256);"; + print "\treturn cdecl__token_name(UNPACK_TOKEN(x));"; print "}"; }