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
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
81 Size of a closure header.
84 fixedHdrSize :: Int{-words-}
85 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize + tickyHdrSize
87 profHdrSize :: Int{-words-}
88 profHdrSize | opt_SccProfilingOn = pROF_HDR_SIZE
91 granHdrSize :: Int{-words-}
92 granHdrSize | opt_GranMacros = gRAN_HDR_SIZE
95 tickyHdrSize :: Int{-words-}
96 tickyHdrSize | opt_DoTickyProfiling = tICKY_HDR_SIZE
99 arrHdrSize :: Int{-words-}
100 arrHdrSize = fixedHdrSize + aRR_HDR_SIZE
103 Size of an info table.
106 fixedItblSize :: Int{-words-}
107 fixedItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
109 profItblSize :: Int{-words-}
110 profItblSize | opt_SccProfilingOn = pROF_ITBL_SIZE
113 granItblSize :: Int{-words-}
114 granItblSize | opt_GranMacros = gRAN_ITBL_SIZE
117 tickyItblSize :: Int{-words-}
118 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
123 isConstantRep, isStaticRep :: SMRep -> Bool
124 isConstantRep ConstantRep = True
125 isConstantRep other = False
127 isStaticRep (StaticRep _ _ _) = True
128 isStaticRep _ = False
133 instance Text SMRep where
135 = showString (case rep of
136 StaticRep _ _ _ -> "STATIC"
137 GenericRep _ _ _ -> ""
140 instance Outputable SMRep where
141 ppr rep = pprSMRep rep
143 pprSMRep :: SMRep -> SDoc
144 pprSMRep (GenericRep _ _ t) = pprClosureType t
145 pprSMRep (StaticRep _ _ t) = pprClosureType t <> ptext SLIT("_STATIC")
146 pprSMRep ConstantRep = ptext SLIT("CONSTR_NOCAF_STATIC")
147 pprSMRep BlackHoleRep = ptext SLIT("BLACKHOLE")
149 pprClosureType CONSTR = ptext SLIT("CONSTR")
150 pprClosureType (CONSTR_p_n p n) = ptext SLIT("CONSTR_") <> int p <> char '_' <> int n
151 pprClosureType CONSTR_NOCAF = ptext SLIT("CONSTR_NOCAF")
152 pprClosureType FUN = ptext SLIT("FUN")
153 pprClosureType (FUN_p_n p n) = ptext SLIT("FUN_") <> int p <> char '_' <> int n
154 pprClosureType THUNK = ptext SLIT("THUNK")
155 pprClosureType (THUNK_p_n p n) = ptext SLIT("THUNK_") <> int p <> char '_' <> int n
156 pprClosureType THUNK_SELECTOR = ptext SLIT("THUNK_SELECTOR")
158 #ifndef OMIT_NATIVE_CODEGEN
159 getSMRepClosureTypeInt :: SMRep -> Int
160 getSMRepClosureTypeInt (GenericRep _ _ t) =
163 CONSTR_NOCAF -> panic "getClosureTypeInt: CONSTR_NOCAF"
166 THUNK_SELECTOR -> tHUNK_SELECTOR
167 getSMRepClosureTypeInt (StaticRep _ _ t) =
169 CONSTR -> cONSTR_STATIC
170 CONSTR_NOCAF -> cONSTR_NOCAF_STATIC
172 THUNK -> tHUNK_STATIC
173 THUNK_SELECTOR -> panic "getClosureTypeInt: THUNK_SELECTOR_STATIC"
175 getSMRepClosureTypeInt ConstantRep = cONSTR_NOCAF_STATIC
177 getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE
179 -- Just the ones we need:
181 #include "../includes/ClosureTypes.h"
183 cONSTR = (CONSTR :: Int)
184 cONSTR_STATIC = (CONSTR_STATIC :: Int)
185 cONSTR_NOCAF_STATIC = (CONSTR_NOCAF_STATIC :: Int)
187 fUN_STATIC = (FUN_STATIC :: Int)
188 tHUNK = (THUNK :: Int)
189 tHUNK_STATIC = (THUNK_STATIC :: Int)
190 tHUNK_SELECTOR = (THUNK_SELECTOR :: Int)
191 rET_SMALL = (RET_SMALL :: Int)
192 rET_VEC_SMALL = (RET_VEC_SMALL :: Int)
193 rET_BIG = (RET_BIG :: Int)
194 rET_VEC_BIG = (RET_VEC_BIG :: Int)
195 bLACKHOLE = (BLACKHOLE :: Int)
197 #endif OMIT_NATIVE_CODEGEN