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
|
Rev | Line | |
---|
[d2f75eb] | 1 | #!/usr/bin/awk -f
|
---|
[bfe1fc1] | 2 | #
|
---|
[cccf787] | 3 | # SPDX-FileCopyrightText: 2018 CZ.NIC, z.s.p.o.
|
---|
[bfe1fc1] | 4 | #
|
---|
[cccf787] | 5 | # SPDX-License-Identifier: BSD-3-Clause
|
---|
[bfe1fc1] | 6 | #
|
---|
| 7 |
|
---|
| 8 | # Authors:
|
---|
| 9 | # Jiří Zárevúcky <jiri.zarevucky@nic.cz>
|
---|
[d2f75eb] | 10 |
|
---|
| 11 | BEGIN {
|
---|
| 12 | filename = ARGV[1]
|
---|
[536ab4f] | 13 | output_lines = 0
|
---|
[d2f75eb] | 14 | print "// Generated file. Fix the included header if static assert fails."
|
---|
[536ab4f] | 15 | print "// Inlined \"" filename "\""
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | {
|
---|
| 19 | print $0
|
---|
[d2f75eb] | 20 | }
|
---|
| 21 |
|
---|
| 22 | /}.*;/ {
|
---|
[8be3230] | 23 | pattern = "}( __attribute__\\(.*\\))? (" struct_name "_t)?;"
|
---|
| 24 | if ($0 !~ pattern) {
|
---|
| 25 | print("Bad struct ending: " $0) > "/dev/stderr"
|
---|
| 26 | exit 1
|
---|
[d2f75eb] | 27 | }
|
---|
[8be3230] | 28 | macro_name = toupper(struct_name) "_SIZE"
|
---|
[536ab4f] | 29 | output[output_lines++] = "_Static_assert(" macro_name " == sizeof(struct " struct_name "), \"\");"
|
---|
[8be3230] | 30 | struct_name = ""
|
---|
[d2f75eb] | 31 | }
|
---|
| 32 |
|
---|
| 33 | /;$/ {
|
---|
[8be3230] | 34 | if (struct_name != "") {
|
---|
[d2f75eb] | 35 | # Remove array subscript, if any.
|
---|
| 36 | sub("(\\[.*\\])?;", "", $0)
|
---|
| 37 | member = $NF
|
---|
| 38 |
|
---|
| 39 | macro_name = toupper(struct_name) "_OFFSET_" toupper(member)
|
---|
[536ab4f] | 40 | output[output_lines++] = "_Static_assert(" macro_name " == __builtin_offsetof(struct " struct_name ", " member "), \"\");"
|
---|
[d2f75eb] | 41 |
|
---|
| 42 | macro_name = toupper(struct_name) "_SIZE_" toupper(member)
|
---|
[536ab4f] | 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"
|
---|
[d2f75eb] | 46 | }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | /^typedef struct .* \{/ {
|
---|
| 50 | struct_name = $3
|
---|
[08f1a6d] | 51 | }
|
---|
[536ab4f] | 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.