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 stdItblSize, retItblSize,
15 getSMRepClosureTypeInt,
17 rET_SMALL, rET_VEC_SMALL, rET_BIG, rET_VEC_BIG,
19 StgWord, StgHalfWord, hALF_WORD,
22 #include "HsVersions.h"
23 #include "../includes/MachDeps.h"
32 %************************************************************************
34 \subsubsection[SMRep-datatype]{@SMRep@---storage manager representation}
36 %************************************************************************
40 -- static closure have an extra static link field at the end.
41 = GenericRep -- GC routines consult sizes in info tbl
42 Bool -- True <=> This is a static closure. Affects how
43 -- we garbage-collect it
45 !Int -- # non-ptr words
46 ClosureType -- closure type
50 data ClosureType -- Corresponds 1-1 with the varieties of closures
51 -- implemented by the RTS. Compare with ghc/includes/ClosureTypes.h
59 Size of a closure header.
62 fixedHdrSize :: Int{-words-}
63 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize
65 profHdrSize :: Int{-words-}
66 profHdrSize | opt_SccProfilingOn = pROF_HDR_SIZE
69 granHdrSize :: Int{-words-}
70 granHdrSize | opt_GranMacros = gRAN_HDR_SIZE
73 arrWordsHdrSize :: Int{-words-}
74 arrWordsHdrSize = fixedHdrSize + aRR_WORDS_HDR_SIZE
76 arrPtrsHdrSize :: Int{-words-}
77 arrPtrsHdrSize = fixedHdrSize + aRR_PTRS_HDR_SIZE
80 Size of an info table.
83 stdItblSize :: Int{-words-}
84 stdItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
86 retItblSize :: Int{-words-}
87 retItblSize = stdItblSize + rET_ITBL_SIZE
89 profItblSize :: Int{-words-}
90 profItblSize | opt_SccProfilingOn = pROF_ITBL_SIZE
93 granItblSize :: Int{-words-}
94 granItblSize | opt_GranMacros = gRAN_ITBL_SIZE
97 tickyItblSize :: Int{-words-}
98 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
103 isStaticRep :: SMRep -> Bool
104 isStaticRep (GenericRep is_static _ _ _) = is_static
105 isStaticRep BlackHoleRep = False
109 #include "../includes/ClosureTypes.h"
110 -- Defines CONSTR, CONSTR_1_0 etc
112 getSMRepClosureTypeInt :: SMRep -> Int
113 getSMRepClosureTypeInt (GenericRep False 1 0 Constr) = CONSTR_1_0
114 getSMRepClosureTypeInt (GenericRep False 0 1 Constr) = CONSTR_0_1
115 getSMRepClosureTypeInt (GenericRep False 2 0 Constr) = CONSTR_2_0
116 getSMRepClosureTypeInt (GenericRep False 1 1 Constr) = CONSTR_1_1
117 getSMRepClosureTypeInt (GenericRep False 0 2 Constr) = CONSTR_0_2
118 getSMRepClosureTypeInt (GenericRep False _ _ Constr) = CONSTR
120 getSMRepClosureTypeInt (GenericRep False 1 0 Fun) = FUN_1_0
121 getSMRepClosureTypeInt (GenericRep False 0 1 Fun) = FUN_0_1
122 getSMRepClosureTypeInt (GenericRep False 2 0 Fun) = FUN_2_0
123 getSMRepClosureTypeInt (GenericRep False 1 1 Fun) = FUN_1_1
124 getSMRepClosureTypeInt (GenericRep False 0 2 Fun) = FUN_0_2
125 getSMRepClosureTypeInt (GenericRep False _ _ Fun) = FUN
127 getSMRepClosureTypeInt (GenericRep False 1 0 Thunk) = THUNK_1_0
128 getSMRepClosureTypeInt (GenericRep False 0 1 Thunk) = THUNK_0_1
129 getSMRepClosureTypeInt (GenericRep False 2 0 Thunk) = THUNK_2_0
130 getSMRepClosureTypeInt (GenericRep False 1 1 Thunk) = THUNK_1_1
131 getSMRepClosureTypeInt (GenericRep False 0 2 Thunk) = THUNK_0_2
132 getSMRepClosureTypeInt (GenericRep False _ _ Thunk) = THUNK
134 getSMRepClosureTypeInt (GenericRep False _ _ ThunkSelector) = THUNK_SELECTOR
136 getSMRepClosureTypeInt (GenericRep True _ _ Constr) = CONSTR_STATIC
137 getSMRepClosureTypeInt (GenericRep True _ _ ConstrNoCaf) = CONSTR_NOCAF_STATIC
138 getSMRepClosureTypeInt (GenericRep True _ _ Fun) = FUN_STATIC
139 getSMRepClosureTypeInt (GenericRep True _ _ Thunk) = THUNK_STATIC
141 getSMRepClosureTypeInt BlackHoleRep = BLACKHOLE
143 getSMRepClosureTypeInt rep = panic "getSMRepClosureTypeInt"
146 -- We export these ones
147 rET_SMALL = (RET_SMALL :: Int)
148 rET_VEC_SMALL = (RET_VEC_SMALL :: Int)
149 rET_BIG = (RET_BIG :: Int)
150 rET_VEC_BIG = (RET_VEC_BIG :: Int)
153 A type representing an StgWord on the target platform.
156 #if SIZEOF_HSWORD == 4
157 type StgWord = Word32
158 type StgHalfWord = Word16
159 hALF_WORD = 16 :: Int
160 #elif SIZEOF_HSWORD == 8
161 type StgWord = Word64
162 type StgHalfWord = Word32
163 hALF_WORD = 32 :: Int
165 #error unknown SIZEOF_HSWORD