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 )
42 import GlaExts ( Int(..), Int#, (<#), (==#), (<#), (>#) )
45 %************************************************************************
47 \subsubsection[SMRep-datatype]{@SMRep@---storage manager representation}
49 %************************************************************************
53 -- static closure have an extra static link field at the end.
55 Int -- # ptr words (useful for interpreter, debugger, etc)
56 Int -- # non-ptr words
57 ClosureType -- closure type
59 | GenericRep -- GC routines consult sizes in info tbl
61 Int -- # non-ptr words
62 ClosureType -- closure type
64 | ConstantRep -- CONSTR with zero-arity
78 Size of a closure header.
81 fixedHdrSize :: Int{-words-}
82 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize + tickyHdrSize
84 profHdrSize :: Int{-words-}
85 profHdrSize | opt_SccProfilingOn = pROF_HDR_SIZE
88 granHdrSize :: Int{-words-}
89 granHdrSize | opt_GranMacros = gRAN_HDR_SIZE
92 tickyHdrSize :: Int{-words-}
93 tickyHdrSize | opt_DoTickyProfiling = tICKY_HDR_SIZE
96 arrHdrSize :: Int{-words-}
97 arrHdrSize = fixedHdrSize + aRR_HDR_SIZE
100 Size of an info table.
103 fixedItblSize :: Int{-words-}
104 fixedItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
106 profItblSize :: Int{-words-}
107 profItblSize | opt_SccProfilingOn = pROF_ITBL_SIZE
110 granItblSize :: Int{-words-}
111 granItblSize | opt_GranMacros = gRAN_ITBL_SIZE
114 tickyItblSize :: Int{-words-}
115 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
120 isConstantRep, isStaticRep :: SMRep -> Bool
121 isConstantRep ConstantRep = True
122 isConstantRep other = False
124 isStaticRep (StaticRep _ _ _) = True
125 isStaticRep _ = False
130 instance Text SMRep where
132 = showString (case rep of
133 StaticRep _ _ _ -> "STATIC"
134 GenericRep _ _ _ -> ""
137 instance Outputable SMRep where
138 ppr rep = text (show rep)
140 getSMRepStr (GenericRep _ _ t) = getClosureTypeStr t
141 getSMRepStr (StaticRep _ _ t) = getClosureTypeStr t ++ "_STATIC"
142 getSMRepStr ConstantRep = "CONSTR_NOCAF_STATIC"
143 getSMRepStr BlackHoleRep = "BLACKHOLE"
145 getClosureTypeStr CONSTR = "CONSTR"
146 getClosureTypeStr CONSTR_NOCAF = "CONSTR_NOCAF"
147 getClosureTypeStr FUN = "FUN"
148 getClosureTypeStr THUNK = "THUNK"
149 getClosureTypeStr THUNK_SELECTOR = "THUNK_SELECTOR"
151 #ifndef OMIT_NATIVE_CODEGEN
152 getSMRepClosureTypeInt :: SMRep -> Int
153 getSMRepClosureTypeInt (GenericRep _ _ t) =
156 CONSTR_NOCAF -> panic "getClosureTypeInt: CONSTR_NOCAF"
159 THUNK_SELECTOR -> tHUNK_SELECTOR
160 getSMRepClosureTypeInt (StaticRep _ _ t) =
162 CONSTR -> cONSTR_STATIC
163 CONSTR_NOCAF -> cONSTR_NOCAF_STATIC
165 THUNK -> tHUNK_STATIC
166 THUNK_SELECTOR -> panic "getClosureTypeInt: THUNK_SELECTOR_STATIC"
168 getSMRepClosureTypeInt ConstantRep = cONSTR_NOCAF_STATIC
170 getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE
172 -- Just the ones we need:
174 #include "../includes/ClosureTypes.h"
176 cONSTR = (CONSTR :: Int)
177 cONSTR_STATIC = (CONSTR_STATIC :: Int)
178 cONSTR_NOCAF_STATIC = (CONSTR_NOCAF_STATIC :: Int)
180 fUN_STATIC = (FUN_STATIC :: Int)
181 tHUNK = (THUNK :: Int)
182 tHUNK_STATIC = (THUNK_STATIC :: Int)
183 tHUNK_SELECTOR = (THUNK_SELECTOR :: Int)
184 rET_SMALL = (RET_SMALL :: Int)
185 rET_VEC_SMALL = (RET_VEC_SMALL :: Int)
186 rET_BIG = (RET_BIG :: Int)
187 rET_VEC_BIG = (RET_VEC_BIG :: Int)
188 bLACKHOLE = (BLACKHOLE :: Int)
190 #endif OMIT_NATIVE_CODEGEN