X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=c%CE%BBash%2FCLasH%2FUtils%2FCore%2FCoreTools.hs;h=48ca948c3baf39dfc4edc97ea7fd578ff6d48999;hb=aa2503aeb4cfa5540633db2cdd50bea20b5f1c50;hp=7377c9e36ce332e14c04f2a6cde234e47bf8eb95;hpb=82210ea1ed3bbf1acd5cecef5bc0771e36613bf5;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git "a/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" "b/c\316\273ash/CLasH/Utils/Core/CoreTools.hs" index 7377c9e..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 @@ -36,6 +38,7 @@ import qualified CoreFVs import qualified Literal -- Local imports +import CLasH.Translator.TranslatorTypes import CLasH.Utils.GhcTools import CLasH.Utils.HsTools import CLasH.Utils.Pretty @@ -222,16 +225,52 @@ getLiterals app@(CoreSyn.App _ _) = literals getLiterals lit@(CoreSyn.Lit _) = [lit] -reduceCoreListToHsList :: CoreSyn.CoreExpr -> [CoreSyn.CoreExpr] -reduceCoreListToHsList app@(CoreSyn.App _ _) = out +reduceCoreListToHsList :: + [HscTypes.CoreModule] -- ^ The modules where parts of the list are hidden + -> CoreSyn.CoreExpr -- ^ The refence to atleast one of the nodes + -> TranslatorSession [CoreSyn.CoreExpr] +reduceCoreListToHsList cores app@(CoreSyn.App _ _) = do { + ; let { (fun, args) = CoreSyn.collectArgs app + ; len = length args + } ; + ; case len of + 3 -> do { + ; let topelem = args!!1 + ; case (args!!2) of + (varz@(CoreSyn.Var id)) -> do { + ; binds <- mapM (findExpr (isVarName id)) cores + ; otherelems <- reduceCoreListToHsList cores (head (Maybe.catMaybes binds)) + ; return (topelem:otherelems) + } + (appz@(CoreSyn.App _ _)) -> do { + ; otherelems <- reduceCoreListToHsList cores appz + ; return (topelem:otherelems) + } + otherwise -> return [topelem] + } + otherwise -> return [] + } where - (fun, args) = CoreSyn.collectArgs app - len = length args - out = case len of - 3 -> ((args!!1) : (reduceCoreListToHsList (args!!2))) - otherwise -> [] - -reduceCoreListToHsList _ = [] + isVarName :: Monad m => Var.Var -> Var.Var -> m Bool + isVarName lookfor bind = return $ (Var.varName lookfor) == (Var.varName bind) + +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