[project @ 1999-03-01 17:41:21 by simonm]
[ghc-hetmet.git] / ghc / compiler / codeGen / SMRep.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[SMRep]{Storage manager representations of closure}
5
6 This is here, rather than in ClosureInfo, just to keep nhc happy.
7 Other modules should access this info through ClosureInfo.
8
9 \begin{code}
10 module SMRep (
11         SMRep(..), ClosureType(..),
12         isConstantRep, isStaticRep,
13         fixedHdrSize, arrHdrSize, fixedItblSize, pprSMRep
14
15 #ifndef OMIT_NATIVE_CODEGEN
16         , getSMRepClosureTypeInt
17         , cONSTR
18         , cONSTR_1_0
19         , cONSTR_0_1
20         , cONSTR_2_0
21         , cONSTR_1_1
22         , cONSTR_0_2
23         , cONSTR_STATIC
24         , cONSTR_NOCAF_STATIC
25         , fUN
26         , fUN_1_0
27         , fUN_0_1
28         , fUN_2_0
29         , fUN_1_1
30         , fUN_0_2
31         , fUN_STATIC
32         , tHUNK
33         , tHUNK_1_0
34         , tHUNK_0_1
35         , tHUNK_2_0
36         , tHUNK_1_1
37         , tHUNK_0_2
38         , tHUNK_STATIC
39         , tHUNK_SELECTOR
40         , rET_SMALL
41         , rET_VEC_SMALL
42         , rET_BIG
43         , rET_VEC_BIG
44         , bLACKHOLE
45 #endif
46     ) where
47
48 #include "HsVersions.h"
49
50 import CmdLineOpts
51 import AbsCSyn          ( Liveness(..) )
52 import Constants        ( sTD_HDR_SIZE, pROF_HDR_SIZE,
53                           gRAN_HDR_SIZE, tICKY_HDR_SIZE, aRR_HDR_SIZE,
54                           sTD_ITBL_SIZE, pROF_ITBL_SIZE,
55                           gRAN_ITBL_SIZE, tICKY_ITBL_SIZE )
56 import Outputable
57 import GlaExts          ( Int(..), Int#, (<#), (==#), (<#), (>#) )
58 \end{code}
59
60 %************************************************************************
61 %*                                                                      *
62 \subsubsection[SMRep-datatype]{@SMRep@---storage manager representation}
63 %*                                                                      *
64 %************************************************************************
65
66 \begin{code}
67 data SMRep
68      -- static closure have an extra static link field at the end.
69   = StaticRep
70         Int             -- # ptr words (useful for interpreter, debugger, etc)
71         Int             -- # non-ptr words
72         ClosureType     -- closure type
73
74   | GenericRep          -- GC routines consult sizes in info tbl
75         Int             -- # ptr words
76         Int             -- # non-ptr words
77         ClosureType     -- closure type
78
79   | ConstantRep         -- CONSTR with zero-arity
80
81   | BlackHoleRep
82
83 data ClosureType
84     = CONSTR
85     | CONSTR_p_n Int Int
86     | CONSTR_NOCAF
87     | FUN
88     | FUN_p_n Int Int
89     | THUNK
90     | THUNK_p_n Int Int
91     | THUNK_SELECTOR
92   deriving (Eq,Ord)
93
94 \end{code}
95
96 Size of a closure header.
97
98 \begin{code}
99 fixedHdrSize :: Int{-words-}
100 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize + tickyHdrSize
101
102 profHdrSize  :: Int{-words-}
103 profHdrSize  | opt_SccProfilingOn   = pROF_HDR_SIZE
104              | otherwise            = 0
105
106 granHdrSize  :: Int{-words-}
107 granHdrSize  | opt_GranMacros       = gRAN_HDR_SIZE
108              | otherwise            = 0
109
110 tickyHdrSize :: Int{-words-}
111 tickyHdrSize | opt_DoTickyProfiling = tICKY_HDR_SIZE
112              | otherwise            = 0
113
114 arrHdrSize   :: Int{-words-}
115 arrHdrSize   = fixedHdrSize + aRR_HDR_SIZE
116 \end{code}
117
118 Size of an info table.
119
120 \begin{code}
121 fixedItblSize :: Int{-words-}
122 fixedItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
123
124 profItblSize  :: Int{-words-}
125 profItblSize  | opt_SccProfilingOn   = pROF_ITBL_SIZE
126               | otherwise           = 0
127
128 granItblSize  :: Int{-words-}
129 granItblSize  | opt_GranMacros      = gRAN_ITBL_SIZE
130               | otherwise           = 0
131
132 tickyItblSize :: Int{-words-}
133 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
134               | otherwise           = 0
135 \end{code}
136
137 \begin{code}
138 isConstantRep, isStaticRep :: SMRep -> Bool
139 isConstantRep ConstantRep     = True
140 isConstantRep other           = False
141
142 isStaticRep (StaticRep _ _ _) = True
143 isStaticRep _                 = False
144 \end{code}
145
146 \begin{code}
147 {- ToDo: needed? -}
148 instance Text SMRep where
149     showsPrec d rep
150       = showString (case rep of
151            StaticRep _ _ _                       -> "STATIC"
152            GenericRep _ _ _                      -> ""
153            ConstantRep                           -> "")
154
155 instance Outputable SMRep where
156     ppr rep = pprSMRep rep
157
158 pprSMRep :: SMRep -> SDoc
159 pprSMRep (GenericRep _ _ t)     = pprClosureType t
160 pprSMRep (StaticRep _ _ t)      = pprClosureType t <> ptext SLIT("_STATIC")
161 pprSMRep ConstantRep            = ptext SLIT("CONSTR_NOCAF_STATIC")
162 pprSMRep BlackHoleRep           = ptext SLIT("BLACKHOLE")
163
164 pprClosureType CONSTR           = ptext SLIT("CONSTR")
165 pprClosureType (CONSTR_p_n p n) = ptext SLIT("CONSTR_") <> int p <> char '_' <> int n
166 pprClosureType CONSTR_NOCAF     = ptext SLIT("CONSTR_NOCAF")
167 pprClosureType FUN              = ptext SLIT("FUN")
168 pprClosureType (FUN_p_n p n)    = ptext SLIT("FUN_") <> int p <> char '_' <> int n
169 pprClosureType THUNK            = ptext SLIT("THUNK")
170 pprClosureType (THUNK_p_n p n)  = ptext SLIT("THUNK_") <> int p <> char '_' <> int n
171 pprClosureType THUNK_SELECTOR   = ptext SLIT("THUNK_SELECTOR")
172
173 #ifndef OMIT_NATIVE_CODEGEN
174 getSMRepClosureTypeInt :: SMRep -> Int
175 getSMRepClosureTypeInt (GenericRep _ _ t) =
176   case t of
177     CONSTR         -> cONSTR
178     CONSTR_p_n 1 0 -> cONSTR_1_0
179     CONSTR_p_n 0 1 -> cONSTR_0_1
180     CONSTR_p_n 2 0 -> cONSTR_2_0
181     CONSTR_p_n 1 1 -> cONSTR_1_1
182     CONSTR_p_n 0 2 -> cONSTR_0_2
183     CONSTR_NOCAF   -> panic "getClosureTypeInt: CONSTR_NOCAF"
184     FUN            -> fUN
185     FUN_p_n 1 0    -> fUN_1_0
186     FUN_p_n 0 1    -> fUN_0_1
187     FUN_p_n 2 0    -> fUN_2_0
188     FUN_p_n 1 1    -> fUN_1_1
189     FUN_p_n 0 2    -> fUN_0_2
190     THUNK          -> tHUNK
191     THUNK_p_n 1 0  -> tHUNK_1_0
192     THUNK_p_n 0 1  -> tHUNK_0_1
193     THUNK_p_n 2 0  -> tHUNK_2_0
194     THUNK_p_n 1 1  -> tHUNK_1_1
195     THUNK_p_n 0 2  -> tHUNK_0_2
196     THUNK_SELECTOR -> tHUNK_SELECTOR
197 getSMRepClosureTypeInt (StaticRep _ _ t) =
198   case t of
199     CONSTR         -> cONSTR_STATIC
200     CONSTR_NOCAF   -> cONSTR_NOCAF_STATIC
201     FUN            -> fUN_STATIC
202     THUNK          -> tHUNK_STATIC
203     THUNK_SELECTOR -> panic "getClosureTypeInt: THUNK_SELECTOR_STATIC"
204
205 getSMRepClosureTypeInt ConstantRep = cONSTR_NOCAF_STATIC
206
207 getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE
208
209 -- Just the ones we need:
210
211 #include "../includes/ClosureTypes.h"
212
213 cONSTR                  = (CONSTR               :: Int)
214 cONSTR_1_0              = (CONSTR_1_0           :: Int)
215 cONSTR_0_1              = (CONSTR_0_1           :: Int)
216 cONSTR_2_0              = (CONSTR_2_0           :: Int)
217 cONSTR_1_1              = (CONSTR_1_1           :: Int)
218 cONSTR_0_2              = (CONSTR_0_2           :: Int)
219 cONSTR_STATIC           = (CONSTR_STATIC        :: Int)
220 cONSTR_NOCAF_STATIC     = (CONSTR_NOCAF_STATIC  :: Int)
221 fUN                     = (FUN                  :: Int)
222 fUN_1_0                 = (FUN_1_0              :: Int)
223 fUN_0_1                 = (FUN_0_1              :: Int)
224 fUN_2_0                 = (FUN_2_0              :: Int)
225 fUN_1_1                 = (FUN_1_1              :: Int)
226 fUN_0_2                 = (FUN_0_2              :: Int)
227 fUN_STATIC              = (FUN_STATIC           :: Int)
228 tHUNK                   = (THUNK                :: Int)
229 tHUNK_1_0               = (THUNK_1_0            :: Int)
230 tHUNK_0_1               = (THUNK_0_1            :: Int)
231 tHUNK_2_0               = (THUNK_2_0            :: Int)
232 tHUNK_1_1               = (THUNK_1_1            :: Int)
233 tHUNK_0_2               = (THUNK_0_2            :: Int)
234 tHUNK_STATIC            = (THUNK_STATIC         :: Int)
235 tHUNK_SELECTOR          = (THUNK_SELECTOR       :: Int)
236 rET_SMALL               = (RET_SMALL            :: Int)
237 rET_VEC_SMALL           = (RET_VEC_SMALL        :: Int)
238 rET_BIG                 = (RET_BIG              :: Int)
239 rET_VEC_BIG             = (RET_VEC_BIG          :: Int)
240 bLACKHOLE               = (BLACKHOLE            :: Int)
241
242 #endif OMIT_NATIVE_CODEGEN
243 \end{code}