2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[SMRep]{Storage manager representations of closure}
6 This is here, rather than in ClosureInfo, just to keep nhc happy.
7 Other modules should access this info through ClosureInfo.
11 SMRep(..), ClosureType(..),
12 isConstantRep, isStaticRep,
13 fixedHdrSize, arrWordsHdrSize, arrPtrsHdrSize,
14 fixedItblSize, pprSMRep
16 #ifndef OMIT_NATIVE_CODEGEN
17 , getSMRepClosureTypeInt
49 #include "HsVersions.h"
52 import AbsCSyn ( Liveness(..) )
53 import Constants ( sTD_HDR_SIZE, pROF_HDR_SIZE,
54 gRAN_HDR_SIZE, tICKY_HDR_SIZE,
55 aRR_WORDS_HDR_SIZE, aRR_PTRS_HDR_SIZE,
56 sTD_ITBL_SIZE, pROF_ITBL_SIZE,
57 gRAN_ITBL_SIZE, tICKY_ITBL_SIZE )
59 import GlaExts ( Int(..), Int#, (<#), (==#), (<#), (>#) )
62 %************************************************************************
64 \subsubsection[SMRep-datatype]{@SMRep@---storage manager representation}
66 %************************************************************************
70 -- static closure have an extra static link field at the end.
72 Int -- # ptr words (useful for interpreter, debugger, etc)
73 Int -- # non-ptr words
74 ClosureType -- closure type
76 | GenericRep -- GC routines consult sizes in info tbl
78 Int -- # non-ptr words
79 ClosureType -- closure type
81 | ConstantRep -- CONSTR with zero-arity
98 Size of a closure header.
101 fixedHdrSize :: Int{-words-}
102 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize + tickyHdrSize
104 profHdrSize :: Int{-words-}
105 profHdrSize | opt_SccProfilingOn = pROF_HDR_SIZE
108 granHdrSize :: Int{-words-}
109 granHdrSize | opt_GranMacros = gRAN_HDR_SIZE
112 tickyHdrSize :: Int{-words-}
113 tickyHdrSize | opt_DoTickyProfiling = tICKY_HDR_SIZE
116 arrWordsHdrSize :: Int{-words-}
117 arrWordsHdrSize = fixedHdrSize + aRR_WORDS_HDR_SIZE
119 arrPtrsHdrSize :: Int{-words-}
120 arrPtrsHdrSize = fixedHdrSize + aRR_PTRS_HDR_SIZE
123 Size of an info table.
126 fixedItblSize :: Int{-words-}
127 fixedItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
129 profItblSize :: Int{-words-}
130 profItblSize | opt_SccProfilingOn = pROF_ITBL_SIZE
133 granItblSize :: Int{-words-}
134 granItblSize | opt_GranMacros = gRAN_ITBL_SIZE
137 tickyItblSize :: Int{-words-}
138 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
143 isConstantRep, isStaticRep :: SMRep -> Bool
144 isConstantRep ConstantRep = True
145 isConstantRep other = False
147 isStaticRep (StaticRep _ _ _) = True
148 isStaticRep _ = False
153 instance Text SMRep where
155 = showString (case rep of
156 StaticRep _ _ _ -> "STATIC"
157 GenericRep _ _ _ -> ""
160 instance Outputable SMRep where
161 ppr rep = pprSMRep rep
163 pprSMRep :: SMRep -> SDoc
164 pprSMRep (GenericRep _ _ t) = pprClosureType t
165 pprSMRep (StaticRep _ _ t) = pprClosureType t <> ptext SLIT("_STATIC")
166 pprSMRep ConstantRep = ptext SLIT("CONSTR_NOCAF_STATIC")
167 pprSMRep BlackHoleRep = ptext SLIT("BLACKHOLE")
169 pprClosureType CONSTR = ptext SLIT("CONSTR")
170 pprClosureType (CONSTR_p_n p n) = ptext SLIT("CONSTR_") <> int p <> char '_' <> int n
171 pprClosureType CONSTR_NOCAF = ptext SLIT("CONSTR_NOCAF")
172 pprClosureType FUN = ptext SLIT("FUN")
173 pprClosureType (FUN_p_n p n) = ptext SLIT("FUN_") <> int p <> char '_' <> int n
174 pprClosureType THUNK = ptext SLIT("THUNK")
175 pprClosureType (THUNK_p_n p n) = ptext SLIT("THUNK_") <> int p <> char '_' <> int n
176 pprClosureType THUNK_SELECTOR = ptext SLIT("THUNK_SELECTOR")
178 #ifndef OMIT_NATIVE_CODEGEN
179 getSMRepClosureTypeInt :: SMRep -> Int
180 getSMRepClosureTypeInt (GenericRep _ _ t) =
183 CONSTR_p_n 1 0 -> cONSTR_1_0
184 CONSTR_p_n 0 1 -> cONSTR_0_1
185 CONSTR_p_n 2 0 -> cONSTR_2_0
186 CONSTR_p_n 1 1 -> cONSTR_1_1
187 CONSTR_p_n 0 2 -> cONSTR_0_2
188 CONSTR_NOCAF -> panic "getClosureTypeInt: CONSTR_NOCAF"
190 FUN_p_n 1 0 -> fUN_1_0
191 FUN_p_n 0 1 -> fUN_0_1
192 FUN_p_n 2 0 -> fUN_2_0
193 FUN_p_n 1 1 -> fUN_1_1
194 FUN_p_n 0 2 -> fUN_0_2
196 THUNK_p_n 1 0 -> tHUNK_1_0
197 THUNK_p_n 0 1 -> tHUNK_0_1
198 THUNK_p_n 2 0 -> tHUNK_2_0
199 THUNK_p_n 1 1 -> tHUNK_1_1
200 THUNK_p_n 0 2 -> tHUNK_0_2
201 THUNK_SELECTOR -> tHUNK_SELECTOR
202 getSMRepClosureTypeInt (StaticRep _ _ t) =
204 CONSTR -> cONSTR_STATIC
205 CONSTR_NOCAF -> cONSTR_NOCAF_STATIC
207 THUNK -> tHUNK_STATIC
208 THUNK_SELECTOR -> panic "getClosureTypeInt: THUNK_SELECTOR_STATIC"
210 getSMRepClosureTypeInt ConstantRep = cONSTR_NOCAF_STATIC
212 getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE
214 -- Just the ones we need:
216 #include "../includes/ClosureTypes.h"
218 cONSTR = (CONSTR :: Int)
219 cONSTR_1_0 = (CONSTR_1_0 :: Int)
220 cONSTR_0_1 = (CONSTR_0_1 :: Int)
221 cONSTR_2_0 = (CONSTR_2_0 :: Int)
222 cONSTR_1_1 = (CONSTR_1_1 :: Int)
223 cONSTR_0_2 = (CONSTR_0_2 :: Int)
224 cONSTR_STATIC = (CONSTR_STATIC :: Int)
225 cONSTR_NOCAF_STATIC = (CONSTR_NOCAF_STATIC :: Int)
227 fUN_1_0 = (FUN_1_0 :: Int)
228 fUN_0_1 = (FUN_0_1 :: Int)
229 fUN_2_0 = (FUN_2_0 :: Int)
230 fUN_1_1 = (FUN_1_1 :: Int)
231 fUN_0_2 = (FUN_0_2 :: Int)
232 fUN_STATIC = (FUN_STATIC :: Int)
233 tHUNK = (THUNK :: Int)
234 tHUNK_1_0 = (THUNK_1_0 :: Int)
235 tHUNK_0_1 = (THUNK_0_1 :: Int)
236 tHUNK_2_0 = (THUNK_2_0 :: Int)
237 tHUNK_1_1 = (THUNK_1_1 :: Int)
238 tHUNK_0_2 = (THUNK_0_2 :: Int)
239 tHUNK_STATIC = (THUNK_STATIC :: Int)
240 tHUNK_SELECTOR = (THUNK_SELECTOR :: Int)
241 rET_SMALL = (RET_SMALL :: Int)
242 rET_VEC_SMALL = (RET_VEC_SMALL :: Int)
243 rET_BIG = (RET_BIG :: Int)
244 rET_VEC_BIG = (RET_VEC_BIG :: Int)
245 bLACKHOLE = (BLACKHOLE :: Int)
247 #endif OMIT_NATIVE_CODEGEN