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