www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D's calling convention

reply Kevin VR <azra pandora.be> writes:
Hello,

D has the ability to assign specific calling conventions to each 
function by using "extern(<convention>)".

Which conventions are actually supported?
I know at least 2:
extern(C)	-> cdecl?
extern(Windows)	-> stdcall?

More importantly, which is the default calling convention for D?

Also, a little side question,
is there a way to have the DMD compiler output it's generated assembler 
code? (like the -S option on gcc)

thanks,
Kevin
Apr 30 2005
parent reply John Reimer <brk_6502 yahoo.com> writes:
Kevin VR wrote:
 Hello,
 
 D has the ability to assign specific calling conventions to each 
 function by using "extern(<convention>)".
 
 Which conventions are actually supported?
 I know at least 2:
 extern(C)    -> cdecl?
 extern(Windows)    -> stdcall?
 More importantly, which is the default calling convention for D?

D uses it's own calling convention: extern(D). It's disimilar to either of the above, specifically in name mangling format.
 Also, a little side question,
 is there a way to have the DMD compiler output it's generated assembler 
 code? (like the -S option on gcc)

obj2asm is included with dmd's linux distribution, which should work on any d object file. The same tool is also available for win32, but, strangely, it doesn't look like Walter includes it with the basic dmd distribution. You have to purchase the extended utilities package for $15 to get it. -JJR
Apr 30 2005
parent reply Kevin VR <azra pandora.be> writes:
 Kevin VR wrote:
 
 Hello,

 D has the ability to assign specific calling conventions to each 
 function by using "extern(<convention>)".

 Which conventions are actually supported?
 I know at least 2:
 extern(C)    -> cdecl?
 extern(Windows)    -> stdcall?
 More importantly, which is the default calling convention for D?


Just for someone else who might be interested in this: I have discovered that the D compiler supports D, C, C++, Pascal and Windows as calling conventions.
 D uses it's own calling convention: extern(D).  It's disimilar to either 
  of the above, specifically in name mangling format.

Can you point me to some reference where I can review the specific details of it? I have discovered by examining the .o files that D seems to push its parameters on the stack, except for the last one which seems to be put in the EAX register. I'm not an expert in this kind of stuff though, so I would like to see some kind of documentation about it. I have searched the site and google, but found nothing usefull yet.
 Also, a little side question,
 is there a way to have the DMD compiler output it's generated 
 assembler code? (like the -S option on gcc)

obj2asm is included with dmd's linux distribution, which should work on any d object file. The same tool is also available for win32, but, strangely, it doesn't look like Walter includes it with the basic dmd distribution. You have to purchase the extended utilities package for $15 to get it.

Thanks, this is a very nice tool. I use it on Linux!
May 03 2005
next sibling parent pragma <pragma_member pathlink.com> writes:
In article <d58a9f$2k8q$1 digitaldaemon.com>, Kevin VR says...

Can you point me to some reference where I can review the specific 

I have discovered by examining the .o files that D seems to push its parameters on the stack, except for the last one which seems to be put in the EAX register. I'm not an expert in this kind of stuff though, so I would like to see some kind of documentation about it. I have searched the site and google, but found nothing usefull yet.

From what I know, you're right on the money about D's calling convention. The return value also seems to be EAX (although I'm not sure what happens when you return a struct). The D webpage is supposed to have this kind of documentation, but I think it's very much a work-in-progress like everything else: http://www.digitalmars.com/d/abi.html If you don't get any feedback here from Walter, I'd reccomend either emailing him or adding your findings to the D wiki's doc commments under the ABI (application binary interface). http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/ABI - EricAnderton at yahoo
May 03 2005
prev sibling parent John Reimer <brk_6502 yahoo.com> writes:
Kevin VR wrote:

 D uses it's own calling convention: extern(D).  It's disimilar to 
 either  of the above, specifically in name mangling format.

Can you point me to some reference where I can review the specific details of it? I have discovered by examining the .o files that D seems to push its parameters on the stack, except for the last one which seems to be put in the EAX register. I'm not an expert in this kind of stuff though, so I would like to see some kind of documentation about it. I have searched the site and google, but found nothing usefull yet.

I'm not quite sure what the details are on the calling convention nor where to find it. :-( Personal investigation has led me to believe that D uses a very similar calling convention to either extern(C) or extern(Windows) (can't remember which one)... it seems that the D name mangling is the only obvious difference. I could be wrong.
 Also, a little side question,
 is there a way to have the DMD compiler output it's generated 
 assembler code? (like the -S option on gcc)

obj2asm is included with dmd's linux distribution, which should work on any d object file. The same tool is also available for win32, but, strangely, it doesn't look like Walter includes it with the basic dmd distribution. You have to purchase the extended utilities package for $15 to get it.

Thanks, this is a very nice tool. I use it on Linux!

Linux :-). things seem to be a lot more straightforward on that platform when it comes to programming. -JJR
May 03 2005