Fix warnings: Remove unused imports
[ghc-hetmet.git] / compiler / vectorise / Vectorise / Monad / Naming.hs
1
2 -- | Computations in the vectorisation monad concerned with naming
3 --   and fresh variable generation.
4 module Vectorise.Monad.Naming
5         ( cloneName
6         , cloneId
7         , cloneVar
8         , newExportedVar
9         , newLocalVar
10         , newLocalVars
11         , newDummyVar
12         , newTyVar)
13 where
14 import Vectorise.Monad.Base
15
16 import DsMonad
17 import Type
18 import Var
19 import Name
20 import SrcLoc
21 import Id
22 import FastString
23 import Control.Monad
24
25
26 -- Naming --------------------------------------------------------------------- 
27 -- | Clone a name, using the provide function to transform its `OccName`.       
28 cloneName :: (OccName -> OccName) -> Name -> VM Name
29 cloneName mk_occ name = liftM make (liftDs newUnique)
30   where
31     occ_name = mk_occ (nameOccName name)
32
33     make u | isExternalName name = mkExternalName u (nameModule name)
34                                                     occ_name
35                                                     (nameSrcSpan name)
36            | otherwise           = mkSystemName u occ_name
37
38
39 -- | Clone an `Id`, using the provided function to transform its `OccName`. 
40 cloneId :: (OccName -> OccName) -> Id -> Type -> VM Id
41 cloneId mk_occ id ty
42   = do
43       name <- cloneName mk_occ (getName id)
44       let id' | isExportedId id = Id.mkExportedLocalId name ty
45               | otherwise       = Id.mkLocalId         name ty
46       return id'
47
48
49 -- | Make a fresh instance of this var, with a new unique.
50 cloneVar :: Var -> VM Var
51 cloneVar var = liftM (setIdUnique var) (liftDs newUnique)
52
53
54 -- | Make a fresh exported variable with the given type.
55 newExportedVar :: OccName -> Type -> VM Var
56 newExportedVar occ_name ty 
57  = do mod <- liftDs getModuleDs
58       u   <- liftDs newUnique
59
60       let name = mkExternalName u mod occ_name noSrcSpan
61       
62       return $ Id.mkExportedLocalId name ty
63
64
65 -- | Make a fresh local variable with the given type.
66 --   The variable's name is formed using the given string as the prefix.
67 newLocalVar :: FastString -> Type -> VM Var
68 newLocalVar fs ty
69  = do u <- liftDs newUnique
70       return $ mkSysLocal fs u ty
71
72
73 -- | Make several fresh local varaiables with the given types.
74 --   The variable's names are formed using the given string as the prefix.
75 newLocalVars :: FastString -> [Type] -> VM [Var]
76 newLocalVars fs = mapM (newLocalVar fs)
77
78
79 -- | Make a new local dummy variable.
80 newDummyVar :: Type -> VM Var
81 newDummyVar = newLocalVar (fsLit "vv")
82
83
84 -- | Make a fresh type variable with the given kind.
85 --   The variable's name is formed using the given string as the prefix.
86 newTyVar :: FastString -> Kind -> VM Var
87 newTyVar fs k
88  = do u <- liftDs newUnique
89       return $ mkTyVar (mkSysTvName u fs) k
90