From c89f4e122d5ed54118b09f6af66922a0c5cb5cca Mon Sep 17 00:00:00 2001 From: miod Date: Mon, 7 Oct 2024 15:41:46 +0000 Subject: [PATCH] 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@ --- sys/kern/genassym.sh | 40 +++++++++++++++++++++++----------------- 1 file 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) -- 2.20.1