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