2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[Calling conventions]{External calling conventions}
19 #include "HsVersions.h"
22 import PrimRep ( PrimRep, getPrimRepSizeInBytes )
28 pprCallConv :: CallConv -> SDoc
29 pprCallConv 0 = ptext SLIT("_stdcall")
30 pprCallConv _ = ptext SLIT("_ccall")
32 stdCallConv :: CallConv
38 defaultCallConv :: CallConv
39 defaultCallConv = cCallConv
42 Generate the gcc attribute corresponding to the given
43 calling convention (used by PprAbsC):
45 ToDo: The stdcall calling convention is x86 (win32) specific,
46 so perhaps we should emit a warning if it's being used on other
50 callConvAttribute :: CallConv -> String
52 | cc == stdCallConv = "__attribute__((stdcall))"
53 | cc == cCallConv = ""
54 | otherwise = panic ("callConvAttribute: cannot handle" ++ showSDoc (pprCallConv cc))
58 For stdcall and Win32, the linker expects to see names of the form
62 where n is the size (in 8-bit bytes) of the parameter area
63 that is pushed onto the stack before invocation. We take
64 care of mangling the function name here.
66 This name mangler is only used by the x86 native code generator.
69 decorateExtName :: CallConv -> FAST_STRING -> [PrimRep] -> FAST_STRING
70 decorateExtName cc fs ps
71 {- ifdef COMPILING_WIN32 -}
72 | cc /= stdCallConv = fs
73 | otherwise = fs _APPEND_ (_PK_ ('@':show (size::Int)))
78 size = sum (map (adjustParamSize.getPrimRepSizeInBytes) ps)
80 adjustParamSize sz = paramBoundary * ((sz + paramBoundary - 1) `div` paramBoundary)