[project @ 2001-06-25 14:36:04 by simonpj]
[ghc-hetmet.git] / ghc / compiler / codeGen / SMRep.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[SMRep]{Storage manager representations of closure}
5
6 This is here, rather than in ClosureInfo, just to keep nhc happy.
7 Other modules should access this info through ClosureInfo.
8
9 \begin{code}
10 module SMRep (
11         SMRep(..), ClosureType(..),
12         isStaticRep,
13         fixedHdrSize, arrWordsHdrSize, arrPtrsHdrSize,
14         fixedItblSize, pprSMRep
15
16 #ifndef OMIT_NATIVE_CODEGEN
17         , getSMRepClosureTypeInt
18         , cONSTR
19         , cONSTR_1_0
20         , cONSTR_0_1
21         , cONSTR_2_0
22         , cONSTR_1_1
23         , cONSTR_0_2
24         , cONSTR_STATIC
25         , cONSTR_NOCAF_STATIC
26         , fUN
27         , fUN_1_0
28         , fUN_0_1
29         , fUN_2_0
30         , fUN_1_1
31         , fUN_0_2
32         , fUN_STATIC
33         , tHUNK
34         , tHUNK_1_0
35         , tHUNK_0_1
36         , tHUNK_2_0
37         , tHUNK_1_1
38         , tHUNK_0_2
39         , tHUNK_STATIC
40         , tHUNK_SELECTOR
41         , rET_SMALL
42         , rET_VEC_SMALL
43         , rET_BIG
44         , rET_VEC_BIG
45         , bLACKHOLE
46 #endif
47     ) where
48
49 #include "HsVersions.h"
50
51 import CmdLineOpts
52 import Constants        ( sTD_HDR_SIZE, pROF_HDR_SIZE,
53                           gRAN_HDR_SIZE, tICKY_HDR_SIZE, 
54                           aRR_WORDS_HDR_SIZE, aRR_PTRS_HDR_SIZE,
55                           sTD_ITBL_SIZE, pROF_ITBL_SIZE,
56                           gRAN_ITBL_SIZE, tICKY_ITBL_SIZE )
57 import Outputable
58 \end{code}
59
60 %************************************************************************
61 %*                                                                      *
62 \subsubsection[SMRep-datatype]{@SMRep@---storage manager representation}
63 %*                                                                      *
64 %************************************************************************
65
66 \begin{code}
67 data SMRep
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
72         Int             -- # ptr words
73         Int             -- # non-ptr words
74         ClosureType     -- closure type
75
76   | BlackHoleRep
77
78 data ClosureType        -- Corresponds 1-1 with the varieties of closures
79                         -- implemented by the RTS.  Compare with ghc/includes/ClosureTypes.h
80     = CONSTR
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)
84     | CONSTR_NOCAF
85     | FUN
86     | FUN_p_n
87     | THUNK
88     | THUNK_p_n
89     | THUNK_SELECTOR
90   deriving (Eq,Ord)
91 \end{code}
92
93 Size of a closure header.
94
95 \begin{code}
96 fixedHdrSize :: Int{-words-}
97 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize + tickyHdrSize
98
99 profHdrSize  :: Int{-words-}
100 profHdrSize  | opt_SccProfilingOn   = pROF_HDR_SIZE
101              | otherwise            = 0
102
103 granHdrSize  :: Int{-words-}
104 granHdrSize  | opt_GranMacros       = gRAN_HDR_SIZE
105              | otherwise            = 0
106
107 tickyHdrSize :: Int{-words-}
108 tickyHdrSize | opt_DoTickyProfiling = tICKY_HDR_SIZE
109              | otherwise            = 0
110
111 arrWordsHdrSize   :: Int{-words-}
112 arrWordsHdrSize   = fixedHdrSize + aRR_WORDS_HDR_SIZE
113
114 arrPtrsHdrSize   :: Int{-words-}
115 arrPtrsHdrSize   = fixedHdrSize + aRR_PTRS_HDR_SIZE
116 \end{code}
117
118 Size of an info table.
119
120 \begin{code}
121 fixedItblSize :: Int{-words-}
122 fixedItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
123
124 profItblSize  :: Int{-words-}
125 profItblSize  | opt_SccProfilingOn   = pROF_ITBL_SIZE
126               | otherwise           = 0
127
128 granItblSize  :: Int{-words-}
129 granItblSize  | opt_GranMacros      = gRAN_ITBL_SIZE
130               | otherwise           = 0
131
132 tickyItblSize :: Int{-words-}
133 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
134               | otherwise           = 0
135 \end{code}
136
137 \begin{code}
138 isStaticRep :: SMRep -> Bool
139 isStaticRep (GenericRep is_static _ _ _) = is_static
140 isStaticRep BlackHoleRep                 = False
141 \end{code}
142
143 \begin{code}
144 instance Outputable SMRep where
145     ppr rep = pprSMRep rep
146
147 pprSMRep :: SMRep -> SDoc
148 pprSMRep (GenericRep True  ptrs nptrs clo_ty) = pprClosureType clo_ty ptrs nptrs <> ptext SLIT("_STATIC")
149 pprSMRep (GenericRep False ptrs nptrs clo_ty) = pprClosureType clo_ty ptrs nptrs
150
151 pprClosureType CONSTR         p n = ptext SLIT("CONSTR")
152 pprClosureType CONSTR_p_n     p n = ptext SLIT("CONSTR_") <> int p <> char '_' <> int n
153 pprClosureType CONSTR_NOCAF   p n = ptext SLIT("CONSTR_NOCAF")
154 pprClosureType FUN            p n = ptext SLIT("FUN")
155 pprClosureType FUN_p_n        p n = ptext SLIT("FUN_") <> int p <> char '_' <> int n
156 pprClosureType THUNK          p n = ptext SLIT("THUNK")
157 pprClosureType THUNK_p_n      p n = ptext SLIT("THUNK_") <> int p <> char '_' <> int n
158 pprClosureType THUNK_SELECTOR p n = ptext SLIT("THUNK_SELECTOR")
159
160 #ifndef OMIT_NATIVE_CODEGEN
161 getSMRepClosureTypeInt :: SMRep -> Int
162 getSMRepClosureTypeInt (GenericRep False _ _ CONSTR)     = cONSTR
163 getSMRepClosureTypeInt (GenericRep False 1 0 CONSTR_p_n) = cONSTR_1_0
164 getSMRepClosureTypeInt (GenericRep False 0 1 CONSTR_p_n) = cONSTR_0_1
165 getSMRepClosureTypeInt (GenericRep False 2 0 CONSTR_p_n) = cONSTR_2_0
166 getSMRepClosureTypeInt (GenericRep False 1 1 CONSTR_p_n) = cONSTR_1_1
167 getSMRepClosureTypeInt (GenericRep False 0 2 CONSTR_p_n) = cONSTR_0_2
168
169 getSMRepClosureTypeInt (GenericRep False _ _ FUN)     = fUN
170 getSMRepClosureTypeInt (GenericRep False 1 0 FUN_p_n) = fUN_1_0
171 getSMRepClosureTypeInt (GenericRep False 0 1 FUN_p_n) = fUN_0_1
172 getSMRepClosureTypeInt (GenericRep False 2 0 FUN_p_n) = fUN_2_0
173 getSMRepClosureTypeInt (GenericRep False 1 1 FUN_p_n) = fUN_1_1
174 getSMRepClosureTypeInt (GenericRep False 0 2 FUN_p_n) = fUN_0_2
175
176 getSMRepClosureTypeInt (GenericRep False _ _ THUNK)     = tHUNK
177 getSMRepClosureTypeInt (GenericRep False 1 0 THUNK_p_n) = tHUNK_1_0
178 getSMRepClosureTypeInt (GenericRep False 0 1 THUNK_p_n) = tHUNK_0_1
179 getSMRepClosureTypeInt (GenericRep False 2 0 THUNK_p_n) = tHUNK_2_0
180 getSMRepClosureTypeInt (GenericRep False 1 1 THUNK_p_n) = tHUNK_1_1
181 getSMRepClosureTypeInt (GenericRep False 0 2 THUNK_p_n) = tHUNK_0_2
182
183 getSMRepClosureTypeInt (GenericRep False _ _ THUNK_SELECTOR) =  tHUNK_SELECTOR
184
185 getSMRepClosureTypeInt (GenericRep True _ _ CONSTR)       = cONSTR_STATIC
186 getSMRepClosureTypeInt (GenericRep True _ _ CONSTR_NOCAF) = cONSTR_NOCAF_STATIC
187 getSMRepClosureTypeInt (GenericRep True _ _ FUN)          = fUN_STATIC
188 getSMRepClosureTypeInt (GenericRep True _ _ THUNK)        = tHUNK_STATIC
189
190 getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE
191
192 getSMRepClosureTypeInt rep = pprPanic "getSMRepClosureTypeInt:" (pprSMRep rep)
193
194
195 -- Just the ones we need:
196
197 #include "../includes/ClosureTypes.h"
198
199 cONSTR                  = (CONSTR               :: Int)
200 cONSTR_1_0              = (CONSTR_1_0           :: Int)
201 cONSTR_0_1              = (CONSTR_0_1           :: Int)
202 cONSTR_2_0              = (CONSTR_2_0           :: Int)
203 cONSTR_1_1              = (CONSTR_1_1           :: Int)
204 cONSTR_0_2              = (CONSTR_0_2           :: Int)
205 cONSTR_STATIC           = (CONSTR_STATIC        :: Int)
206 cONSTR_NOCAF_STATIC     = (CONSTR_NOCAF_STATIC  :: Int)
207 fUN                     = (FUN                  :: Int)
208 fUN_1_0                 = (FUN_1_0              :: Int)
209 fUN_0_1                 = (FUN_0_1              :: Int)
210 fUN_2_0                 = (FUN_2_0              :: Int)
211 fUN_1_1                 = (FUN_1_1              :: Int)
212 fUN_0_2                 = (FUN_0_2              :: Int)
213 fUN_STATIC              = (FUN_STATIC           :: Int)
214 tHUNK                   = (THUNK                :: Int)
215 tHUNK_1_0               = (THUNK_1_0            :: Int)
216 tHUNK_0_1               = (THUNK_0_1            :: Int)
217 tHUNK_2_0               = (THUNK_2_0            :: Int)
218 tHUNK_1_1               = (THUNK_1_1            :: Int)
219 tHUNK_0_2               = (THUNK_0_2            :: Int)
220 tHUNK_STATIC            = (THUNK_STATIC         :: Int)
221 tHUNK_SELECTOR          = (THUNK_SELECTOR       :: Int)
222 rET_SMALL               = (RET_SMALL            :: Int)
223 rET_VEC_SMALL           = (RET_VEC_SMALL        :: Int)
224 rET_BIG                 = (RET_BIG              :: Int)
225 rET_VEC_BIG             = (RET_VEC_BIG          :: Int)
226 bLACKHOLE               = (BLACKHOLE            :: Int)
227
228 #endif OMIT_NATIVE_CODEGEN
229 \end{code}