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, getSMRepStr, getClosureTypeStr
15 #ifndef OMIT_NATIVE_CODEGEN
16 , getSMRepClosureTypeInt
33 #include "HsVersions.h"
36 import AbsCSyn ( Liveness(..) )
37 import Constants ( sTD_HDR_SIZE, pROF_HDR_SIZE,
38 gRAN_HDR_SIZE, tICKY_HDR_SIZE, aRR_HDR_SIZE,
39 sTD_ITBL_SIZE, pROF_ITBL_SIZE,
40 gRAN_ITBL_SIZE, tICKY_ITBL_SIZE )
43 import GlaExts ( Int(..), Int#, (<#), (==#), (<#), (>#) )
46 %************************************************************************
48 \subsubsection[SMRep-datatype]{@SMRep@---storage manager representation}
50 %************************************************************************
54 -- static closure have an extra static link field at the end.
56 Int -- # ptr words (useful for interpreter, debugger, etc)
57 Int -- # non-ptr words
58 ClosureType -- closure type
60 | GenericRep -- GC routines consult sizes in info tbl
62 Int -- # non-ptr words
63 ClosureType -- closure type
65 | ConstantRep -- CONSTR with zero-arity
79 Size of a closure header.
82 fixedHdrSize :: Int{-words-}
83 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize + tickyHdrSize
85 profHdrSize :: Int{-words-}
86 profHdrSize | opt_SccProfilingOn = pROF_HDR_SIZE
89 granHdrSize :: Int{-words-}
90 granHdrSize | opt_GranMacros = gRAN_HDR_SIZE
93 tickyHdrSize :: Int{-words-}
94 tickyHdrSize | opt_DoTickyProfiling = tICKY_HDR_SIZE
97 arrHdrSize :: Int{-words-}
98 arrHdrSize = fixedHdrSize + aRR_HDR_SIZE
101 Size of an info table.
104 fixedItblSize :: Int{-words-}
105 fixedItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
107 profItblSize :: Int{-words-}
108 profItblSize | opt_SccProfilingOn = pROF_ITBL_SIZE
111 granItblSize :: Int{-words-}
112 granItblSize | opt_GranMacros = gRAN_ITBL_SIZE
115 tickyItblSize :: Int{-words-}
116 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
121 isConstantRep, isStaticRep :: SMRep -> Bool
122 isConstantRep ConstantRep = True
123 isConstantRep other = False
125 isStaticRep (StaticRep _ _ _) = True
126 isStaticRep _ = False
131 instance Text SMRep where
133 = showString (case rep of
134 StaticRep _ _ _ -> "STATIC"
135 GenericRep _ _ _ -> ""
138 instance Outputable SMRep where
139 ppr rep = text (show rep)
141 getSMRepStr (GenericRep _ _ t) = getClosureTypeStr t
142 getSMRepStr (StaticRep _ _ t) = getClosureTypeStr t ++ "_STATIC"
143 getSMRepStr ConstantRep = "CONSTR_NOCAF_STATIC"
144 getSMRepStr BlackHoleRep = "BLACKHOLE"
146 getClosureTypeStr CONSTR = "CONSTR"
147 getClosureTypeStr CONSTR_NOCAF = "CONSTR_NOCAF"
148 getClosureTypeStr FUN = "FUN"
149 getClosureTypeStr THUNK = "THUNK"
150 getClosureTypeStr THUNK_SELECTOR = "THUNK_SELECTOR"
152 #ifndef OMIT_NATIVE_CODEGEN
153 getSMRepClosureTypeInt :: SMRep -> Int
154 getSMRepClosureTypeInt (GenericRep _ _ t) =
157 CONSTR_NOCAF -> panic "getClosureTypeInt: CONSTR_NOCAF"
160 THUNK_SELECTOR -> tHUNK_SELECTOR
161 getSMRepClosureTypeInt (StaticRep _ _ t) =
163 CONSTR -> cONSTR_STATIC
164 CONSTR_NOCAF -> cONSTR_NOCAF_STATIC
166 THUNK -> tHUNK_STATIC
167 THUNK_SELECTOR -> panic "getClosureTypeInt: THUNK_SELECTOR_STATIC"
169 getSMRepClosureTypeInt ConstantRep = cONSTR_NOCAF_STATIC
171 getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE
173 -- Just the ones we need:
175 #include "../includes/ClosureTypes.h"
177 cONSTR = (CONSTR :: Int)
178 cONSTR_STATIC = (CONSTR_STATIC :: Int)
179 cONSTR_NOCAF_STATIC = (CONSTR_NOCAF_STATIC :: Int)
181 fUN_STATIC = (FUN_STATIC :: Int)
182 tHUNK = (THUNK :: Int)
183 tHUNK_STATIC = (THUNK_STATIC :: Int)
184 tHUNK_SELECTOR = (THUNK_SELECTOR :: Int)
185 rET_SMALL = (RET_SMALL :: Int)
186 rET_VEC_SMALL = (RET_VEC_SMALL :: Int)
187 rET_BIG = (RET_BIG :: Int)
188 rET_VEC_BIG = (RET_VEC_BIG :: Int)
189 bLACKHOLE = (BLACKHOLE :: Int)
191 #endif OMIT_NATIVE_CODEGEN