aboutsummaryrefslogtreecommitdiff
path: root/gas/macro.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2024-05-13 09:56:09 +0100
committerNick Clifton <nickc@redhat.com>2024-05-13 09:56:09 +0100
commit83b972fc272db31ab48aa5cde84f47c98868d7c8 (patch)
tree535c22f6be9bf53b1475e9490681ed04987d4ae6 /gas/macro.c
parent7143ed12051c7e432d93f83b387a26ded3d8ddae (diff)
downloadbinutils-83b972fc272db31ab48aa5cde84f47c98868d7c8.zip
binutils-83b972fc272db31ab48aa5cde84f47c98868d7c8.tar.gz
binutils-83b972fc272db31ab48aa5cde84f47c98868d7c8.tar.bz2
Add new assembler macro pseudo-variable \+ which counts the number of times a macro has been invoked.
Diffstat (limited to 'gas/macro.c')
-rw-r--r--gas/macro.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/gas/macro.c b/gas/macro.c
index e2ee39b..72d869d 100644
--- a/gas/macro.c
+++ b/gas/macro.c
@@ -56,7 +56,7 @@ int macro_defined;
/* Number of macro expansions that have been done. */
-static int macro_number;
+static unsigned int macro_number;
static void free_macro (macro_entry *);
@@ -668,6 +668,7 @@ define_macro (sb *in, sb *label, size_t (*get_line) (sb *))
macro->formal_count = 0;
macro->formals = 0;
macro->formal_hash = str_htab_create ();
+ macro->count = 0;
idx = sb_skip_white (0, in);
if (! buffer_and_nest ("MACRO", "ENDM", &macro->sub, get_line))
@@ -846,11 +847,20 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
}
else if (src < in->len && in->ptr[src] == '@')
{
- /* Sub in the macro invocation number. */
+ /* Sub in the total macro invocation number. */
char buffer[12];
src++;
- sprintf (buffer, "%d", macro_number);
+ sprintf (buffer, "%u", macro_number);
+ sb_add_string (out, buffer);
+ }
+ else if (src < in->len && in->ptr[src] == '+')
+ {
+ /* Sub in the current macro invocation number. */
+
+ char buffer[12];
+ src++;
+ sprintf (buffer, "%d", macro->count);
sb_add_string (out, buffer);
}
else if (src < in->len && in->ptr[src] == '&')
@@ -1227,7 +1237,10 @@ macro_expand (size_t idx, sb *in, macro_entry *m, sb *out)
sb_kill (&t);
if (!err)
- macro_number++;
+ {
+ macro_number++;
+ m->count++;
+ }
return err;
}