]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: extend \+ support to .irp / .irpc
authorJan Beulich <jbeulich@suse.com>
Fri, 24 May 2024 10:23:22 +0000 (12:23 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 24 May 2024 10:23:22 +0000 (12:23 +0200)
PR gas/31752

These are effectively macro-like, without any separate macro definition.
They already support \@, so they would better also support \+. This
allows, where desired, to get away without maintaining an explicit count
variable in source code.

With this the recently introduced testcase doesn't need any xfails
anymore.

gas/NEWS
gas/macro.c
gas/testsuite/gas/macros/irp-count.d [deleted file]
gas/testsuite/gas/macros/irp-count.l
gas/testsuite/gas/macros/irp-count.s
gas/testsuite/gas/macros/macros.exp

index 0fbd244c518cfcca598011ffcd840cd98c458d70..804ef3559a7b03da010b78d5c95c7b88f2dd84ff 100644 (file)
--- a/gas/NEWS
+++ b/gas/NEWS
@@ -1,8 +1,9 @@
 -*- text -*-
 
-* Assembler macros can now use the syntax \+ to access the number of times a
-  given macro has been executed.  This is similar to the already existing \@
-  syntax, except that the count is maintained on a per-macro basis.
+* Assembler macros as well as the bodies of .irp / .irpc can now use the
+  syntax \+ to access the number of times a given macro has been executed.
+  This is similar to the already existing \@ syntax, except that the count is
+  maintained on a per-macro basis.
   
 * Support the NF feature in Intel APX.
 
index 077bb019a3139449e5f47e4794189d8b043df564..a35e1356bbff5a64f01e1e1a5e7a2b17ea3185c2 100644 (file)
@@ -798,7 +798,8 @@ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
 
 static const char *
 macro_expand_body (sb *in, sb *out, formal_entry *formals,
-                  struct htab *formal_hash, const macro_entry *macro)
+                  struct htab *formal_hash, const macro_entry *macro,
+                  unsigned int instance)
 {
   sb t;
   size_t src = 0;
@@ -854,13 +855,13 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
              sprintf (buffer, "%u", macro_number);
              sb_add_string (out, buffer);
            }
-         else if (macro && src < in->len && in->ptr[src] == '+')
+         else if (src < in->len && in->ptr[src] == '+')
            {
              /* Sub in the current macro invocation number.  */
 
              char buffer[12];
              src++;
-             sprintf (buffer, "%d", macro->count);
+             sprintf (buffer, "%d", instance);
              sb_add_string (out, buffer);
            }
          else if (src < in->len && in->ptr[src] == '&')
@@ -1213,7 +1214,8 @@ macro_expand (size_t idx, sb *in, macro_entry *m, sb *out)
            }
        }
 
-      err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, m);
+      err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, m,
+                              m->count);
     }
 
   /* Discard any unnamed formal arguments.  */
@@ -1363,11 +1365,12 @@ expand_irp (int irpc, size_t idx, sb *in, sb *out, size_t (*get_line) (sb *))
   if (idx >= in->len)
     {
       /* Expand once with a null string.  */
-      err = macro_expand_body (&sub, out, &f, h, 0);
+      err = macro_expand_body (&sub, out, &f, h, NULL, 0);
     }
   else
     {
       bool in_quotes = false;
+      unsigned int instance = 0;
 
       while (idx < in->len)
        {
@@ -1392,7 +1395,8 @@ expand_irp (int irpc, size_t idx, sb *in, sb *out, size_t (*get_line) (sb *))
              ++idx;
            }
 
-         err = macro_expand_body (&sub, out, &f, h, 0);
+         err = macro_expand_body (&sub, out, &f, h, NULL, instance);
+         ++instance;
          if (err != NULL)
            break;
          if (!irpc)
diff --git a/gas/testsuite/gas/macros/irp-count.d b/gas/testsuite/gas/macros/irp-count.d
deleted file mode 100644 (file)
index 66c51a6..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#name: Macro counters inside IRP commands (irp-count.d)
-# Tests that \+ does not trip up IRP commands
index d1015552dca60c6aaaf3c6ab6d29c09c7bb00be3..734032e5e4fa976e207566c64922ca88154d0be2 100644 (file)
@@ -1,3 +1,7 @@
 #...
-\+
-\+
+a0
+a1
+b2
+x0
+x1
+y2
index 1ff5c7b72f836d0d948f34f0fc22c07f22dd93f3..93d8c93b1706a10f62f4dde99ee3c6329d346355 100644 (file)
@@ -1,7 +1,7 @@
-       .irp i,1
-       .print "\+"
+       .irp i,a,a,b
+       .print "\i\+"
        .endr
        
-       .irpc i,1
-       .print "\+"
+       .irpc i,xxy
+       .print "\i\+"
        .endr
index 49347096e8d29ea248660ca68c338513a1b1797d..fbe50f3a68dd7cf260352c830fd1ed49bbdc7472 100644 (file)
@@ -103,11 +103,5 @@ gas_test_error "exit.s" "" ".exitm outside of a macro"
 
 run_list_test altmacro
 run_list_test count
-
-# The AVR, CRIS, MSP430 and Z80 targets define ONLY_STANDARD_ESCAPES,
-#  so \+ is rejected.
-# AIX targets need an extended regexp to match "\+".
-setup_xfail "avr-*-*" "cris*-*-*" "msp430-*-*" "z80-*-*" "*-*-aix*"
 run_list_test irp-count
-
 run_list_test irpc-quote