Haskell).
\begin{code}
+{-# LANGUAGE BangPatterns #-}
module Unique (
-- * Main data types
Unique, Uniquable(..),
pprUnique,
- mkUnique, -- Used in UniqSupply
mkUniqueGrimily, -- Used in UniqSupply only!
getKey, getKeyFastInt, -- Used in Var, UniqFM, Name only!
mkPreludeTyConUnique, mkPreludeClassUnique,
mkPArrDataConUnique,
+ mkVarOccUnique, mkDataOccUnique, mkTvOccUnique, mkTcOccUnique,
+ mkRegSingleUnique, mkRegPairUnique, mkRegClassUnique, mkRegSubUnique,
+
mkBuiltinUnique,
mkPseudoUniqueC,
mkPseudoUniqueD,
import FastTypes
import FastString
import Outputable
-import StaticFlags
+-- import StaticFlags
#if defined(__GLASGOW_HASKELL__)
--just for implementing a fast [0,61) -> Char function
The stuff about unique *supplies* is handled further down this module.
\begin{code}
-mkUnique :: Char -> Int -> Unique -- Builds a unique from pieces
unpkUnique :: Unique -> (Char, Int) -- The reverse
mkUniqueGrimily :: Int -> Unique -- A trap-door for UniqSupply
-- and as long as the Char fits in 8 bits, which we assume anyway!
+mkUnique :: Char -> Int -> Unique -- Builds a unique from pieces
+-- NOT EXPORTED, so that we can see all the Chars that
+-- are used in this one module
mkUnique c i
= MkUnique (tag `bitOrFastInt` bits)
where
\begin{code}
pprUnique :: Unique -> SDoc
pprUnique uniq
- | opt_SuppressUniques
- = empty -- Used exclusively to suppress uniques so you
- | otherwise -- can compare output easily
+-- | opt_SuppressUniques
+-- = empty -- Used exclusively to suppress uniques so you
+-- | otherwise -- can compare output easily
= case unpkUnique uniq of
(tag, u) -> finish_ppr tag u (text (iToBase62 u))
mkPrimOpIdUnique op = mkUnique '9' op
mkPreludeMiscIdUnique i = mkUnique '0' i
--- No numbers left anymore, so I pick something different for the character
--- tag
+-- No numbers left anymore, so I pick something different for the character tag
mkPArrDataConUnique a = mkUnique ':' (2*a)
-- The "tyvar uniques" print specially nicely: a, b, c, etc.
mkPseudoUniqueD i = mkUnique 'D' i -- used in NCG for getUnique on RealRegs
mkPseudoUniqueE i = mkUnique 'E' i -- used in NCG spiller to create spill VirtualRegs
mkPseudoUniqueH i = mkUnique 'H' i -- used in NCG spiller to create spill VirtualRegs
+
+mkRegSingleUnique, mkRegPairUnique, mkRegSubUnique, mkRegClassUnique :: Int -> Unique
+mkRegSingleUnique = mkUnique 'R'
+mkRegSubUnique = mkUnique 'S'
+mkRegPairUnique = mkUnique 'P'
+mkRegClassUnique = mkUnique 'L'
+
+mkVarOccUnique, mkDataOccUnique, mkTvOccUnique, mkTcOccUnique :: FastString -> Unique
+-- See Note [The Unique of an OccName] in OccName
+mkVarOccUnique fs = mkUnique 'i' (iBox (uniqueOfFS fs))
+mkDataOccUnique fs = mkUnique 'd' (iBox (uniqueOfFS fs))
+mkTvOccUnique fs = mkUnique 'v' (iBox (uniqueOfFS fs))
+mkTcOccUnique fs = mkUnique 'c' (iBox (uniqueOfFS fs))
\end{code}