xlat: extend syntax with #val_type directive

When #val_type directive is encountered, gen.sh starts using
XLAT_TYPE/XLAT_TYPE_PAIR macros instead of XLAT/XLAT_PAIR,
with #val_type's argument as a type.

For example, "#val_type uint64_t" means values of type uint64_t.

* xlat/gen.sh (gen_header, print_xlat, print_xlat_pair):
Add val_type support.
This commit is contained in:
Дмитрий Левин 2016-04-29 01:02:13 +00:00
parent 6b040fc505
commit 9ae46690bd

View File

@ -64,7 +64,11 @@ print_xlat()
local val local val
val="$1"; shift val="$1"; shift
if [ -z "${val_type-}" ]; then
echo " XLAT(${val})," echo " XLAT(${val}),"
else
echo " XLAT_TYPE(${val_type}, ${val}),"
fi
} }
print_xlat_pair() print_xlat_pair()
@ -73,7 +77,11 @@ print_xlat_pair()
val="$1"; shift val="$1"; shift
str="$1"; shift str="$1"; shift
if [ -z "${val_type-}" ]; then
echo " XLAT_PAIR(${val}, \"${str}\")," echo " XLAT_PAIR(${val}, \"${str}\"),"
else
echo " XLAT_TYPE_PAIR(${val_type}, ${val}, \"${str}\"),"
fi
} }
cond_xlat() cond_xlat()
@ -134,6 +142,9 @@ gen_header()
'#unterminated') '#unterminated')
unterminated=1 unterminated=1
;; ;;
'#val_type '*)
# to be processed during 2nd pass
;;
'#'*) '#'*)
echo "${line}" echo "${line}"
;; ;;
@ -175,7 +186,7 @@ gen_header()
fi fi
echo "const struct xlat ${name}[] = {" echo "const struct xlat ${name}[] = {"
unconditional= unconditional= val_type=
# 2nd pass: output everything. # 2nd pass: output everything.
while read line; do while read line; do
LC_COLLATE=C LC_COLLATE=C
@ -186,6 +197,9 @@ gen_header()
'#unterminated') '#unterminated')
# processed during 1st pass # processed during 1st pass
;; ;;
'#val_type '*)
val_type="${line#\#val_type }"
;;
[A-Z_]*) # symbolic constants [A-Z_]*) # symbolic constants
if [ -n "${unconditional}" ]; then if [ -n "${unconditional}" ]; then
print_xlat "${line}" print_xlat "${line}"