diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2024-10-07 15:41:47 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2024-10-07 15:41:47 +0000 |
commit | 892349a85f8902ed7b3559f3f7f99935d5cb8c3b (patch) | |
tree | 540c20860356ae3aec82933a576546f66f3ce3ad /sys | |
parent | 63b0d08bdc87bc8cbe3878fbefb49d8c03949094 (diff) |
Tweak genassym code generation to force preprocessor conditional directives
to always be put inside functions.
This allows such statements to appear anywhere in assym.cf; without this
change they would require at least one `export' or `define' stanza to occur
first.
Problem noticed by & ok jsg@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/genassym.sh | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/sys/kern/genassym.sh b/sys/kern/genassym.sh index a28dd70e9d4..bf686c8624a 100644 --- a/sys/kern/genassym.sh +++ b/sys/kern/genassym.sh @@ -1,4 +1,4 @@ -# $OpenBSD: genassym.sh,v 1.14 2021/03/06 09:20:49 jsg Exp $ +# $OpenBSD: genassym.sh,v 1.15 2024/10/07 15:41:46 miod Exp $ # $NetBSD: genassym.sh,v 1.9 1998/04/25 19:48:27 matthias Exp $ # @@ -55,6 +55,24 @@ BEGIN { asmprint = ""; } +function start_define() { + if (defining == 0) { + defining = 1; + printf("void f" FNR "(void);\n"); + printf("void f" FNR "(void) {\n"); + if (ccode) + call[FNR] = "f" FNR; + defining = 1; + } +} + +function end_define() { + if (defining != 0) { + defining = 0; + printf("}\n"); + } +} + $0 ~ /^[ \t]*#.*/ || $0 ~ /^[ \t]*$/ { # Just ignore comments and empty lines next; @@ -68,10 +86,7 @@ $0 ~ /^config[ \t]/ { } /^include[ \t]/ { - if (defining != 0) { - defining = 0; - printf("}\n"); - } + end_define(); if (includes[$2] == 0) { printf("#%s\n", $0); includes[$2] = 1; @@ -85,6 +100,7 @@ $0 ~ /^ifndef[ \t]/ || $0 ~ /^else/ || $0 ~ /^elif[ \t]/ || $0 ~ /^endif/ { + start_define(); printf("#%s\n", $0); next; } @@ -129,14 +145,7 @@ $0 ~ /^endif/ { } /^define[ \t]/ { - if (defining == 0) { - defining = 1; - printf("void f" FNR "(void);\n"); - printf("void f" FNR "(void) {\n"); - if (ccode) - call[FNR] = "f" FNR; - defining = 1; - } + start_define(); value = $0 gsub("^define[ \t]+[A-Za-z_][A-Za-z_0-9]*[ \t]+", "", value) if (ccode) @@ -158,10 +167,7 @@ $0 ~ /^endif/ { } END { - if (defining != 0) { - defining = 0; - printf("}\n"); - } + end_define(); if (ccode) { printf("int main(int argc, char **argv) {"); for (i in call) |