]> granicus.if.org Git - yasm/commitdiff
nasm-pp.c: Fix handling of nested %macro and nested %rep.
authorPeter Johnson <peter@tortall.net>
Sun, 17 Sep 2006 17:10:17 +0000 (17:10 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 17 Sep 2006 17:10:17 +0000 (17:10 -0000)
Reported (and test) by: Mathieu Monnier <manao@melix.net>
Fix by: nasm64developer@yahoo.com

svn path=/trunk/yasm/; revision=1619

modules/preprocs/nasm/nasm-pp.c
modules/preprocs/nasm/tests/Makefile.inc
modules/preprocs/nasm/tests/nasmpp-nested.asm [new file with mode: 0644]
modules/preprocs/nasm/tests/nasmpp-nested.errwarn [new file with mode: 0644]
modules/preprocs/nasm/tests/nasmpp-nested.hex [new file with mode: 0644]

index 97d49ce33b6ba3b029bccf92682930f708fa7abf..e41cd93feb006655ad5668d5bc3ad3b89e19ed50 100644 (file)
@@ -398,6 +398,8 @@ static const char **stdmacpos;
 static const char **extrastdmac = NULL;
 int any_extrastdmac;
 
+static int nested_mac_count, nested_rep_count;
+
 /*
  * Tokens are allocated in blocks to improve speed
  */
@@ -1831,6 +1833,29 @@ do_directive(Token * tline)
        return NO_DIRECTIVE_FOUND;
     }
 
+    if (defining) {
+       if (i == PP_MACRO || i == PP_IMACRO) {
+           nested_mac_count++;
+           return NO_DIRECTIVE_FOUND;
+       } else if (nested_mac_count > 0) {
+           if (i == PP_ENDMACRO) {
+               nested_mac_count--;
+               return NO_DIRECTIVE_FOUND;
+           }
+       }
+       if (!defining->name) {
+           if (i == PP_REP) {
+               nested_rep_count++;
+               return NO_DIRECTIVE_FOUND;
+           } else if (nested_rep_count > 0) {
+               if (i == PP_ENDREP) {
+                   nested_rep_count--;
+                   return NO_DIRECTIVE_FOUND;
+               }
+           }
+       }
+    }
+
     if (j != -2)
     {
        error(ERR_NONFATAL, "unknown preprocessor directive `%s'",
@@ -4132,6 +4157,8 @@ pp_reset(FILE *f, const char *file, int apass, efunc errfunc, evalfunc eval,
     nasm_src_set_linnum(0);
     istk->lineinc = 1;
     defining = NULL;
+    nested_mac_count = 0;
+    nested_rep_count = 0;
     for (h = 0; h < NHASH; h++)
     {
        mmacros[h] = NULL;
index 17acff5b6def8b4bac5ae9b2008071c10ff5557f..f2f6e5c5e8f301b5b60cbd2de828c6430908c12d 100644 (file)
@@ -13,5 +13,8 @@ EXTRA_DIST += modules/preprocs/nasm/tests/noinclude-err.asm
 EXTRA_DIST += modules/preprocs/nasm/tests/noinclude-err.errwarn
 EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-bigint.asm
 EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-bigint.hex
+EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-nested.asm
+EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-nested.errwarn
+EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-nested.hex
 EXTRA_DIST += modules/preprocs/nasm/tests/orgsect.asm
 EXTRA_DIST += modules/preprocs/nasm/tests/orgsect.hex
diff --git a/modules/preprocs/nasm/tests/nasmpp-nested.asm b/modules/preprocs/nasm/tests/nasmpp-nested.asm
new file mode 100644 (file)
index 0000000..ed1551b
--- /dev/null
@@ -0,0 +1,29 @@
+%MACRO WORK_1 0
+   %ASSIGN %%count1 4
+   %error %%count1
+   %REP %%count1
+   %ENDREP
+%ENDMACRO   
+
+%MACRO WORK_2 0
+   %ASSIGN %%count1 4
+   %error %%count1
+   %REP %%count1
+   %REP 4
+   %ENDREP
+   %ENDREP
+%ENDMACRO   
+
+%MACRO DONT_WORK_1 0
+   %ASSIGN %%count1 4
+   %ASSIGN %%count2 4
+   %error %%count1 %%count2
+   %REP %%count1
+   %REP %%count2
+   %ENDREP
+   %ENDREP
+%ENDMACRO   
+
+WORK_1 
+WORK_2
+DONT_WORK_1
diff --git a/modules/preprocs/nasm/tests/nasmpp-nested.errwarn b/modules/preprocs/nasm/tests/nasmpp-nested.errwarn
new file mode 100644 (file)
index 0000000..101c132
--- /dev/null
@@ -0,0 +1,3 @@
+-:26: warning: (WORK_1:4) 0x4
+-:26: warning: (WORK_2:4) 0x4
+-:26: warning: (DONT_WORK_1:6) 0x4 0x4
diff --git a/modules/preprocs/nasm/tests/nasmpp-nested.hex b/modules/preprocs/nasm/tests/nasmpp-nested.hex
new file mode 100644 (file)
index 0000000..e69de29