[project @ 1998-12-02 13:17:09 by simonm]
[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, arrHdrSize, fixedItblSize, getSMRepStr, getClosureTypeStr
14
15 #ifndef OMIT_NATIVE_CODEGEN
16         , getSMRepClosureTypeInt
17         , cONSTR                  
18         , cONSTR_STATIC           
19         , cONSTR_NOCAF_STATIC     
20         , fUN                     
21         , fUN_STATIC              
22         , tHUNK                   
23         , tHUNK_STATIC            
24         , tHUNK_SELECTOR          
25         , rET_SMALL               
26         , rET_VEC_SMALL           
27         , rET_BIG                 
28         , rET_VEC_BIG
29         , bLACKHOLE               
30 #endif
31     ) where
32
33 #include "HsVersions.h"
34
35 import CmdLineOpts
36 import AbsCSyn          ( Liveness(..) )
37 import Constants        ( sTD_HDR_SIZE, pROF_HDR_SIZE, 
38                           gRAN_HDR_SIZE, tICKY_HDR_SIZE, aRR_HDR_SIZE,
39                           sTD_ITBL_SIZE, pROF_ITBL_SIZE, 
40                           gRAN_ITBL_SIZE, tICKY_ITBL_SIZE )
41 import Outputable
42 import Util             ( panic )
43 import GlaExts          ( Int(..), Int#, (<#), (==#), (<#), (>#) )
44 \end{code}
45
46 %************************************************************************
47 %*                                                                      *
48 \subsubsection[SMRep-datatype]{@SMRep@---storage manager representation}
49 %*                                                                      *
50 %************************************************************************
51
52 \begin{code}
53 data SMRep
54      -- static closure have an extra static link field at the end.
55   = StaticRep
56         Int             -- # ptr words (useful for interpreter, debugger, etc)
57         Int             -- # non-ptr words
58         ClosureType     -- closure type
59
60   | GenericRep          -- GC routines consult sizes in info tbl
61         Int             -- # ptr words
62         Int             -- # non-ptr words
63         ClosureType     -- closure type
64
65   | ConstantRep         -- CONSTR with zero-arity
66
67   | BlackHoleRep
68
69 data ClosureType
70     = CONSTR
71     | CONSTR_NOCAF
72     | FUN
73     | THUNK
74     | THUNK_SELECTOR
75   deriving (Eq,Ord)
76
77 \end{code}
78
79 Size of a closure header.
80
81 \begin{code}
82 fixedHdrSize :: Int{-words-}
83 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize + tickyHdrSize
84
85 profHdrSize  :: Int{-words-}
86 profHdrSize  | opt_SccProfilingOn   = pROF_HDR_SIZE
87              | otherwise            = 0
88
89 granHdrSize  :: Int{-words-}
90 granHdrSize  | opt_GranMacros       = gRAN_HDR_SIZE
91              | otherwise            = 0
92
93 tickyHdrSize :: Int{-words-}
94 tickyHdrSize | opt_DoTickyProfiling = tICKY_HDR_SIZE
95              | otherwise            = 0
96
97 arrHdrSize   :: Int{-words-}
98 arrHdrSize   = fixedHdrSize + aRR_HDR_SIZE
99 \end{code}
100
101 Size of an info table.
102
103 \begin{code}
104 fixedItblSize :: Int{-words-}
105 fixedItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
106
107 profItblSize  :: Int{-words-}
108 profItblSize  | opt_SccProfilingOn   = pROF_ITBL_SIZE
109               | otherwise           = 0
110
111 granItblSize  :: Int{-words-}
112 granItblSize  | opt_GranMacros      = gRAN_ITBL_SIZE
113               | otherwise           = 0
114
115 tickyItblSize :: Int{-words-}
116 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
117               | otherwise           = 0
118 \end{code}
119
120 \begin{code}
121 isConstantRep, isStaticRep :: SMRep -> Bool
122 isConstantRep ConstantRep     = True
123 isConstantRep other           = False
124
125 isStaticRep (StaticRep _ _ _) = True
126 isStaticRep _                 = False
127 \end{code}
128
129 \begin{code}
130 {- ToDo: needed? -}
131 instance Text SMRep where
132     showsPrec d rep
133       = showString (case rep of
134            StaticRep _ _ _                       -> "STATIC"
135            GenericRep _ _ _                      -> ""
136            ConstantRep                           -> "")
137
138 instance Outputable SMRep where
139     ppr rep = text (show rep)
140
141 getSMRepStr (GenericRep _ _ t)     = getClosureTypeStr t
142 getSMRepStr (StaticRep _ _ t)      = getClosureTypeStr t ++ "_STATIC"
143 getSMRepStr ConstantRep            = "CONSTR_NOCAF_STATIC"
144 getSMRepStr BlackHoleRep           = "BLACKHOLE"
145
146 getClosureTypeStr CONSTR           = "CONSTR"
147 getClosureTypeStr CONSTR_NOCAF     = "CONSTR_NOCAF"
148 getClosureTypeStr FUN              = "FUN"
149 getClosureTypeStr THUNK            = "THUNK"
150 getClosureTypeStr THUNK_SELECTOR   = "THUNK_SELECTOR"
151
152 #ifndef OMIT_NATIVE_CODEGEN
153 getSMRepClosureTypeInt :: SMRep -> Int
154 getSMRepClosureTypeInt (GenericRep _ _ t) =
155   case t of 
156     CONSTR         -> cONSTR
157     CONSTR_NOCAF   -> panic "getClosureTypeInt: CONSTR_NOCAF"
158     FUN            -> fUN
159     THUNK          -> tHUNK
160     THUNK_SELECTOR -> tHUNK_SELECTOR
161 getSMRepClosureTypeInt (StaticRep _ _ t) =
162   case t of 
163     CONSTR         -> cONSTR_STATIC
164     CONSTR_NOCAF   -> cONSTR_NOCAF_STATIC
165     FUN            -> fUN_STATIC
166     THUNK          -> tHUNK_STATIC
167     THUNK_SELECTOR -> panic "getClosureTypeInt: THUNK_SELECTOR_STATIC"
168
169 getSMRepClosureTypeInt ConstantRep = cONSTR_NOCAF_STATIC
170
171 getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE
172
173 -- Just the ones we need:
174
175 #include "../includes/ClosureTypes.h"
176
177 cONSTR                  = (CONSTR               :: Int)
178 cONSTR_STATIC           = (CONSTR_STATIC        :: Int)
179 cONSTR_NOCAF_STATIC     = (CONSTR_NOCAF_STATIC  :: Int)
180 fUN                     = (FUN                  :: Int)
181 fUN_STATIC              = (FUN_STATIC           :: Int)
182 tHUNK                   = (THUNK                :: Int)
183 tHUNK_STATIC            = (THUNK_STATIC         :: Int)
184 tHUNK_SELECTOR          = (THUNK_SELECTOR       :: Int)
185 rET_SMALL               = (RET_SMALL            :: Int)
186 rET_VEC_SMALL           = (RET_VEC_SMALL        :: Int)
187 rET_BIG                 = (RET_BIG              :: Int)
188 rET_VEC_BIG             = (RET_VEC_BIG          :: Int)
189 bLACKHOLE               = (BLACKHOLE            :: Int)
190
191 #endif OMIT_NATIVE_CODEGEN
192 \end{code}