root/compiler/cmm/Cmm.hs

Revision d6705e972b905f5034bdc3e0b2fca65f9be33b22, 5.1 KB (checked in by Iavor S. Diatchki <iavor.diatchki@…>, 5 months ago)

Remove tabs, so that I can push.

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