Renaming only
[ghc.git] / compiler / cmm / Cmm.hs
1 -- Cmm representations using Hoopl's Graph CmmNode e x.
2 {-# LANGUAGE GADTs #-}
3 {-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
4
5 {-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
6 #if __GLASGOW_HASKELL__ >= 703
7 -- GHC 7.0.1 improved incomplete pattern warnings with GADTs
8 {-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
9 #endif
10
11 module Cmm (
12 -- * Cmm top-level datatypes
13 CmmProgram, CmmGroup, GenCmmGroup,
14 CmmDecl, GenCmmDecl(..),
15 CmmGraph, GenCmmGraph(..),
16 CmmBlock,
17 Section(..), CmmStatics(..), CmmStatic(..),
18
19 -- * Cmm graphs
20 CmmReplGraph, GenCmmReplGraph, CmmFwdRewrite, CmmBwdRewrite,
21
22 -- * Info Tables
23 CmmTopInfo(..), CmmStackInfo(..), CmmInfoTable(..),
24 ClosureTypeInfo(..),
25 C_SRT(..), needsSRT,
26 ProfilingInfo(..), ConstrDescription,
27
28 -- * Statements, expressions and types
29 module CmmNode,
30 module CmmExpr,
31 ) where
32
33 import CLabel
34 import BlockId
35 import CmmNode
36 import OptimizationFuel as F
37 import SMRep
38 import CmmExpr
39 import Compiler.Hoopl
40
41 import Data.Word ( Word8 )
42
43 #include "HsVersions.h"
44
45 -----------------------------------------------------------------------------
46 -- Cmm, GenCmm
47 -----------------------------------------------------------------------------
48
49 -- A CmmProgram is a list of CmmGroups
50 -- A CmmGroup is a list of top-level declarations
51
52 -- When object-splitting is on,each group is compiled into a separate
53 -- .o file. So typically we put closely related stuff in a CmmGroup.
54
55 type CmmProgram = [CmmGroup]
56
57 type GenCmmGroup d h g = [GenCmmDecl d h g]
58 type CmmGroup = GenCmmGroup CmmStatics CmmTopInfo CmmGraph
59
60 -----------------------------------------------------------------------------
61 -- CmmDecl, GenCmmDecl
62 -----------------------------------------------------------------------------
63
64 -- GenCmmDecl is abstracted over
65 -- d, the type of static data elements in CmmData
66 -- h, the static info preceding the code of a CmmProc
67 -- g, the control-flow graph of a CmmProc
68 --
69 -- We expect there to be two main instances of this type:
70 -- (a) C--, i.e. populated with various C-- constructs
71 -- (Cmm and RawCmm in OldCmm.hs)
72 -- (b) Native code, populated with data/instructions
73 --
74 -- A second family of instances based on Hoopl is in Cmm.hs.
75
76 -- | A top-level chunk, abstracted over the type of the contents of
77 -- the basic blocks (Cmm or instructions are the likely instantiations).
78 data GenCmmDecl d h g
79 = CmmProc -- A procedure
80 h -- Extra header such as the info table
81 CLabel -- Entry label
82 g -- Control-flow graph for the procedure's code
83
84 | CmmData -- Static data
85 Section
86 d
87
88 type CmmDecl = GenCmmDecl CmmStatics CmmTopInfo CmmGraph
89
90 -----------------------------------------------------------------------------
91 -- Graphs
92 -----------------------------------------------------------------------------
93
94 type CmmGraph = GenCmmGraph CmmNode
95 data GenCmmGraph n = CmmGraph { g_entry :: BlockId, g_graph :: Graph n C C }
96 type CmmBlock = Block CmmNode C C
97
98 type CmmReplGraph e x = GenCmmReplGraph CmmNode e x
99 type GenCmmReplGraph n e x = FuelUniqSM (Maybe (Graph n e x))
100 type CmmFwdRewrite f = FwdRewrite FuelUniqSM CmmNode f
101 type CmmBwdRewrite f = BwdRewrite FuelUniqSM CmmNode f
102
103 -----------------------------------------------------------------------------
104 -- Info Tables
105 -----------------------------------------------------------------------------
106
107 data CmmTopInfo = TopInfo {info_tbl :: CmmInfoTable, stack_info :: CmmStackInfo}
108
109 data CmmStackInfo
110 = StackInfo {
111 arg_space :: ByteOff, -- XXX: comment?
112 updfr_space :: Maybe ByteOff -- XXX: comment?
113 }
114
115 -- | Info table as a haskell data type
116 data CmmInfoTable
117 = CmmInfoTable {
118 cit_lbl :: CLabel, -- Info table label
119 cit_rep :: SMRep,
120 cit_prof :: ProfilingInfo,
121 cit_srt :: C_SRT
122 }
123 | CmmNonInfoTable -- Procedure doesn't need an info table
124
125 data ProfilingInfo
126 = NoProfilingInfo
127 | ProfilingInfo [Word8] [Word8] -- closure_type, closure_desc
128
129 -- C_SRT is what StgSyn.SRT gets translated to...
130 -- we add a label for the table, and expect only the 'offset/length' form
131
132 data C_SRT = NoC_SRT
133 | C_SRT !CLabel !WordOff !StgHalfWord {-bitmap or escape-}
134 deriving (Eq)
135
136 needsSRT :: C_SRT -> Bool
137 needsSRT NoC_SRT = False
138 needsSRT (C_SRT _ _ _) = True
139
140 -----------------------------------------------------------------------------
141 -- Static Data
142 -----------------------------------------------------------------------------
143
144 data Section
145 = Text
146 | Data
147 | ReadOnlyData
148 | RelocatableReadOnlyData
149 | UninitialisedData
150 | ReadOnlyData16 -- .rodata.cst16 on x86_64, 16-byte aligned
151 | OtherSection String
152
153 data CmmStatic
154 = CmmStaticLit CmmLit
155 -- a literal value, size given by cmmLitRep of the literal.
156 | CmmUninitialised Int
157 -- uninitialised data, N bytes long
158 | CmmString [Word8]
159 -- string of 8-bit values only, not zero terminated.
160
161 data CmmStatics
162 = Statics
163 CLabel -- Label of statics
164 [CmmStatic] -- The static data itself
165