BlockId.hs 1.34 KB
Newer Older
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 10
  ) where

11 12
import GhcPrelude

13 14 15
import CLabel
import IdInfo
import Name
16
import Unique
17
import UniqSupply
18

19 20
import Hoopl.Label (Label, uniqueToLbl)
import Hoopl.Unique (intToUnique)
21 22 23 24 25 26 27 28 29

----------------------------------------------------------------
--- Block Ids, their environments, and their sets

{- Note [Unique BlockId]
~~~~~~~~~~~~~~~~~~~~~~~~
Although a 'BlockId' is a local label, for reasons of implementation,
'BlockId's must be unique within an entire compilation unit.  The reason
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 32 33
compilation unit in which it appears.
-}

34
type BlockId = Label
35

36
mkBlockId :: Unique -> BlockId
37
mkBlockId unique = uniqueToLbl $ intToUnique $ getKey unique
38

39 40 41
newBlockId :: MonadUnique m => m BlockId
newBlockId = mkBlockId <$> getUniqueM

42
blockLbl :: BlockId -> CLabel
43
blockLbl label = mkLocalBlockLabel (getUnique label)
44 45

infoTblLbl :: BlockId -> CLabel
46 47
infoTblLbl label
  = mkBlockInfoTableLabel (mkFCallName (getUnique label) "block") NoCafRefs