d59cbd08e46a82a396ae3feb4fdf8bdbfda7f3fa
[ghc.git] / compiler / cmm / BlockId.hs
1 {-# LANGUAGE TypeSynonymInstances #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
3
4 {- BlockId module should probably go away completely, being superseded by Label -}
5 module BlockId
6 ( BlockId, mkBlockId -- ToDo: BlockId should be abstract, but it isn't yet
7 , newBlockId
8 , blockLbl, infoTblLbl
9 ) where
10
11 import CLabel
12 import IdInfo
13 import Name
14 import Outputable
15 import Unique
16 import UniqSupply
17
18 import Compiler.Hoopl as Hoopl hiding (Unique)
19 import Compiler.Hoopl.Internals (uniqueToLbl, lblToUnique)
20
21 ----------------------------------------------------------------
22 --- Block Ids, their environments, and their sets
23
24 {- Note [Unique BlockId]
25 ~~~~~~~~~~~~~~~~~~~~~~~~
26 Although a 'BlockId' is a local label, for reasons of implementation,
27 'BlockId's must be unique within an entire compilation unit. The reason
28 is that each local label is mapped to an assembly-language label, and in
29 most assembly languages allow, a label is visible throughout the entire
30 compilation unit in which it appears.
31 -}
32
33 type BlockId = Hoopl.Label
34
35 instance Uniquable BlockId where
36 getUnique label = getUnique (lblToUnique label)
37
38 instance Outputable BlockId where
39 ppr label = ppr (getUnique label)
40
41 mkBlockId :: Unique -> BlockId
42 mkBlockId unique = uniqueToLbl $ intToUnique $ getKey unique
43
44 newBlockId :: MonadUnique m => m BlockId
45 newBlockId = mkBlockId <$> getUniqueM
46
47 blockLbl :: BlockId -> CLabel
48 blockLbl label = mkEntryLabel (mkFCallName (getUnique label) "block") NoCafRefs
49
50 infoTblLbl :: BlockId -> CLabel
51 infoTblLbl label = mkInfoTableLabel (mkFCallName (getUnique label) "block") NoCafRefs