Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F161018255
D57865.id180675.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D57865.id180675.diff
View Options
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}"') .*/\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
Details
Attached
Mime Type
text/plain
Expires
Tue, Jun 30, 9:38 PM (12 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34524698
Default Alt Text
D57865.id180675.diff (2 KB)
Attached To
Mode
D57865: libsysdecode: parse enums
Attached
Detach File
Event Timeline
Log In to Comment