Last change
on this file since 77578e8 was cccf787, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago |
Update that one AWK script
|
-
Property mode
set to
100755
|
File size:
1.3 KB
|
Line | |
---|
1 | #!/usr/bin/awk -f
|
---|
2 | #
|
---|
3 | # SPDX-FileCopyrightText: 2018 CZ.NIC, z.s.p.o.
|
---|
4 | #
|
---|
5 | # SPDX-License-Identifier: BSD-3-Clause
|
---|
6 | #
|
---|
7 |
|
---|
8 | # Authors:
|
---|
9 | # Jiří Zárevúcky <jiri.zarevucky@nic.cz>
|
---|
10 |
|
---|
11 | BEGIN {
|
---|
12 | filename = ARGV[1]
|
---|
13 | output_lines = 0
|
---|
14 | print "// Generated file. Fix the included header if static assert fails."
|
---|
15 | print "// Inlined \"" filename "\""
|
---|
16 | }
|
---|
17 |
|
---|
18 | {
|
---|
19 | print $0
|
---|
20 | }
|
---|
21 |
|
---|
22 | /}.*;/ {
|
---|
23 | pattern = "}( __attribute__\\(.*\\))? (" struct_name "_t)?;"
|
---|
24 | if ($0 !~ pattern) {
|
---|
25 | print("Bad struct ending: " $0) > "/dev/stderr"
|
---|
26 | exit 1
|
---|
27 | }
|
---|
28 | macro_name = toupper(struct_name) "_SIZE"
|
---|
29 | output[output_lines++] = "_Static_assert(" macro_name " == sizeof(struct " struct_name "), \"\");"
|
---|
30 | struct_name = ""
|
---|
31 | }
|
---|
32 |
|
---|
33 | /;$/ {
|
---|
34 | if (struct_name != "") {
|
---|
35 | # Remove array subscript, if any.
|
---|
36 | sub("(\\[.*\\])?;", "", $0)
|
---|
37 | member = $NF
|
---|
38 |
|
---|
39 | macro_name = toupper(struct_name) "_OFFSET_" toupper(member)
|
---|
40 | output[output_lines++] = "_Static_assert(" macro_name " == __builtin_offsetof(struct " struct_name ", " member "), \"\");"
|
---|
41 |
|
---|
42 | macro_name = toupper(struct_name) "_SIZE_" toupper(member)
|
---|
43 | output[output_lines++] = "#ifdef " macro_name
|
---|
44 | output[output_lines++] = "_Static_assert(" macro_name " == sizeof(((struct " struct_name "){ })." member "), \"\");"
|
---|
45 | output[output_lines++] = "#endif"
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | /^typedef struct .* \{/ {
|
---|
50 | struct_name = $3
|
---|
51 | }
|
---|
52 |
|
---|
53 | END {
|
---|
54 | for ( i = 0; i < output_lines; i++ ) {
|
---|
55 | print output[i]
|
---|
56 | }
|
---|
57 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.