Menu

#16 %macro in listing: substitute parameters

open
nobody
None
1
2004-02-15
2002-11-27
No

I think it would be quite useful to have NASM
substitute parameter references (%1 etc.) with actual
macro parameters in macro expansions in the listing.
Consider this code (straight from the manual):

1 %macro silly 2
2 %2: db %1
3 %endmacro
4
5 silly
'a', letter_a
6 00000000 61 <1> %2: db %1
7 silly
'ab', string_ab
8 00000001 6162 <1> %2: db %1
9 silly
{13,10}, crlf
10 00000003 0D0A <1> %2: db %1

With the proposed macro parameter substitution, the
listing would look like this instead:

1 %macro silly 2
2 %2: db %1
3 %endmacro
4
5 silly
'a', letter_a
6 00000000 61 <1> letter_a: db 'a'
7 silly
'ab', string_ab
8 00000001 6162 <1> string_ab: db 'ab'
9 silly
{13,10}, crlf
10 00000003 0D0A <1> crlf: db 13,10

With large source code, this would make it much easier
to see e.g. whether macros work as intended.

The attached patch does the proposed change; as you can
see, it requires only a minor change to preproc.c.

Discussion

  • Marcin Grzegorczyk

    Macro listing parameter substitution patch for NASM 0.98.35

     
  • Nobody/Anonymous

    Logged In: NO

    I strongly suggest that we make this optional, i.e. have
    a command line option which selects between the old
    and the new behavior.

    NASM is old enough so that backward compatibility is
    becoming an issue...

     
  • Nobody/Anonymous

    Logged In: NO

    I've applied this patch to my local tree, and I've
    added support for a command line option, to control
    whether the old or the new behavior takes effect.

    After a couple of uneventful weeks, I have just run
    into a problem that seems to be caused by the patch.

    Since I'm not at liberty to post the actual code, I
    have come up with the following "artificial" case.
    It assumes that there is an environment variable
    called USERNAME, but no environment variable that
    is called MISSING. You may use different variables
    depending on your particular environment, as long
    as one is defined, but the other one is not.

    ; plain use of %! -> works
    [extern %!USERNAME] ; works
    [extern %!MISSING] ; complains as expected

    ; use of %! inside single-line macro -> works
    %define d1 [extern %!USERNAME]
    %define d2 [extern %!MISSING]
    d1 ; works
    d2 ; complains as expected

    ; use of %! in multi-line macro -> broken
    extern %!USERNAME ; works
    extern %!MISSING ; causes a core dump! :-(

    Without the patch, I don't get the core dump. With
    the patch, I do. Hence I suspect that this patch is
    the cause of the problem. However, I haven't been
    able to figure out yet, where/why things go wrong.

    Perhaps you can help?

     
  • Nobody/Anonymous

    Logged In: NO

    I've isolated the problem, and come up with a fix.

    Since the problem really is independent from this patch
    even though it only manifests itself whenever this patch
    is applied, I have filed a separate bug report.

    See SourceForge #731818 for details.

     
  • nasm64developer

    nasm64developer - 2004-02-15
    • priority: 5 --> 1
     

Log in to post a comment.