# define SoM(type_, member_) (sizeof(((type_ *)0)->member_))
EOF
-for struct in $(sed -n 's/^struct \(BPF_[^[:space:]]\+_struct\) .*/\1/p' < "$input"); do
+for struct in $(sed -n 's/^struct \([^[:space:]]\+_struct\) .*/\1/p' < "$input"); do
+ case "$struct" in
+ BPF_*) type_name='union bpf_attr' ;;
+ *) type_name="struct ${struct%_struct}" ;;
+ esac
+ TYPE_NAME="$(printf %s "$type_name" |tr '[:lower:] ' '[:upper:]_')"
+
enum="$(sed -n 's/^struct '"$struct"' \/\* \([^[:space:]]\+\) \*\/ {.*/\1/p' < "$input")"
ENUM="$(printf %s "$enum" |tr '[:lower:]' '[:upper:]')"
enum="$enum${enum:+.}"
FIELD="$(printf %s "$field" |tr '[:lower:]' '[:upper:]')"
cat <<EOF
-# ifdef HAVE_UNION_BPF_ATTR_$ENUM$FIELD
- static_assert(SoM(struct $struct, $field) == SoM(union bpf_attr, $enum$field),
+# ifdef HAVE_${TYPE_NAME}_$ENUM$FIELD
+ static_assert(SoM(struct $struct, $field) == SoM($type_name, $enum$field),
"$struct.$field size mismatch");
- static_assert(offsetof(struct $struct, $field) == offsetof(union bpf_attr, $enum$field),
+ static_assert(offsetof(struct $struct, $field) == offsetof($type_name, $enum$field),
"$struct.$field offset mismatch");
-# endif /* HAVE_UNION_BPF_ATTR_$ENUM$FIELD */
+# endif /* HAVE_${TYPE_NAME}_$ENUM$FIELD */
EOF
done
cat <<EOF
AC_CHECK_MEMBERS(m4_normalize([
EOF
-fetch_structs()
-{
- local name="${1:-}"
- local name_re=
- [ -z "$name" ] ||
- name_re='\/\* '"$name"' \*\/ '
+gawk -e '
+/^struct ([^[:space:]]+)_struct([[:space:]]+\/\* ([^[:space:]]+) \*\/)?[[:space:]]+{/ {
+ match($0, /^struct ([^[:space:]]+)_struct([[:space:]]+\/\* ([^[:space:]]+) \*\/)?[[:space:]]+{/, a)
- sed -n '/^struct BPF_[^[:space:]]\+_struct '"$name_re"'{/,/^};/p' < "$input"
-}
+ struct_name = a[1]
+ subtype_name = a[3]
+
+ if (struct_name ~ /^BPF_/)
+ prefix = "union bpf_attr"
+ else
+ prefix = "struct " struct_name
+
+ if (subtype_name != "")
+ prefix = prefix "." subtype_name
-filter_entries()
-{
- local name="${1:-}"
- local subtype=
- [ -z "$name" ] ||
- subtype=".$name"
- local search='^[[:space:]]\+[^][;]*[[:space:]]\([^][[:space:];]\+\)\(\[[^;]*\]\)\?;$'
- local replacement='\t\tunion bpf_attr'"$subtype"'.\1,'
- sed -n "s/$search/$replacement/p" |
- sort -u
+ in_struct = 1
+ next
}
-# nameless structures in union bpf_attr
-fetch_structs |
- filter_entries
+/^}( ATTRIBUTE_ALIGNED\(.*\))?;/ {
+ in_struct = 0
+ next
+}
-# named structures in union bpf_attr
-for name in $(sed -n 's/^struct BPF_[^[:space:]]\+_struct \/\* \([^[:space:]]\+\) \*\/ {.*/\1/p' < "$input"); do
- fetch_structs "$name" |
- filter_entries "$name"
-done
+(in_struct == 1) {
+ if (match($0, /^[[:space:]]+[^;\[\]]+[[:space:]]+([^[:space:]\[\];]+)(\[[^;]*\])?;$/, a)) {
+ print "\t\t" prefix "." a[1] ","
+ }
+}
+' < "$input" | sort -u
cat <<'EOF'
union bpf_attr.dummy