[project @ 2001-05-22 13:22:14 by simonmar]
[ghc-hetmet.git] / ghc / compiler / absCSyn / CallConv.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
3 %
4 \section[Calling conventions]{External calling conventions}
5
6 \begin{code}
7 module CallConv
8        (
9          CallConv
10        , pprCallConv
11        , callConvToInt
12
13        , stdCallConv
14        , cCallConv
15        , defaultCallConv
16        , callConvAttribute
17        ) where
18
19 #include "HsVersions.h"
20
21 import Outputable
22 import PrimRep     ( PrimRep, getPrimRepSizeInBytes )
23 \end{code}
24
25 \begin{code}
26 type CallConv = Int
27
28 pprCallConv :: CallConv -> SDoc
29 pprCallConv 0 = ptext SLIT("__stdcall")
30 pprCallConv _ = ptext SLIT("_ccall")
31
32 stdCallConv :: CallConv
33 stdCallConv = 0
34
35 cCallConv  :: CallConv
36 cCallConv = 1
37
38 defaultCallConv :: CallConv
39 defaultCallConv = cCallConv
40
41 callConvToInt :: CallConv -> Int
42 callConvToInt x = x
43 \end{code}
44
45 Generate the gcc attribute corresponding to the given
46 calling convention (used by PprAbsC):
47
48 ToDo: The stdcall calling convention is x86 (win32) specific,
49 so perhaps we should emit a warning if it's being used on other
50 platforms.
51
52 \begin{code}
53 callConvAttribute :: CallConv -> String
54 callConvAttribute cc
55  | cc == stdCallConv   = "__stdcall"
56  | cc == cCallConv     = ""
57  | otherwise           = panic ("callConvAttribute: cannot handle" ++ showSDoc (pprCallConv cc))
58
59 \end{code}