From a9ef23ae9e5448c48ca4ee3113fd957cef3b6ca3 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 12 Aug 2009 16:14:50 +0200 Subject: [PATCH] Add isStateCon helper. --- "c\316\273ash/CLasH/Utils/Core/CoreTools.hs" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 -- 2.30.2