[project @ 2002-12-11 15:36:20 by simonmar]
[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         stdItblSize, retItblSize
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
53 import Outputable
54 \end{code}
55
56 %************************************************************************
57 %*                                                                      *
58 \subsubsection[SMRep-datatype]{@SMRep@---storage manager representation}
59 %*                                                                      *
60 %************************************************************************
61
62 \begin{code}
63 data SMRep
64      -- static closure have an extra static link field at the end.
65   = GenericRep          -- GC routines consult sizes in info tbl
66         Bool            -- True <=> This is a static closure.  Affects how 
67                         --          we garbage-collect it
68         !Int            -- # ptr words
69         !Int            -- # non-ptr words
70         ClosureType     -- closure type
71
72   | BlackHoleRep
73
74 data ClosureType        -- Corresponds 1-1 with the varieties of closures
75                         -- implemented by the RTS.  Compare with ghc/includes/ClosureTypes.h
76     = CONSTR
77     | CONSTR_NOCAF
78     | FUN
79     | THUNK
80     | THUNK_SELECTOR
81 \end{code}
82
83 Size of a closure header.
84
85 \begin{code}
86 fixedHdrSize :: Int{-words-}
87 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize
88
89 profHdrSize  :: Int{-words-}
90 profHdrSize  | opt_SccProfilingOn   = pROF_HDR_SIZE
91              | otherwise            = 0
92
93 granHdrSize  :: Int{-words-}
94 granHdrSize  | opt_GranMacros       = gRAN_HDR_SIZE
95              | otherwise            = 0
96
97 arrWordsHdrSize   :: Int{-words-}
98 arrWordsHdrSize   = fixedHdrSize + aRR_WORDS_HDR_SIZE
99
100 arrPtrsHdrSize   :: Int{-words-}
101 arrPtrsHdrSize   = fixedHdrSize + aRR_PTRS_HDR_SIZE
102 \end{code}
103
104 Size of an info table.
105
106 \begin{code}
107 stdItblSize :: Int{-words-}
108 stdItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
109
110 retItblSize :: Int{-words-}
111 retItblSize = stdItblSize + rET_ITBL_SIZE
112
113 profItblSize  :: Int{-words-}
114 profItblSize  | opt_SccProfilingOn   = pROF_ITBL_SIZE
115               | otherwise           = 0
116
117 granItblSize  :: Int{-words-}
118 granItblSize  | opt_GranMacros      = gRAN_ITBL_SIZE
119               | otherwise           = 0
120
121 tickyItblSize :: Int{-words-}
122 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
123               | otherwise           = 0
124 \end{code}
125
126 \begin{code}
127 isStaticRep :: SMRep -> Bool
128 isStaticRep (GenericRep is_static _ _ _) = is_static
129 isStaticRep BlackHoleRep                 = False
130 \end{code}
131
132 \begin{code}
133 getSMRepClosureTypeInt :: SMRep -> Int
134 getSMRepClosureTypeInt (GenericRep False 1 0 CONSTR) = cONSTR_1_0
135 getSMRepClosureTypeInt (GenericRep False 0 1 CONSTR) = cONSTR_0_1
136 getSMRepClosureTypeInt (GenericRep False 2 0 CONSTR) = cONSTR_2_0
137 getSMRepClosureTypeInt (GenericRep False 1 1 CONSTR) = cONSTR_1_1
138 getSMRepClosureTypeInt (GenericRep False 0 2 CONSTR) = cONSTR_0_2
139 getSMRepClosureTypeInt (GenericRep False _ _ CONSTR) = cONSTR
140
141 getSMRepClosureTypeInt (GenericRep False 1 0 FUN) = fUN_1_0
142 getSMRepClosureTypeInt (GenericRep False 0 1 FUN) = fUN_0_1
143 getSMRepClosureTypeInt (GenericRep False 2 0 FUN) = fUN_2_0
144 getSMRepClosureTypeInt (GenericRep False 1 1 FUN) = fUN_1_1
145 getSMRepClosureTypeInt (GenericRep False 0 2 FUN) = fUN_0_2
146 getSMRepClosureTypeInt (GenericRep False _ _ FUN) = fUN
147
148 getSMRepClosureTypeInt (GenericRep False 1 0 THUNK) = tHUNK_1_0
149 getSMRepClosureTypeInt (GenericRep False 0 1 THUNK) = tHUNK_0_1
150 getSMRepClosureTypeInt (GenericRep False 2 0 THUNK) = tHUNK_2_0
151 getSMRepClosureTypeInt (GenericRep False 1 1 THUNK) = tHUNK_1_1
152 getSMRepClosureTypeInt (GenericRep False 0 2 THUNK) = tHUNK_0_2
153 getSMRepClosureTypeInt (GenericRep False _ _ THUNK) = tHUNK
154
155 getSMRepClosureTypeInt (GenericRep False _ _ THUNK_SELECTOR) =  tHUNK_SELECTOR
156
157 getSMRepClosureTypeInt (GenericRep True _ _ CONSTR)       = cONSTR_STATIC
158 getSMRepClosureTypeInt (GenericRep True _ _ CONSTR_NOCAF) = cONSTR_NOCAF_STATIC
159 getSMRepClosureTypeInt (GenericRep True _ _ FUN)          = fUN_STATIC
160 getSMRepClosureTypeInt (GenericRep True _ _ THUNK)        = tHUNK_STATIC
161
162 getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE
163
164 getSMRepClosureTypeInt rep = panic "getSMRepClosureTypeInt"
165
166
167 -- Just the ones we need:
168
169 #include "../includes/ClosureTypes.h"
170
171 cONSTR                  = (CONSTR               :: Int)
172 cONSTR_1_0              = (CONSTR_1_0           :: Int)
173 cONSTR_0_1              = (CONSTR_0_1           :: Int)
174 cONSTR_2_0              = (CONSTR_2_0           :: Int)
175 cONSTR_1_1              = (CONSTR_1_1           :: Int)
176 cONSTR_0_2              = (CONSTR_0_2           :: Int)
177 cONSTR_STATIC           = (CONSTR_STATIC        :: Int)
178 cONSTR_NOCAF_STATIC     = (CONSTR_NOCAF_STATIC  :: Int)
179 fUN                     = (FUN                  :: Int)
180 fUN_1_0                 = (FUN_1_0              :: Int)
181 fUN_0_1                 = (FUN_0_1              :: Int)
182 fUN_2_0                 = (FUN_2_0              :: Int)
183 fUN_1_1                 = (FUN_1_1              :: Int)
184 fUN_0_2                 = (FUN_0_2              :: Int)
185 fUN_STATIC              = (FUN_STATIC           :: Int)
186 tHUNK                   = (THUNK                :: Int)
187 tHUNK_1_0               = (THUNK_1_0            :: Int)
188 tHUNK_0_1               = (THUNK_0_1            :: Int)
189 tHUNK_2_0               = (THUNK_2_0            :: Int)
190 tHUNK_1_1               = (THUNK_1_1            :: Int)
191 tHUNK_0_2               = (THUNK_0_2            :: Int)
192 tHUNK_STATIC            = (THUNK_STATIC         :: Int)
193 tHUNK_SELECTOR          = (THUNK_SELECTOR       :: Int)
194 rET_SMALL               = (RET_SMALL            :: Int)
195 rET_VEC_SMALL           = (RET_VEC_SMALL        :: Int)
196 rET_BIG                 = (RET_BIG              :: Int)
197 rET_VEC_BIG             = (RET_VEC_BIG          :: Int)
198 bLACKHOLE               = (BLACKHOLE            :: Int)
199 \end{code}