[project @ 1998-12-18 17:40:31 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, 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 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_NOCAF
71     | FUN
72     | THUNK
73     | THUNK_SELECTOR
74   deriving (Eq,Ord)
75
76 \end{code}
77
78 Size of a closure header.
79
80 \begin{code}
81 fixedHdrSize :: Int{-words-}
82 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize + tickyHdrSize
83
84 profHdrSize  :: Int{-words-}
85 profHdrSize  | opt_SccProfilingOn   = pROF_HDR_SIZE
86              | otherwise            = 0
87
88 granHdrSize  :: Int{-words-}
89 granHdrSize  | opt_GranMacros       = gRAN_HDR_SIZE
90              | otherwise            = 0
91
92 tickyHdrSize :: Int{-words-}
93 tickyHdrSize | opt_DoTickyProfiling = tICKY_HDR_SIZE
94              | otherwise            = 0
95
96 arrHdrSize   :: Int{-words-}
97 arrHdrSize   = fixedHdrSize + aRR_HDR_SIZE
98 \end{code}
99
100 Size of an info table.
101
102 \begin{code}
103 fixedItblSize :: Int{-words-}
104 fixedItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
105
106 profItblSize  :: Int{-words-}
107 profItblSize  | opt_SccProfilingOn   = pROF_ITBL_SIZE
108               | otherwise           = 0
109
110 granItblSize  :: Int{-words-}
111 granItblSize  | opt_GranMacros      = gRAN_ITBL_SIZE
112               | otherwise           = 0
113
114 tickyItblSize :: Int{-words-}
115 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
116               | otherwise           = 0
117 \end{code}
118
119 \begin{code}
120 isConstantRep, isStaticRep :: SMRep -> Bool
121 isConstantRep ConstantRep     = True
122 isConstantRep other           = False
123
124 isStaticRep (StaticRep _ _ _) = True
125 isStaticRep _                 = False
126 \end{code}
127
128 \begin{code}
129 {- ToDo: needed? -}
130 instance Text SMRep where
131     showsPrec d rep
132       = showString (case rep of
133            StaticRep _ _ _                       -> "STATIC"
134            GenericRep _ _ _                      -> ""
135            ConstantRep                           -> "")
136
137 instance Outputable SMRep where
138     ppr rep = text (show rep)
139
140 getSMRepStr (GenericRep _ _ t)     = getClosureTypeStr t
141 getSMRepStr (StaticRep _ _ t)      = getClosureTypeStr t ++ "_STATIC"
142 getSMRepStr ConstantRep            = "CONSTR_NOCAF_STATIC"
143 getSMRepStr BlackHoleRep           = "BLACKHOLE"
144
145 getClosureTypeStr CONSTR           = "CONSTR"
146 getClosureTypeStr CONSTR_NOCAF     = "CONSTR_NOCAF"
147 getClosureTypeStr FUN              = "FUN"
148 getClosureTypeStr THUNK            = "THUNK"
149 getClosureTypeStr THUNK_SELECTOR   = "THUNK_SELECTOR"
150
151 #ifndef OMIT_NATIVE_CODEGEN
152 getSMRepClosureTypeInt :: SMRep -> Int
153 getSMRepClosureTypeInt (GenericRep _ _ t) =
154   case t of 
155     CONSTR         -> cONSTR
156     CONSTR_NOCAF   -> panic "getClosureTypeInt: CONSTR_NOCAF"
157     FUN            -> fUN
158     THUNK          -> tHUNK
159     THUNK_SELECTOR -> tHUNK_SELECTOR
160 getSMRepClosureTypeInt (StaticRep _ _ t) =
161   case t of 
162     CONSTR         -> cONSTR_STATIC
163     CONSTR_NOCAF   -> cONSTR_NOCAF_STATIC
164     FUN            -> fUN_STATIC
165     THUNK          -> tHUNK_STATIC
166     THUNK_SELECTOR -> panic "getClosureTypeInt: THUNK_SELECTOR_STATIC"
167
168 getSMRepClosureTypeInt ConstantRep = cONSTR_NOCAF_STATIC
169
170 getSMRepClosureTypeInt BlackHoleRep = bLACKHOLE
171
172 -- Just the ones we need:
173
174 #include "../includes/ClosureTypes.h"
175
176 cONSTR                  = (CONSTR               :: Int)
177 cONSTR_STATIC           = (CONSTR_STATIC        :: Int)
178 cONSTR_NOCAF_STATIC     = (CONSTR_NOCAF_STATIC  :: Int)
179 fUN                     = (FUN                  :: Int)
180 fUN_STATIC              = (FUN_STATIC           :: Int)
181 tHUNK                   = (THUNK                :: Int)
182 tHUNK_STATIC            = (THUNK_STATIC         :: Int)
183 tHUNK_SELECTOR          = (THUNK_SELECTOR       :: Int)
184 rET_SMALL               = (RET_SMALL            :: Int)
185 rET_VEC_SMALL           = (RET_VEC_SMALL        :: Int)
186 rET_BIG                 = (RET_BIG              :: Int)
187 rET_VEC_BIG             = (RET_VEC_BIG          :: Int)
188 bLACKHOLE               = (BLACKHOLE            :: Int)
189
190 #endif OMIT_NATIVE_CODEGEN
191 \end{code}