update submodules for GHC.HetMet.GArrow -> Control.GArrow renaming
[ghc-hetmet.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         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            -- Used to generate both info & entry labels
59      g                 -- Control-flow graph for the procedure's code
60
61   | CmmData     -- Static data
62         Section
63         [d]
64
65
66 -- A basic block containing a single label, at the beginning.
67 -- The list of basic blocks in a top-level code block may be re-ordered.
68 -- Fall-through is not allowed: there must be an explicit jump at the
69 -- end of each basic block, but the code generator might rearrange basic
70 -- blocks in order to turn some jumps into fallthroughs.
71
72
73 -----------------------------------------------------------------------------
74 --     Info Tables
75 -----------------------------------------------------------------------------
76
77 -- Info table as a haskell data type
78 data CmmInfoTable
79   = CmmInfoTable
80       HasStaticClosure
81       ProfilingInfo
82       ClosureTypeTag -- Int
83       ClosureTypeInfo
84   | CmmNonInfoTable   -- Procedure doesn't need an info table
85
86 type HasStaticClosure = Bool
87
88 -- TODO: The GC target shouldn't really be part of CmmInfo
89 -- as it doesn't appear in the resulting info table.
90 -- It should be factored out.
91
92 data ClosureTypeInfo
93   = ConstrInfo ClosureLayout ConstrTag ConstrDescription
94   | FunInfo    ClosureLayout C_SRT FunArity ArgDescr SlowEntry
95   | ThunkInfo  ClosureLayout C_SRT
96   | ThunkSelectorInfo SelectorOffset C_SRT
97   | ContInfo
98       [Maybe LocalReg]  -- Stack layout: Just x, an item x
99                         --               Nothing: a 1-word gap
100                         -- Start of list is the *young* end
101       C_SRT
102
103 -- TODO: These types may need refinement
104 data ProfilingInfo = ProfilingInfo CmmLit CmmLit -- closure_type, closure_desc
105 type ClosureTypeTag = StgHalfWord
106 type ClosureLayout = (StgHalfWord, StgHalfWord) -- ptrs, nptrs
107 type ConstrTag = StgHalfWord
108 type ConstrDescription = CmmLit
109 type FunArity = StgHalfWord
110 type SlowEntry = CmmLit
111   -- We would like this to be a CLabel but
112   -- for now the parser sets this to zero on an INFO_TABLE_FUN.
113 type SelectorOffset = StgWord
114
115 type CmmActual = CmmExpr
116 type CmmFormal = LocalReg
117
118 data ForeignHint
119   = NoHint | AddrHint | SignedHint
120   deriving( Eq )
121         -- Used to give extra per-argument or per-result
122         -- information needed by foreign calling conventions
123
124 -----------------------------------------------------------------------------
125 --              Static Data
126 -----------------------------------------------------------------------------
127
128 data Section
129   = Text
130   | Data
131   | ReadOnlyData
132   | RelocatableReadOnlyData
133   | UninitialisedData
134   | ReadOnlyData16      -- .rodata.cst16 on x86_64, 16-byte aligned
135   | OtherSection String
136
137 data CmmStatic
138   = CmmStaticLit CmmLit
139         -- a literal value, size given by cmmLitRep of the literal.
140   | CmmUninitialised Int
141         -- uninitialised data, N bytes long
142   | CmmAlign Int
143         -- align to next N-byte boundary (N must be a power of 2).
144   | CmmDataLabel CLabel
145         -- label the current position in this section.
146   | CmmString [Word8]
147         -- string of 8-bit values only, not zero terminated.
148