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, arrHdrSize, fixedItblSize, pprSMRep
15 #ifndef OMIT_NATIVE_CODEGEN
16 , getSMRepClosureTypeInt
48 #include "HsVersions.h"
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 )
57 import GlaExts ( Int(..), Int#, (<#), (==#), (<#), (>#) )
60 %************************************************************************
62 \subsubsection[SMRep-datatype]{@SMRep@---storage manager representation}
64 %************************************************************************
68 -- static closure have an extra static link field at the end.
70 Int -- # ptr words (useful for interpreter, debugger, etc)
71 Int -- # non-ptr words
72 ClosureType -- closure type
74 | GenericRep -- GC routines consult sizes in info tbl
76 Int -- # non-ptr words
77 ClosureType -- closure type
79 | ConstantRep -- CONSTR with zero-arity
96 Size of a closure header.
99 fixedHdrSize :: Int{-words-}
100 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize + tickyHdrSize
102 profHdrSize :: Int{-words-}
103 profHdrSize | opt_SccProfilingOn = pROF_HDR_SIZE
106 granHdrSize :: Int{-words-}
107 granHdrSize | opt_GranMacros = gRAN_HDR_SIZE
110 tickyHdrSize :: Int{-words-}
111 tickyHdrSize | opt_DoTickyProfiling = tICKY_HDR_SIZE
114 arrHdrSize :: Int{-words-}
115 arrHdrSize = fixedHdrSize + aRR_HDR_SIZE
118 Size of an info table.
121 fixedItblSize :: Int{-words-}
122 fixedItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
124 profItblSize :: Int{-words-}
125 profItblSize | opt_SccProfilingOn = pROF_ITBL_SIZE
128 granItblSize :: Int{-words-}
129 granItblSize | opt_GranMacros = gRAN_ITBL_SIZE
132 tickyItblSize :: Int{-words-}
133 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
138 isConstantRep, isStaticRep :: SMRep -> Bool
139 isConstantRep ConstantRep = True
140 isConstantRep other = False
142 isStaticRep (StaticRep _ _ _) = True
143 isStaticRep _ = False
148 instance Text SMRep where
150 = showString (case rep of
151 StaticRep _ _ _ -> "STATIC"
152 GenericRep _ _ _ -> ""
155 instance Outputable SMRep where
156 ppr rep = pprSMRep rep
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")
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")
173 #ifndef OMIT_NATIVE_CODEGEN
174 getSMRepClosureTypeInt :: SMRep -> Int
175 getSMRepClosureTypeInt (GenericRep _ _ t) =
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"
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
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) =
199 CONSTR -> cONSTR_STATIC
200 CONSTR_NOCAF -> cONSTR_NOCAF_STATIC
202 THUNK -> tHUNK_STATIC
203 THUNK_SELECTOR -> panic "getClosureTypeInt: THUNK_SELECTOR_STATIC"
205 getSMRepClosureTypeInt ConstantRep = cONSTR_NOCAF_STATIC
207 getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE
209 -- Just the ones we need:
211 #include "../includes/ClosureTypes.h"
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)
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)
242 #endif OMIT_NATIVE_CODEGEN