Page MenuHomeFreeBSD

D57865.id180730.diff
No OneTemporary

D57865.id180730.diff

diff --git a/lib/libsysdecode/Makefile b/lib/libsysdecode/Makefile
--- a/lib/libsysdecode/Makefile
+++ b/lib/libsysdecode/Makefile
@@ -133,6 +133,7 @@
MKTABLES_INCLUDEDIR= ${SYSROOT:U${DESTDIR}}${INCLUDEDIR}
.endif
tables.h: mktables
+ env COMPILER_TYPE="${COMPILER_TYPE}" \
sh ${.CURDIR}/mktables ${MKTABLES_INCLUDEDIR} ${.TARGET}
tables_linux.h: mklinuxtables
sh ${.CURDIR}/mklinuxtables ${SRCTOP}/sys ${.TARGET}
diff --git a/lib/libsysdecode/mktables b/lib/libsysdecode/mktables
--- a/lib/libsysdecode/mktables
+++ b/lib/libsysdecode/mktables
@@ -84,6 +84,64 @@
_EOF_
}
+#
+# Generate a table from a named enum declaration. Tries to really parse a
+# fragment of AST.
+# Caveats:
+# - doesn't support typedefed anonymous enums
+# - works only with clang build
+#
+gen_table_enum()
+{
+ local name enum file
+ name=$1
+ enum=$2
+ file=$3
+
+ echo TABLE_START\(${name}\)
+ if [ ${COMPILER_TYPE} = "clang" ]; then
+ TERM= clang -fsyntax-only -Xclang -ast-dump -x c \
+ "${include_dir}/${file}" | \
+ sed -nE '
+ /^((\| )+)?\|-EnumDecl .* '"${enum}"'$/ {
+ :loop
+ n
+ / [|`]-EnumConstantDecl/ {
+ h
+ s/.*col:[0-9]+ ([A-Z_][A-Z0-9_]+).*/TABLE_ENTRY(\1)/p
+ x
+ /`-EnumConstantDecl/q
+ }
+ b loop
+ }'
+ fi
+ echo TABLE_END
+ echo
+}
+
+#
+# Generate a table from enum values that match regexp. May be used for
+# anonymous enums.
+# Caveats:
+# - works only with clang build
+#
+gen_table_enum_re()
+{
+ local name enumre file
+ name=$1
+ enumre=$2
+ file=$3
+
+ echo TABLE_START\(${name}\)
+ if [ ${COMPILER_TYPE} = "clang" ]; then
+ TERM= clang -fsyntax-only -Xclang -ast-dump -x c \
+ "${include_dir}/${file}" | sed -nE \
+ 's/.*[|`]-EnumConstantDecl .* col:[0-9]+ ('"${enumre}"') .*/TABLE_ENTRY(\1)/p'
+ fi
+ echo TABLE_END
+ echo
+}
+
cat <<_EOF_
/* This file is auto-generated. */
@@ -127,7 +185,7 @@
gen_table "schedpolicy" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sys/sched.h"
gen_table "sendfileflags" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
gen_table "shmatflags" "SHM_[A-Z]+[[:space:]]+[0-9]{6}" "sys/shm.h"
-gen_table "shutdownhow" "SHUT_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
+gen_table_enum "shutdownhow" shutdown_how "sys/socket.h"
gen_table "sigbuscode" "BUS_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
gen_table "sigchldcode" "CLD_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
gen_table "sigfpecode" "FPE_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"

File Metadata

Mime Type
text/plain
Expires
Tue, Jun 30, 1:04 PM (3 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34474277
Default Alt Text
D57865.id180730.diff (2 KB)

Event Timeline