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(..),
13 fixedHdrSize, arrWordsHdrSize, arrPtrsHdrSize,
14 fixedItblSize, pprSMRep
16 #ifndef OMIT_NATIVE_CODEGEN
17 , getSMRepClosureTypeInt
49 #include "HsVersions.h"
52 import Constants ( sTD_HDR_SIZE, pROF_HDR_SIZE,
53 gRAN_HDR_SIZE, tICKY_ITBL_SIZE,
54 aRR_WORDS_HDR_SIZE, aRR_PTRS_HDR_SIZE,
55 sTD_ITBL_SIZE, pROF_ITBL_SIZE,
60 %************************************************************************
62 \subsubsection[SMRep-datatype]{@SMRep@---storage manager representation}
64 %************************************************************************
68 -- static closure have an extra static link field at the end.
69 = GenericRep -- GC routines consult sizes in info tbl
70 Bool -- True <=> This is a static closure. Affects how
71 -- we garbage-collect it
73 Int -- # non-ptr words
74 ClosureType -- closure type
78 data ClosureType -- Corresponds 1-1 with the varieties of closures
79 -- implemented by the RTS. Compare with ghc/includes/ClosureTypes.h
81 | CONSTR_p_n -- The p_n variants have more efficient GC, but we
82 -- only provide them for dynamically-allocated closures
83 -- (We could do them for static ones, but we don't)
93 Size of a closure header.
96 fixedHdrSize :: Int{-words-}
97 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize
99 profHdrSize :: Int{-words-}
100 profHdrSize | opt_SccProfilingOn = pROF_HDR_SIZE
103 granHdrSize :: Int{-words-}
104 granHdrSize | opt_GranMacros = gRAN_HDR_SIZE
107 arrWordsHdrSize :: Int{-words-}
108 arrWordsHdrSize = fixedHdrSize + aRR_WORDS_HDR_SIZE
110 arrPtrsHdrSize :: Int{-words-}
111 arrPtrsHdrSize = fixedHdrSize + aRR_PTRS_HDR_SIZE
114 Size of an info table.
117 fixedItblSize :: Int{-words-}
118 fixedItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
120 profItblSize :: Int{-words-}
121 profItblSize | opt_SccProfilingOn = pROF_ITBL_SIZE
124 granItblSize :: Int{-words-}
125 granItblSize | opt_GranMacros = gRAN_ITBL_SIZE
128 tickyItblSize :: Int{-words-}
129 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
134 isStaticRep :: SMRep -> Bool
135 isStaticRep (GenericRep is_static _ _ _) = is_static
136 isStaticRep BlackHoleRep = False
140 instance Outputable SMRep where
141 ppr rep = pprSMRep rep
143 pprSMRep :: SMRep -> SDoc
144 pprSMRep (GenericRep True ptrs nptrs clo_ty) = pprClosureType clo_ty ptrs nptrs <> ptext SLIT("_STATIC")
145 pprSMRep (GenericRep False ptrs nptrs clo_ty) = pprClosureType clo_ty ptrs nptrs
147 pprClosureType CONSTR p n = ptext SLIT("CONSTR")
148 pprClosureType CONSTR_p_n p n = ptext SLIT("CONSTR_") <> int p <> char '_' <> int n
149 pprClosureType CONSTR_NOCAF p n = ptext SLIT("CONSTR_NOCAF")
150 pprClosureType FUN p n = ptext SLIT("FUN")
151 pprClosureType FUN_p_n p n = ptext SLIT("FUN_") <> int p <> char '_' <> int n
152 pprClosureType THUNK p n = ptext SLIT("THUNK")
153 pprClosureType THUNK_p_n p n = ptext SLIT("THUNK_") <> int p <> char '_' <> int n
154 pprClosureType THUNK_SELECTOR p n = ptext SLIT("THUNK_SELECTOR")
156 #ifndef OMIT_NATIVE_CODEGEN
157 getSMRepClosureTypeInt :: SMRep -> Int
158 getSMRepClosureTypeInt (GenericRep False _ _ CONSTR) = cONSTR
159 getSMRepClosureTypeInt (GenericRep False 1 0 CONSTR_p_n) = cONSTR_1_0
160 getSMRepClosureTypeInt (GenericRep False 0 1 CONSTR_p_n) = cONSTR_0_1
161 getSMRepClosureTypeInt (GenericRep False 2 0 CONSTR_p_n) = cONSTR_2_0
162 getSMRepClosureTypeInt (GenericRep False 1 1 CONSTR_p_n) = cONSTR_1_1
163 getSMRepClosureTypeInt (GenericRep False 0 2 CONSTR_p_n) = cONSTR_0_2
165 getSMRepClosureTypeInt (GenericRep False _ _ FUN) = fUN
166 getSMRepClosureTypeInt (GenericRep False 1 0 FUN_p_n) = fUN_1_0
167 getSMRepClosureTypeInt (GenericRep False 0 1 FUN_p_n) = fUN_0_1
168 getSMRepClosureTypeInt (GenericRep False 2 0 FUN_p_n) = fUN_2_0
169 getSMRepClosureTypeInt (GenericRep False 1 1 FUN_p_n) = fUN_1_1
170 getSMRepClosureTypeInt (GenericRep False 0 2 FUN_p_n) = fUN_0_2
172 getSMRepClosureTypeInt (GenericRep False _ _ THUNK) = tHUNK
173 getSMRepClosureTypeInt (GenericRep False 1 0 THUNK_p_n) = tHUNK_1_0
174 getSMRepClosureTypeInt (GenericRep False 0 1 THUNK_p_n) = tHUNK_0_1
175 getSMRepClosureTypeInt (GenericRep False 2 0 THUNK_p_n) = tHUNK_2_0
176 getSMRepClosureTypeInt (GenericRep False 1 1 THUNK_p_n) = tHUNK_1_1
177 getSMRepClosureTypeInt (GenericRep False 0 2 THUNK_p_n) = tHUNK_0_2
179 getSMRepClosureTypeInt (GenericRep False _ _ THUNK_SELECTOR) = tHUNK_SELECTOR
181 getSMRepClosureTypeInt (GenericRep True _ _ CONSTR) = cONSTR_STATIC
182 getSMRepClosureTypeInt (GenericRep True _ _ CONSTR_NOCAF) = cONSTR_NOCAF_STATIC
183 getSMRepClosureTypeInt (GenericRep True _ _ FUN) = fUN_STATIC
184 getSMRepClosureTypeInt (GenericRep True _ _ THUNK) = tHUNK_STATIC
186 getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE
188 getSMRepClosureTypeInt rep = pprPanic "getSMRepClosureTypeInt:" (pprSMRep rep)
191 -- Just the ones we need:
193 #include "../includes/ClosureTypes.h"
195 cONSTR = (CONSTR :: Int)
196 cONSTR_1_0 = (CONSTR_1_0 :: Int)
197 cONSTR_0_1 = (CONSTR_0_1 :: Int)
198 cONSTR_2_0 = (CONSTR_2_0 :: Int)
199 cONSTR_1_1 = (CONSTR_1_1 :: Int)
200 cONSTR_0_2 = (CONSTR_0_2 :: Int)
201 cONSTR_STATIC = (CONSTR_STATIC :: Int)
202 cONSTR_NOCAF_STATIC = (CONSTR_NOCAF_STATIC :: Int)
204 fUN_1_0 = (FUN_1_0 :: Int)
205 fUN_0_1 = (FUN_0_1 :: Int)
206 fUN_2_0 = (FUN_2_0 :: Int)
207 fUN_1_1 = (FUN_1_1 :: Int)
208 fUN_0_2 = (FUN_0_2 :: Int)
209 fUN_STATIC = (FUN_STATIC :: Int)
210 tHUNK = (THUNK :: Int)
211 tHUNK_1_0 = (THUNK_1_0 :: Int)
212 tHUNK_0_1 = (THUNK_0_1 :: Int)
213 tHUNK_2_0 = (THUNK_2_0 :: Int)
214 tHUNK_1_1 = (THUNK_1_1 :: Int)
215 tHUNK_0_2 = (THUNK_0_2 :: Int)
216 tHUNK_STATIC = (THUNK_STATIC :: Int)
217 tHUNK_SELECTOR = (THUNK_SELECTOR :: Int)
218 rET_SMALL = (RET_SMALL :: Int)
219 rET_VEC_SMALL = (RET_VEC_SMALL :: Int)
220 rET_BIG = (RET_BIG :: Int)
221 rET_VEC_BIG = (RET_VEC_BIG :: Int)
222 bLACKHOLE = (BLACKHOLE :: Int)
224 #endif OMIT_NATIVE_CODEGEN