Author Topic: Invoke macro reading prototypes  (Read 2292 times)

HSE

  • Member
  • *****
  • Posts: 2497
  • AMD 7-32 / i3 10-64
Invoke macro reading prototypes
« on: May 05, 2021, 06:15:42 AM »
Hi All!

This is an update of Invoke macro for ML64 that can read prototypes to detect errors in type and number of arguments and allow or not to promotion.

H2incX @DefProto macro is used for still undeclared procs and a more simple macro @DefProtoE for procs already declared in Hutch's includes:
Code: [Select]
    @DefProtoE macro ApiQual, ProcName, CallConv, NameSuffix, Params, DecorSuffix
      ifdif <CallConv>, <vectorcall>
        ??CallConv equ <fastcall>
      else
        ??CallConv equ <&CallConv>
      endif

      ifndef __JWASM__
      ProcName&ProtoConv equ <??CallConv>
      ProcName&ProtoParams textequ <&Params>
      endif
    endm

@DefProtoE DllImport, fptoa, WIN_STD_CALL_CONV,,<:REAL8,:QWORD>
@DefProtoE DllImport, vc__i64toa, WIN_STD_CALL_CONV,, <:SQWORD, :PTR SBYTE, :SDWORD>
@DefProtoE DllImport, __imp_sprintf, WIN_STD_CALL_CONV,, <:VARARG>, 4
@DefProtoE DllImport, ExitProcess, WIN_STD_CALL_CONV,, <:UINT>, 4


You can see it's no so automatic to write proc name because can be expanded or not. Because in the example Invoke is forced to expansion vc_sprintf don't work and must be __imp_sprintf.

Variable AllowPromotions can be TRUE or FALSE and control promotions. If FALSE you have to manually convert for example a BYTE in QWORD, if function is Unprototyped or Vararg. If TRUE that is maked by Invoke macro.

Obviously is just a beginning  :biggrin:

First test (testxmm64) show if Invoke still work, and also VARARG. Here you can see what happen if you change AllowPromotions to FALSE.

Second test (Hutch2) show some error detections already working:
Code: [Select]
hutch2.asm(163) : error A2052:forced error :  Too many arguments (>2)

hutch2.asm(164) : error A2052:forced error : Argument for rcx is incorrect

hutch2.asm(164) : error A2052:forced error : Argument for rdx is incorrect

hutch2.asm(168) : error A2052:forced error : Argument (1) is missing
Equations in Assembly: SmplMath

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: Invoke macro reading prototypes
« Reply #1 on: May 05, 2021, 08:31:42 AM »
Congrats, Hector :thumbsup:

My Dual 64- and 32-bit Assembly package works, too, but I am in the process of generating the args info directly from the GCC headers, and currently a little bit stuck - too little time, too much distraction. We'll see :biggrin:

HSE

  • Member
  • *****
  • Posts: 2497
  • AMD 7-32 / i3 10-64
Re: Invoke macro reading prototypes
« Reply #2 on: May 05, 2021, 09:41:23 AM »
but I am in the process of generating the args info directly from the GCC headers
:biggrin: Another includes!   Well... Good luck  :thumbsup:
Equations in Assembly: SmplMath

LiaoMi

  • Member
  • *****
  • Posts: 1055
Re: Invoke macro reading prototypes
« Reply #3 on: May 05, 2021, 11:28:38 PM »
Congrats, Hector :thumbsup:

My Dual 64- and 32-bit Assembly package works, too, but I am in the process of generating the args info directly from the GCC headers, and currently a little bit stuck - too little time, too much distraction. We'll see :biggrin:

Hi jj2007,

your experience can be transferred to the creation of UASM SDK for Linux :tongue: