4f53f4bfee641910ad0a8062effb45fc635c4fe6
[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         getSMRepClosureTypeInt,
16
17         rET_SMALL, rET_VEC_SMALL, rET_BIG, rET_VEC_BIG,
18
19         StgWord, StgHalfWord, hALF_WORD,
20     ) where
21
22 #include "HsVersions.h"
23 #include "../includes/MachDeps.h"
24
25 import CmdLineOpts
26 import Constants
27 import Outputable
28
29 import DATA_WORD
30 \end{code}
31
32 %************************************************************************
33 %*                                                                      *
34 \subsubsection[SMRep-datatype]{@SMRep@---storage manager representation}
35 %*                                                                      *
36 %************************************************************************
37
38 \begin{code}
39 data SMRep
40      -- static closure have an extra static link field at the end.
41   = GenericRep          -- GC routines consult sizes in info tbl
42         Bool            -- True <=> This is a static closure.  Affects how 
43                         --          we garbage-collect it
44         !Int            -- # ptr words
45         !Int            -- # non-ptr words
46         ClosureType     -- closure type
47
48   | BlackHoleRep
49
50 data ClosureType        -- Corresponds 1-1 with the varieties of closures
51                         -- implemented by the RTS.  Compare with ghc/includes/ClosureTypes.h
52     = Constr
53     | ConstrNoCaf
54     | Fun
55     | Thunk
56     | ThunkSelector
57 \end{code}
58
59 Size of a closure header.
60
61 \begin{code}
62 fixedHdrSize :: Int{-words-}
63 fixedHdrSize = sTD_HDR_SIZE + profHdrSize + granHdrSize
64
65 profHdrSize  :: Int{-words-}
66 profHdrSize  | opt_SccProfilingOn   = pROF_HDR_SIZE
67              | otherwise            = 0
68
69 granHdrSize  :: Int{-words-}
70 granHdrSize  | opt_GranMacros       = gRAN_HDR_SIZE
71              | otherwise            = 0
72
73 arrWordsHdrSize   :: Int{-words-}
74 arrWordsHdrSize   = fixedHdrSize + aRR_WORDS_HDR_SIZE
75
76 arrPtrsHdrSize   :: Int{-words-}
77 arrPtrsHdrSize   = fixedHdrSize + aRR_PTRS_HDR_SIZE
78 \end{code}
79
80 Size of an info table.
81
82 \begin{code}
83 stdItblSize :: Int{-words-}
84 stdItblSize = sTD_ITBL_SIZE + profItblSize + granItblSize + tickyItblSize
85
86 retItblSize :: Int{-words-}
87 retItblSize = stdItblSize + rET_ITBL_SIZE
88
89 profItblSize  :: Int{-words-}
90 profItblSize  | opt_SccProfilingOn  = pROF_ITBL_SIZE
91               | otherwise           = 0
92
93 granItblSize  :: Int{-words-}
94 granItblSize  | opt_GranMacros      = gRAN_ITBL_SIZE
95               | otherwise           = 0
96
97 tickyItblSize :: Int{-words-}
98 tickyItblSize | opt_DoTickyProfiling = tICKY_ITBL_SIZE
99               | otherwise            = 0
100 \end{code}
101
102 \begin{code}
103 isStaticRep :: SMRep -> Bool
104 isStaticRep (GenericRep is_static _ _ _) = is_static
105 isStaticRep BlackHoleRep                 = False
106 \end{code}
107
108 \begin{code}
109 #include "../includes/ClosureTypes.h"
110 -- Defines CONSTR, CONSTR_1_0 etc
111
112 getSMRepClosureTypeInt :: SMRep -> Int
113 getSMRepClosureTypeInt (GenericRep False 1 0 Constr) = CONSTR_1_0
114 getSMRepClosureTypeInt (GenericRep False 0 1 Constr) = CONSTR_0_1
115 getSMRepClosureTypeInt (GenericRep False 2 0 Constr) = CONSTR_2_0
116 getSMRepClosureTypeInt (GenericRep False 1 1 Constr) = CONSTR_1_1
117 getSMRepClosureTypeInt (GenericRep False 0 2 Constr) = CONSTR_0_2
118 getSMRepClosureTypeInt (GenericRep False _ _ Constr) = CONSTR
119
120 getSMRepClosureTypeInt (GenericRep False 1 0 Fun) = FUN_1_0
121 getSMRepClosureTypeInt (GenericRep False 0 1 Fun) = FUN_0_1
122 getSMRepClosureTypeInt (GenericRep False 2 0 Fun) = FUN_2_0
123 getSMRepClosureTypeInt (GenericRep False 1 1 Fun) = FUN_1_1
124 getSMRepClosureTypeInt (GenericRep False 0 2 Fun) = FUN_0_2
125 getSMRepClosureTypeInt (GenericRep False _ _ Fun) = FUN
126
127 getSMRepClosureTypeInt (GenericRep False 1 0 Thunk) = THUNK_1_0
128 getSMRepClosureTypeInt (GenericRep False 0 1 Thunk) = THUNK_0_1
129 getSMRepClosureTypeInt (GenericRep False 2 0 Thunk) = THUNK_2_0
130 getSMRepClosureTypeInt (GenericRep False 1 1 Thunk) = THUNK_1_1
131 getSMRepClosureTypeInt (GenericRep False 0 2 Thunk) = THUNK_0_2
132 getSMRepClosureTypeInt (GenericRep False _ _ Thunk) = THUNK
133
134 getSMRepClosureTypeInt (GenericRep False _ _ ThunkSelector) =  THUNK_SELECTOR
135
136 getSMRepClosureTypeInt (GenericRep True _ _ Constr)      = CONSTR_STATIC
137 getSMRepClosureTypeInt (GenericRep True _ _ ConstrNoCaf) = CONSTR_NOCAF_STATIC
138 getSMRepClosureTypeInt (GenericRep True _ _ Fun)         = FUN_STATIC
139 getSMRepClosureTypeInt (GenericRep True _ _ Thunk)       = THUNK_STATIC
140
141 getSMRepClosureTypeInt BlackHoleRep = BLACKHOLE
142
143 getSMRepClosureTypeInt rep = panic "getSMRepClosureTypeInt"
144
145
146 -- We export these ones
147 rET_SMALL     = (RET_SMALL     :: Int)
148 rET_VEC_SMALL = (RET_VEC_SMALL :: Int)
149 rET_BIG       = (RET_BIG       :: Int)
150 rET_VEC_BIG   = (RET_VEC_BIG   :: Int)
151 \end{code}
152
153 A type representing an StgWord on the target platform.
154
155 \begin{code}
156 #if SIZEOF_HSWORD == 4
157 type StgWord     = Word32
158 type StgHalfWord = Word16
159 hALF_WORD = 16 :: Int
160 #elif SIZEOF_HSWORD == 8
161 type StgWord     = Word64
162 type StgHalfWord = Word32
163 hALF_WORD = 32 :: Int
164 #else
165 #error unknown SIZEOF_HSWORD
166 #endif
167 \end{code}