RFC: Maintaining a per-macro invocation count

Nick Clifton nickc@redhat.com
Wed May 8 17:11:13 GMT 2024


Hi Guys,

  The attached patch implements a extension to the assembler's macro
  syntax, allowing a macro to access a count of the number of times that
  it has been executed via the \+ pseudo-variable.  ie like this:

    .macro foo
      .print "I have been invoked \+ times"
    .endm

  This syntax is similar to the already supported \@ pseudo-variable,
  except that the count is maintained on a per-macro basis.

  The drive for this extension is that I want to be able to generate
  N references to unique symbols in file A and then N definitions of
  those symbols in file B.  Using assembler macros makes this easy,
  providing that I can ensure that the names in file A will match those
  in file B.  ie:

  fileA.s:
    .macro gen_refs count
    .dc.a ref_\+
    .if \count > 1
    gen_refs \count-1
    .endif
    .endm

    gen_refs 1000

  fileB.s:
    .macro gen_defs count
    .global ref_\+
    ref_\+ :
    .if \count > 1
    gen_defs \count-1
    .endif
    .endm

    gen_defs 1000

  (This is part of a larger exercise to generate some micro benchmarks
  for the assembler that exercise various different features.  In this
  case I am looking into relocation processing).

  Comments, suggestions ?

Cheers
  Nick

PS. In the course of creating this patch I noticed that the altmacto
test (gas/testsuite/gas/macros/altmacro.d) does not appear to be run.
So I have fixed that as well.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gas.macro+.patch
Type: text/x-patch
Size: 5836 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20240508/71e076b3/attachment.bin>


More information about the Binutils mailing list