552878e7bba4220cf330f1c4b1b0424cf8477ce6
[ghc.git] / compiler / cmm / CmmDecl.hs
1 -----------------------------------------------------------------------------
2 --
3 -- Cmm data types
4 --
5 -- (c) The University of Glasgow 2004-2006
6 --
7 -----------------------------------------------------------------------------
8
9 module CmmDecl (
10 GenCmm(..), GenCmmTop(..),
11 CmmInfoTable(..), HasStaticClosure, ClosureTypeInfo(..), ConstrDescription,
12 ProfilingInfo(..), ClosureTypeTag,
13 CmmActual, CmmFormal, ForeignHint(..),
14 CmmStatics(..), CmmStatic(..), Section(..),
15 ) where
16
17 #include "HsVersions.h"
18
19 import CmmExpr
20 import CLabel
21 import SMRep
22 import ClosureInfo
23
24 import Data.Word
25
26
27 -- A [[BlockId]] is a local label.
28 -- Local labels must be unique within an entire compilation unit, not
29 -- just a single top-level item, because local labels map one-to-one
30 -- with assembly-language labels.
31
32 -----------------------------------------------------------------------------
33 -- GenCmm, GenCmmTop
34 -----------------------------------------------------------------------------
35
36 -- A file is a list of top-level chunks. These may be arbitrarily
37 -- re-orderd during code generation.
38
39 -- GenCmm is abstracted over
40 -- d, the type of static data elements in CmmData
41 -- h, the static info preceding the code of a CmmProc
42 -- g, the control-flow graph of a CmmProc
43 --
44 -- We expect there to be two main instances of this type:
45 -- (a) C--, i.e. populated with various C-- constructs
46 -- (Cmm and RawCmm in OldCmm.hs)
47 -- (b) Native code, populated with data/instructions
48 --
49 -- A second family of instances based on Hoopl is in Cmm.hs.
50 --
51 newtype GenCmm d h g = Cmm [GenCmmTop d h g]
52
53 -- | A top-level chunk, abstracted over the type of the contents of
54 -- the basic blocks (Cmm or instructions are the likely instantiations).
55 data GenCmmTop d h g
56 = CmmProc -- A procedure
57 h -- Extra header such as the info table
58 CLabel -- Entry label
59 g -- Control-flow graph for the procedure's code
60
61 | CmmData -- Static data
62 Section
63 d
64
65
66 -----------------------------------------------------------------------------
67 -- Info Tables
68 -----------------------------------------------------------------------------
69
70 -- Info table as a haskell data type
71 data CmmInfoTable
72 = CmmInfoTable
73 CLabel -- Info table label
74 HasStaticClosure
75 ProfilingInfo
76 ClosureTypeTag -- Int
77 ClosureTypeInfo
78 | CmmNonInfoTable -- Procedure doesn't need an info table
79
80 type HasStaticClosure = Bool
81
82 -- TODO: The GC target shouldn't really be part of CmmInfo
83 -- as it doesn't appear in the resulting info table.
84 -- It should be factored out.
85
86 data ClosureTypeInfo
87 = ConstrInfo ClosureLayout ConstrTag ConstrDescription
88 | FunInfo ClosureLayout C_SRT FunArity ArgDescr SlowEntry
89 | ThunkInfo ClosureLayout C_SRT
90 | ThunkSelectorInfo SelectorOffset C_SRT
91 | ContInfo
92 [Maybe LocalReg] -- Stack layout: Just x, an item x
93 -- Nothing: a 1-word gap
94 -- Start of list is the *young* end
95 C_SRT
96
97 -- TODO: These types may need refinement
98 data ProfilingInfo = ProfilingInfo CmmLit CmmLit -- closure_type, closure_desc
99 type ClosureTypeTag = StgHalfWord
100 type ClosureLayout = (StgHalfWord, StgHalfWord) -- ptrs, nptrs
101 type ConstrTag = StgHalfWord
102 type ConstrDescription = CmmLit
103 type FunArity = StgHalfWord
104 type SlowEntry = CmmLit
105 -- We would like this to be a CLabel but
106 -- for now the parser sets this to zero on an INFO_TABLE_FUN.
107 type SelectorOffset = StgWord
108
109 type CmmActual = CmmExpr
110 type CmmFormal = LocalReg
111
112 data ForeignHint
113 = NoHint | AddrHint | SignedHint
114 deriving( Eq )
115 -- Used to give extra per-argument or per-result
116 -- information needed by foreign calling conventions
117
118 -----------------------------------------------------------------------------
119 -- Static Data
120 -----------------------------------------------------------------------------
121
122 data Section
123 = Text
124 | Data
125 | ReadOnlyData
126 | RelocatableReadOnlyData
127 | UninitialisedData
128 | ReadOnlyData16 -- .rodata.cst16 on x86_64, 16-byte aligned
129 | OtherSection String
130
131 data CmmStatic
132 = CmmStaticLit CmmLit
133 -- a literal value, size given by cmmLitRep of the literal.
134 | CmmUninitialised Int
135 -- uninitialised data, N bytes long
136 | CmmString [Word8]
137 -- string of 8-bit values only, not zero terminated.
138
139 data CmmStatics = Statics CLabel {- Label of statics -} [CmmStatic] {- The static data itself -}