7ea1d40b5efd27a3d9cc5431c858b48053e2c898
[ghc-hetmet.git] / compiler / cmm / CmmCPSData.hs
1 module CmmCPSData (
2   blocksToBlockEnv,
3   BrokenBlock(..),
4   BlockEntryInfo(..),
5   FinalStmt(..)
6   ) where
7
8 #include "HsVersions.h"
9
10 import Cmm
11 import CLabel
12
13 import UniqFM
14
15 -- A minor helper (TODO document)
16 blocksToBlockEnv :: [BrokenBlock] -> BlockEnv BrokenBlock
17 blocksToBlockEnv blocks = listToUFM $ map (\b -> (brokenBlockId b, b)) blocks
18
19 data BrokenBlock
20   = BrokenBlock {
21       brokenBlockId :: BlockId, -- Like a CmmBasicBlock
22       brokenBlockEntry :: BlockEntryInfo,
23                                 -- How this block can be entered
24
25       brokenBlockStmts :: [CmmStmt],
26                                 -- Like a CmmBasicBlock
27                                 -- (but without the last statement)
28
29       brokenBlockTargets :: [BlockId],
30                                 -- Blocks that this block could
31                                 -- branch to one either by conditional
32                                 -- branches or via the last statement
33
34       brokenBlockExit :: FinalStmt
35                                 -- How the block can be left
36     }
37
38 data BlockEntryInfo
39   = FunctionEntry               -- Beginning of a function
40       CLabel                    -- The function name
41       CmmFormals                -- Aguments to function
42
43   | ContinuationEntry           -- Return point of a call
44       CmmFormals                -- return values (argument to continuation)
45   -- TODO:
46   -- | ProcPointEntry -- no return values, but some live might end up as params or possibly in the frame
47
48   | ControlEntry                -- A label in the input
49
50 -- Final statement in a BlokenBlock
51 -- Constructors and arguments match those in Cmm,
52 -- but are restricted to branches, returns, jumps, calls and switches
53 data FinalStmt
54   = FinalBranch
55       BlockId -- next block (must be a ControlEntry)
56
57   | FinalReturn
58       CmmActuals -- return values
59
60   | FinalJump
61       CmmExpr -- the function to call
62       CmmActuals -- arguments to call
63
64   | FinalCall
65       BlockId -- next block after call (must be a ContinuationEntry)
66       CmmCallTarget -- the function to call
67       CmmFormals -- results from call (redundant with ContinuationEntry)
68       CmmActuals -- arguments to call
69       (Maybe [GlobalReg]) -- registers that must be saved (TODO)
70
71   | FinalSwitch
72       CmmExpr [Maybe BlockId]   -- Table branch
73
74   -- TODO: | ProcPointExit (needed?)