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