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