From: Matthijs Kooijman Date: Wed, 12 Aug 2009 14:14:50 +0000 (+0200) Subject: Add isStateCon helper. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;ds=inline;h=a9ef23ae9e5448c48ca4ee3113fd957cef3b6ca3;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Add isStateCon helper. --- diff --git "a/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" "b/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" index e3021ad..48ca948 100644 --- "a/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" +++ "b/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" @@ -23,12 +23,14 @@ import qualified OccName import qualified Type import qualified Id import qualified TyCon +import qualified DataCon import qualified TysWiredIn import qualified Bag import qualified DynFlags import qualified SrcLoc import qualified CoreSyn import qualified Var +import qualified IdInfo import qualified VarSet import qualified Unique import qualified CoreUtils @@ -254,6 +256,22 @@ reduceCoreListToHsList cores app@(CoreSyn.App _ _) = do { reduceCoreListToHsList _ _ = return [] +-- Is the given var the State data constructor? +isStateCon :: Var.Var -> Bool +isStateCon var = do + -- See if it is a DataConWrapId (not DataConWorkId, since State is a + -- newtype). + case Id.idDetails var of + IdInfo.DataConWrapId dc -> + -- See if the datacon is the State datacon from the State type. + let tycon = DataCon.dataConTyCon dc + tyname = Name.getOccString tycon + dcname = Name.getOccString dc + in case (tyname, dcname) of + ("State", "State") -> True + _ -> False + _ -> False + -- | Is the given type a State type? isStateType :: Type.Type -> Bool -- Resolve any type synonyms remaining