Author Topic: [HJWASM Bug] Output Stream and Macro Stream not separate during macro parsing  (Read 2773 times)

dawnraider

  • Regular Member
  • *
  • Posts: 26
Hi Habran,

I recently came across another bug in HJWasm to do with macro parsing. Create a new file test.asm as follows:

Code: [Select]
tempvar TEXTEQU <MyProc PROC param1:DWORD,>

MyMacro MACRO
tempvar
EXITM
ENDM

.CODE

MyMacro

ret

MyProc ENDP

END

With ml64.exe this assembles fine. However, with HJWasm, the following error occurs:

Code: [Select]
JWasm v2.11, Oct 20 2013, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.

x.asm(10) : Error A2209: Syntax error: EXITM
 MyMacro(2)[x.asm]: Macro called from
  x.asm(10): Main line code
x.asm: 16 lines, 1 passes, 0 ms, 0 warnings, 1 errors

The problem appears to be that the output stream and the macro parsing stream and being merged, hence the EXITM is being
appended to the PROC declaration with the comma at the end even though they are technically two different processing streams.

Here is the listing file from ml64.exe

Code: [Select]
= MyProc PROC param1:DWORD     tempvar TEXTEQU <MyProc PROC param1:DWORD,>
   ,

                                MyMacro MACRO
                                tempvar
                                EXITM
                                ENDM

 00000000                       .CODE

                                MyMacro
 00000000                    1  tempvar

                                        ret

 00000006                       MyProc ENDP

                                END

This does indeed produce a real function as the following output from dumpbin.exe shows:

Code: [Select]
File Type: COFF OBJECT

MyProc:
  0000000000000000: 55                 push        rbp
  0000000000000001: 48 8B EC           mov         rbp,rsp
  0000000000000004: C9                 leave
  0000000000000005: C3                 ret

Here is the listing from HJWasm:

Code: [Select]
= MyProc PROC param1:DWORD,    tempvar TEXTEQU <MyProc PROC param1:DWORD,>

                                MyMacro MACRO
 >                              tempvar
 >                              EXITM
 >                              ENDM

                                .CODE

                                MyMacro
00000000                     1  MyProc PROC param1:DWORD,EXITM
                           Error A2209: Syntax error: EXITM

00000000                                ret

00000001                        MyProc ENDP

                                END

Would appreciate it if you could take a look. Thanks in advance.

habran

  • Member
  • *****
  • Posts: 1225
    • uasm
Thanks dawnraider, it'll be fixed in next release :biggrin:
Cod-Father

habran

  • Member
  • *****
  • Posts: 1225
    • uasm
Hi dawnraider,
Sorry for taking so long, I was very bussy with the 2.16 release :dazzled:

The problem was caused with comma in :
tempvar TEXTEQU <MyProc PROC  param1:DWORD,>

When I removed "," everything worked.
So, HJWasm tuk EXITM as parameter to the function because of the comma.
ML64 disregarded it for some unknown reason???

Anyway, here is the listing:
Code: [Select]
                                .x64
                                option casemap:none
 = MyProc PROC  param1:DWORD    tempvar TEXTEQU <MyProc PROC  param1:DWORD>

                                MyMacro MACRO
 >                              tempvar
 >                              EXITM
 >                              ENDM

                                .CODE

                                MyMacro
00000000                     1  MyProc PROC  param1:DWORD
00000004                        ret
00000006                        MyProc ENDP
                                END

However, I wouldn't recommend that kind of programming.
IMHO, The function should show clearly which parameters are used in it

 
Cod-Father

dawnraider

  • Regular Member
  • *
  • Posts: 26
Hi Habran,

I think you have misinterpreted the reason for the bug report.

The problem is that comma is a continuation character in MASM and HJWasm is not interpreting it correctly when it appears within
a macro.

I have macros which build the arguments to some functions automatically depending on the context. That's why in the example
the function prototype was a string. The comma continues the prototype onto the next line which, if blank, should do nothing.

I admit, I did find this bug in HJWasm by accident as my code was not functioning properly. However, this is how MASM works and
it makes perfect sense. The problem is not in how the prototype was written. The problem is in the macro processing as HJWasm
is processing a comma continuation character as macro input when in fact it is clearly meant for the assembler.

This, in my opinion, is a bug.

Cheers.

johnsa

  • Member
  • ****
  • Posts: 810
    • Uasm

I would agree that it is a bug, however it's one based on a bit of an ambiguous or suspect use-case.

the EXITM should always terminate the macro no matter what is happening, so i think as a fix specifically for this case we could force EXITM to terminate any current macro even if the assembler is busy expanding some other construct.

I think the reason these issues happen is that masm runs multi-pass over macros and hjwasm recursively expands .. so the behaviour is slightly different.

Once again i would suggest a work-around by building up your argument list to the proc or proto then using a macro string op to just remove the final comma so it can be built up dynamically and would exist on a single line. This should be compatible with both masm and hjwasm.