Recent

Author Topic: Does Lazarus support thiscall and fastcall calling conventions?  (Read 6055 times)

gonz0

  • New Member
  • *
  • Posts: 15
I couldn't find anything specific via forums search / google.

I know it supports register-call (by default), cdecl, safecall and stdcall.

But what about thiscall and fastcall?

Thanks in advance :)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Does Lazarus support thiscall and fastcall calling conventions?
« Reply #1 on: August 30, 2015, 01:09:24 am »
No.  The default convention "register" is serves the function of fastcall in FPC/Delphi

gonz0

  • New Member
  • *
  • Posts: 15
Re: Does Lazarus support thiscall and fastcall calling conventions?
« Reply #2 on: August 30, 2015, 03:49:18 am »
Thanks for your fast anwswer.

Is there any way to "define" a thiscall calling convention.

At the moment i am adding "fake" parameters and switch the arguments so it works - which isn't "nice" but functional.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Does Lazarus support thiscall and fastcall calling conventions?
« Reply #3 on: August 31, 2015, 01:52:55 am »
Is there any way to "define" a thiscall calling convention.
Tweak the compiler to support it. However, which thiscall do you refer to? GCC and MSVC doesn't seem to agree on how it should be implemented, such a weird spec for a calling convention.

gonz0

  • New Member
  • *
  • Posts: 15
Re: Does Lazarus support thiscall and fastcall calling conventions?
« Reply #4 on: August 31, 2015, 08:45:18 am »
Is there any way to "define" a thiscall calling convention.
Tweak the compiler to support it. However, which thiscall do you refer to? GCC and MSVC doesn't seem to agree on how it should be implemented, such a weird spec for a calling convention.

I would in both cases implement MSVC calling convention:

thiscall (ecx) and fastcall (ecx, edx) in parameters.

How would one tweak the compiler? Couldn't find anything with forums search so i feat it is beyond my skill level.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Does Lazarus support thiscall and fastcall calling conventions?
« Reply #5 on: August 31, 2015, 08:51:18 am »
How would one tweak the compiler? Couldn't find anything with forums search so i feat it is beyond my skill level.
Get the source, study and modify it yourself. You can also offer bounties and hope for some people to get interested and implement. Welcome to open source development model.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Does Lazarus support thiscall and fastcall calling conventions?
« Reply #6 on: August 31, 2015, 10:11:32 am »
Calling conventions are a lot of pain. If it is for a few functions it is often easier to just have some C wrapper code declared with stdcall that calls the thiscall method.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Does Lazarus support thiscall and fastcall calling conventions?
« Reply #7 on: August 31, 2015, 10:54:09 am »
Also note that it would be only for 32 bit Windows and even only for 32 i386 Windows.
If I need to interface with that kind of code I use small Basm stubs that massage the registers into place.
Under 64 bit (and ARM) these conventions are either ignored or generate an error.
The GCC fastcall has a little more merit to be implemented, I believe.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018