summaryrefslogtreecommitdiff
path: root/m4/gen_bpf_attr_m4.awk
blob: 51d136f6f4046daaf81ffaeff19e7ecb8d3f0e6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/gawk -f
#
# Copyright (c) 2018-2019 Dmitry V. Levin <ldv@altlinux.org>
# All rights reserved.
#
# SPDX-License-Identifier: LGPL-2.1-or-later

/^struct ([^[:space:]]+)_struct([[:space:]]+\/\* ([^[:space:]]+) \*\/)?[[:space:]]+{/ {
	match($0, /^struct ([^[:space:]]+)_struct([[:space:]]+\/\* ([^[:space:]]+) \*\/)?[[:space:]]+{/, a)

	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

	in_struct = 1
	next
}

/^}( ATTRIBUTE_ALIGNED\(.*\))?;/ {
	in_struct = 0
	next
}

(in_struct == 1) {
	if (match($0, /^[[:space:]]+[^;:\[\]]+[[:space:]]+([^[:space:]\[\];:]+)(\[[^;:]*\])?;$/, a)) {
		print "\t\t" prefix "." a[1] ","
	}
}