compiler: introduce custom "GhcPrelude" Prelude
[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 GhcPrelude
12
13 import CLabel
14 import IdInfo
15 import Name
16 import Unique
17 import UniqSupply
18
19 import Hoopl.Label (Label, uniqueToLbl)
20 import Hoopl.Unique (intToUnique)
21
22 ----------------------------------------------------------------
23 --- Block Ids, their environments, and their sets
24
25 {- Note [Unique BlockId]
26 ~~~~~~~~~~~~~~~~~~~~~~~~
27 Although a 'BlockId' is a local label, for reasons of implementation,
28 'BlockId's must be unique within an entire compilation unit. The reason
29 is that each local label is mapped to an assembly-language label, and in
30 most assembly languages allow, a label is visible throughout the entire
31 compilation unit in which it appears.
32 -}
33
34 type BlockId = Label
35
36 mkBlockId :: Unique -> BlockId
37 mkBlockId unique = uniqueToLbl $ intToUnique $ getKey unique
38
39 newBlockId :: MonadUnique m => m BlockId
40 newBlockId = mkBlockId <$> getUniqueM
41
42 blockLbl :: BlockId -> CLabel
43 blockLbl label = mkAsmTempLabel (getUnique label)
44
45 infoTblLbl :: BlockId -> CLabel
46 infoTblLbl label = mkInfoTableLabel (mkFCallName (getUnique label) "block") NoCafRefs