From f29ebbe3be5c2a4400ad8b89a8f399ead4448148 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Fri, 24 May 2024 12:23:22 +0200 Subject: gas: extend \+ support to .irp / .irpc 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 | 7 ++++--- gas/macro.c | 16 ++++++++++------ gas/testsuite/gas/macros/irp-count.d | 2 -- gas/testsuite/gas/macros/irp-count.l | 8 ++++++-- gas/testsuite/gas/macros/irp-count.s | 8 ++++---- gas/testsuite/gas/macros/macros.exp | 6 ------ 6 files changed, 24 insertions(+), 23 deletions(-) delete mode 100644 gas/testsuite/gas/macros/irp-count.d diff --git a/gas/NEWS b/gas/NEWS index 0fbd244..804ef35 100644 --- 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. diff --git a/gas/macro.c b/gas/macro.c index 077bb01..a35e135 100644 --- a/gas/macro.c +++ b/gas/macro.c @@ -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 index 66c51a6..0000000 --- a/gas/testsuite/gas/macros/irp-count.d +++ /dev/null @@ -1,2 +0,0 @@ -#name: Macro counters inside IRP commands (irp-count.d) -# Tests that \+ does not trip up IRP commands diff --git a/gas/testsuite/gas/macros/irp-count.l b/gas/testsuite/gas/macros/irp-count.l index d101555..734032e 100644 --- a/gas/testsuite/gas/macros/irp-count.l +++ b/gas/testsuite/gas/macros/irp-count.l @@ -1,3 +1,7 @@ #... -\+ -\+ +a0 +a1 +b2 +x0 +x1 +y2 diff --git a/gas/testsuite/gas/macros/irp-count.s b/gas/testsuite/gas/macros/irp-count.s index 1ff5c7b..93d8c93 100644 --- a/gas/testsuite/gas/macros/irp-count.s +++ b/gas/testsuite/gas/macros/irp-count.s @@ -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 diff --git a/gas/testsuite/gas/macros/macros.exp b/gas/testsuite/gas/macros/macros.exp index 4934709..fbe50f3 100644 --- a/gas/testsuite/gas/macros/macros.exp +++ b/gas/testsuite/gas/macros/macros.exp @@ -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 -- cgit v1.1