aabcf404492c5f08867e86a222fa956622bf9ec2
[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         isConstantRep, 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 AbsCSyn          ( Liveness(..) )
53 import Constants        ( sTD_HDR_SIZE, pROF_HDR_SIZE,
54                           gRAN_HDR_SIZE, tICKY_HDR_SIZE, 
55                           aRR_WORDS_HDR_SIZE, aRR_PTRS_HDR_SIZE,
56                           sTD_ITBL_SIZE, pROF_ITBL_SIZE,
57                           gRAN_ITBL_SIZE, tICKY_ITBL_SIZE )
58 import Outputable
59 import GlaExts          ( Int(..), Int#, (<#), (==#), (<#), (>#) )
60 \end{code}
61
62 %************************************************************************
63 %*                                                                      *
64 \subsubsection[SMRep-datatype]{@SMRep@---storage manager representation}
65 %*                                                                      *
66 %************************************************************************
67
68 \begin{code}
69 data SMRep
70      -- static closure have an extra static link field at the end.
71   = StaticRep
72         Int             -- # ptr words (useful for interpreter, debugger, etc)
73         Int             -- # non-ptr words
74         ClosureType     -- closure type
75
76   | GenericRep          -- GC routines consult sizes in info tbl
77         Int             -- # ptr words
78         Int             -- # non-ptr words
79         ClosureType     -- closure type
80
81   | ConstantRep         -- CONSTR with zero-arity
82
83   | BlackHoleRep
84
85 data ClosureType
86     = CONSTR
87     | CONSTR_p_n Int Int
88     | CONSTR_NOCAF
89     | FUN
90     | FUN_p_n Int Int
91     | THUNK
92     | THUNK_p_n Int Int
93     | THUNK_SELECTOR
94   deriving (Eq,Ord)
95
96 \end{code}
97
98 Size of a closure header.
99
100 \begin{code}
101 fixedHdrSize :: Int{-words-}
102 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize + tickyHdrSize
103
104 profHdrSize  :: Int{-words-}
105 profHdrSize  | opt_SccProfilingOn   = pROF_HDR_SIZE
106              | otherwise            = 0
107
108 granHdrSize  :: Int{-words-}
109 granHdrSize  | opt_GranMacros       = gRAN_HDR_SIZE
110              | otherwise            = 0
111
112 tickyHdrSize :: Int{-words-}
113 tickyHdrSize | opt_DoTickyProfiling = tICKY_HDR_SIZE
114              | otherwise            = 0
115
116 arrWordsHdrSize   :: Int{-words-}
117 arrWordsHdrSize   = fixedHdrSize + aRR_WORDS_HDR_SIZE
118
119 arrPtrsHdrSize   :: Int{-words-}
120 arrPtrsHdrSize   = fixedHdrSize + aRR_PTRS_HDR_SIZE
121 \end{code}
122
123 Size of an info table.
124
125 \begin{code}
126 fixedItblSize :: Int{-words-}
127 fixedItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
128
129 profItblSize  :: Int{-words-}
130 profItblSize  | opt_SccProfilingOn   = pROF_ITBL_SIZE
131               | otherwise           = 0
132
133 granItblSize  :: Int{-words-}
134 granItblSize  | opt_GranMacros      = gRAN_ITBL_SIZE
135               | otherwise           = 0
136
137 tickyItblSize :: Int{-words-}
138 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
139               | otherwise           = 0
140 \end{code}
141
142 \begin{code}
143 isConstantRep, isStaticRep :: SMRep -> Bool
144 isConstantRep ConstantRep     = True
145 isConstantRep other           = False
146
147 isStaticRep (StaticRep _ _ _) = True
148 isStaticRep _                 = False
149 \end{code}
150
151 \begin{code}
152 {- ToDo: needed? -}
153 instance Text SMRep where
154     showsPrec d rep
155       = showString (case rep of
156            StaticRep _ _ _                       -> "STATIC"
157            GenericRep _ _ _                      -> ""
158            ConstantRep                           -> "")
159
160 instance Outputable SMRep where
161     ppr rep = pprSMRep rep
162
163 pprSMRep :: SMRep -> SDoc
164 pprSMRep (GenericRep _ _ t)     = pprClosureType t
165 pprSMRep (StaticRep _ _ t)      = pprClosureType t <> ptext SLIT("_STATIC")
166 pprSMRep ConstantRep            = ptext SLIT("CONSTR_NOCAF_STATIC")
167 pprSMRep BlackHoleRep           = ptext SLIT("BLACKHOLE")
168
169 pprClosureType CONSTR           = ptext SLIT("CONSTR")
170 pprClosureType (CONSTR_p_n p n) = ptext SLIT("CONSTR_") <> int p <> char '_' <> int n
171 pprClosureType CONSTR_NOCAF     = ptext SLIT("CONSTR_NOCAF")
172 pprClosureType FUN              = ptext SLIT("FUN")
173 pprClosureType (FUN_p_n p n)    = ptext SLIT("FUN_") <> int p <> char '_' <> int n
174 pprClosureType THUNK            = ptext SLIT("THUNK")
175 pprClosureType (THUNK_p_n p n)  = ptext SLIT("THUNK_") <> int p <> char '_' <> int n
176 pprClosureType THUNK_SELECTOR   = ptext SLIT("THUNK_SELECTOR")
177
178 #ifndef OMIT_NATIVE_CODEGEN
179 getSMRepClosureTypeInt :: SMRep -> Int
180 getSMRepClosureTypeInt (GenericRep _ _ t) =
181   case t of
182     CONSTR         -> cONSTR
183     CONSTR_p_n 1 0 -> cONSTR_1_0
184     CONSTR_p_n 0 1 -> cONSTR_0_1
185     CONSTR_p_n 2 0 -> cONSTR_2_0
186     CONSTR_p_n 1 1 -> cONSTR_1_1
187     CONSTR_p_n 0 2 -> cONSTR_0_2
188     CONSTR_NOCAF   -> panic "getClosureTypeInt: CONSTR_NOCAF"
189     FUN            -> fUN
190     FUN_p_n 1 0    -> fUN_1_0
191     FUN_p_n 0 1    -> fUN_0_1
192     FUN_p_n 2 0    -> fUN_2_0
193     FUN_p_n 1 1    -> fUN_1_1
194     FUN_p_n 0 2    -> fUN_0_2
195     THUNK          -> tHUNK
196     THUNK_p_n 1 0  -> tHUNK_1_0
197     THUNK_p_n 0 1  -> tHUNK_0_1
198     THUNK_p_n 2 0  -> tHUNK_2_0
199     THUNK_p_n 1 1  -> tHUNK_1_1
200     THUNK_p_n 0 2  -> tHUNK_0_2
201     THUNK_SELECTOR -> tHUNK_SELECTOR
202 getSMRepClosureTypeInt (StaticRep _ _ t) =
203   case t of
204     CONSTR         -> cONSTR_STATIC
205     CONSTR_NOCAF   -> cONSTR_NOCAF_STATIC
206     FUN            -> fUN_STATIC
207     THUNK          -> tHUNK_STATIC
208     THUNK_SELECTOR -> panic "getClosureTypeInt: THUNK_SELECTOR_STATIC"
209
210 getSMRepClosureTypeInt ConstantRep = cONSTR_NOCAF_STATIC
211
212 getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE
213
214 -- Just the ones we need:
215
216 #include "../includes/ClosureTypes.h"
217
218 cONSTR                  = (CONSTR               :: Int)
219 cONSTR_1_0              = (CONSTR_1_0           :: Int)
220 cONSTR_0_1              = (CONSTR_0_1           :: Int)
221 cONSTR_2_0              = (CONSTR_2_0           :: Int)
222 cONSTR_1_1              = (CONSTR_1_1           :: Int)
223 cONSTR_0_2              = (CONSTR_0_2           :: Int)
224 cONSTR_STATIC           = (CONSTR_STATIC        :: Int)
225 cONSTR_NOCAF_STATIC     = (CONSTR_NOCAF_STATIC  :: Int)
226 fUN                     = (FUN                  :: Int)
227 fUN_1_0                 = (FUN_1_0              :: Int)
228 fUN_0_1                 = (FUN_0_1              :: Int)
229 fUN_2_0                 = (FUN_2_0              :: Int)
230 fUN_1_1                 = (FUN_1_1              :: Int)
231 fUN_0_2                 = (FUN_0_2              :: Int)
232 fUN_STATIC              = (FUN_STATIC           :: Int)
233 tHUNK                   = (THUNK                :: Int)
234 tHUNK_1_0               = (THUNK_1_0            :: Int)
235 tHUNK_0_1               = (THUNK_0_1            :: Int)
236 tHUNK_2_0               = (THUNK_2_0            :: Int)
237 tHUNK_1_1               = (THUNK_1_1            :: Int)
238 tHUNK_0_2               = (THUNK_0_2            :: Int)
239 tHUNK_STATIC            = (THUNK_STATIC         :: Int)
240 tHUNK_SELECTOR          = (THUNK_SELECTOR       :: Int)
241 rET_SMALL               = (RET_SMALL            :: Int)
242 rET_VEC_SMALL           = (RET_VEC_SMALL        :: Int)
243 rET_BIG                 = (RET_BIG              :: Int)
244 rET_VEC_BIG             = (RET_VEC_BIG          :: Int)
245 bLACKHOLE               = (BLACKHOLE            :: Int)
246
247 #endif OMIT_NATIVE_CODEGEN
248 \end{code}