module Vectorise.Monad.Naming
( cloneName
, cloneId
, cloneVar
, newExportedVar
, newLocalVar
, newLocalVars
, newDummyVar
, newTyVar)
where
import Vectorise.Monad.Base
import DsMonad
import Type
import Var
import Name
import SrcLoc
import Id
import FastString
import Control.Monad
cloneName :: (OccName -> OccName) -> Name -> VM Name
cloneName mk_occ name = liftM make (liftDs newUnique)
where
occ_name = mk_occ (nameOccName name)
make u | isExternalName name = mkExternalName u (nameModule name)
occ_name
(nameSrcSpan name)
| otherwise = mkSystemName u occ_name
cloneId :: (OccName -> OccName) -> Id -> Type -> VM Id
cloneId mk_occ id ty
= do
name <- cloneName mk_occ (getName id)
let id' | isExportedId id = Id.mkExportedLocalId name ty
| otherwise = Id.mkLocalId name ty
return id'
cloneVar :: Var -> VM Var
cloneVar var = liftM (setIdUnique var) (liftDs newUnique)
newExportedVar :: OccName -> Type -> VM Var
newExportedVar occ_name ty
= do mod <- liftDs getModuleDs
u <- liftDs newUnique
let name = mkExternalName u mod occ_name noSrcSpan
return $ Id.mkExportedLocalId name ty
newLocalVar :: FastString -> Type -> VM Var
newLocalVar fs ty
= do u <- liftDs newUnique
return $ mkSysLocal fs u ty
newLocalVars :: FastString -> [Type] -> VM [Var]
newLocalVars fs = mapM (newLocalVar fs)
newDummyVar :: Type -> VM Var
newDummyVar = newLocalVar (fsLit "vv")
newTyVar :: FastString -> Kind -> VM Var
newTyVar fs k
= do u <- liftDs newUnique
return $ mkTyVar (mkSysTvName u fs) k