BlockId == Int now
[ghc.git] / compiler / cmm / BlockId.hs
1 {- BlockId module should probably go away completely, being superseded by Label -}
2 module BlockId
3 ( BlockId, mkBlockId -- ToDo: BlockId should be abstract, but it isn't yet
4 , BlockSet, BlockEnv
5 , IsSet(..), setInsertList, setDeleteList, setUnions
6 , IsMap(..), mapInsertList, mapDeleteList, mapUnions
7 , emptyBlockSet, emptyBlockMap
8 , blockLbl, infoTblLbl, retPtLbl
9 ) where
10
11 import CLabel
12 import IdInfo
13 import Name
14 import Outputable
15 import Unique
16
17 import Compiler.Hoopl as Hoopl hiding (Unique)
18 import Compiler.Hoopl.GHC (uniqueToInt, uniqueToLbl, lblToUnique)
19
20 ----------------------------------------------------------------
21 --- Block Ids, their environments, and their sets
22
23 {- Note [Unique BlockId]
24 ~~~~~~~~~~~~~~~~~~~~~~~~
25 Although a 'BlockId' is a local label, for reasons of implementation,
26 'BlockId's must be unique within an entire compilation unit. The reason
27 is that each local label is mapped to an assembly-language label, and in
28 most assembly languages allow, a label is visible throughout the entire
29 compilation unit in which it appears.
30 -}
31
32 type BlockId = Hoopl.Label
33
34 mkBlockId :: Unique -> BlockId
35 mkBlockId unique = uniqueToLbl $ intToUnique $ getKey unique
36
37 retPtLbl :: BlockId -> CLabel
38 retPtLbl label = mkReturnPtLabel $ getUnique label
39
40 blockLbl :: BlockId -> CLabel
41 blockLbl label = mkEntryLabel (mkFCallName (getUnique label) "block") NoCafRefs
42
43 infoTblLbl :: BlockId -> CLabel
44 infoTblLbl label = mkInfoTableLabel (mkFCallName (getUnique label) "block") NoCafRefs
45
46 -- Block environments: Id blocks
47 type BlockEnv a = Hoopl.LabelMap a
48
49 instance Outputable a => Outputable (BlockEnv a) where
50 ppr = ppr . mapToList
51
52 emptyBlockMap :: BlockEnv a
53 emptyBlockMap = mapEmpty
54
55 -- Block sets
56 type BlockSet = Hoopl.LabelSet
57
58 instance Outputable BlockSet where
59 ppr = ppr . setElems
60
61 emptyBlockSet :: BlockSet
62 emptyBlockSet = setEmpty