diff options
author | Mattias Andrée <maandree@kth.se> | 2023-12-03 19:23:35 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-12-03 19:23:35 +0100 |
commit | c131f122778c62f920a99bbf854ced4a37ee8b03 (patch) | |
tree | 14c933f98f4d64dffb0a594bc40dd5121c6c5a8e /util/make-enum | |
download | libsyscalls-c131f122778c62f920a99bbf854ced4a37ee8b03.tar.gz libsyscalls-c131f122778c62f920a99bbf854ced4a37ee8b03.tar.bz2 libsyscalls-c131f122778c62f920a99bbf854ced4a37ee8b03.tar.xz |
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'util/make-enum')
-rwxr-xr-x | util/make-enum | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/util/make-enum b/util/make-enum new file mode 100755 index 0000000..7b63e3c --- /dev/null +++ b/util/make-enum @@ -0,0 +1,45 @@ +#!/bin/sh + +set -e + +test $# -ge 1 + +lowercase () { printf '%s\n' "$*" | tr '[A-Z]' '[a-z]'; } + +symbols="$(lowercase "$1")" +shift 1 + +validate () { + if (( -$1 > 0x7FFF )) || (( +$1 > 0x7FFF )); then + printf 'Invalid enum value: %s = %x (beyond 16-bit signed integer)\n' $2 $1 >&2 + return 1 + else + return 0 + fi +} + +printf 'static const char *\n' +printf 'extract_symbol_%s(struct libsyscalls_symbol_printer_data *data, ' "$symbols" +printf 'unsigned long long int *valuep, char *fallback_out) /* 1 */\n' +printf '{\n' +printf ' const char *ret;\n' +printf ' switch ((signed long long int)*valuep) {\n' +while read name value; do +validate $value $name +printf ' case %i: ret = "%s"; break;\n' $value $name +done +printf ' default:\n' +if test $# -ge 1; then + for use; do +printf ' if ((ret = extract_symbol_%s(data, valuep, fallback_out))) return ret;\n' "$(lowercase "$use")" + done +fi +printf ' return NULL;\n' +printf ' }\n' +printf ' *valuep = 0;\n' +if test $# = 0; then +printf ' (void) data;\n' +printf ' (void) fallback_out;\n' +fi +printf ' return ret;\n' +printf '}\n' |