X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=c%CE%BBash%2FCLasH%2FUtils%2FGhcTools.hs;h=c407436e61939553832e4b5fb66e5162edb8e892;hb=eade653c03372e3cc27e502e053b6de7d924eb64;hp=373e9cf6827f3db91f0877ef73370ec7757ff912;hpb=a54863feb7304aa6a843efc15d29f017c45407f4;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git "a/c\316\273ash/CLasH/Utils/GhcTools.hs" "b/c\316\273ash/CLasH/Utils/GhcTools.hs" index 373e9cf..c407436 100644 --- "a/c\316\273ash/CLasH/Utils/GhcTools.hs" +++ "b/c\316\273ash/CLasH/Utils/GhcTools.hs" @@ -19,6 +19,7 @@ import qualified Name import qualified Serialized import qualified Var import qualified Outputable +import qualified Class -- Local Imports import CLasH.Utils.Pretty @@ -29,13 +30,16 @@ import CLasH.Utils listBindings :: FilePath -> [FilePath] -> IO [()] listBindings libdir filenames = do (cores,_,_) <- loadModules libdir filenames Nothing - let binds = concat $ map (CoreSyn.flattenBinds . HscTypes.cm_binds) cores - mapM (listBinding) binds + let binds = concatMap (CoreSyn.flattenBinds . HscTypes.cm_binds) cores + mapM listBinding binds + putStr "\n=========================\n" + let classes = concatMap (HscTypes.typeEnvClasses . HscTypes.cm_types) cores + mapM listClass classes listBinding :: (CoreSyn.CoreBndr, CoreSyn.CoreExpr) -> IO () listBinding (b, e) = do putStr "\nBinder: " - putStr $ show b + putStr $ show b ++ "[" ++ show (Var.varUnique b) ++ "]" putStr "\nType of Binder: \n" putStr $ Outputable.showSDoc $ Outputable.ppr $ Var.varType b putStr "\n\nExpression: \n" @@ -45,13 +49,21 @@ listBinding (b, e) = do putStr "\n\nType of Expression: \n" putStr $ Outputable.showSDoc $ Outputable.ppr $ CoreUtils.exprType e putStr "\n\n" + +listClass :: Class.Class -> IO () +listClass c = do + putStr "\nClass: " + putStr $ show (Class.className c) + putStr "\nSelectors: " + putStr $ show (Class.classSelIds c) + putStr "\n" -- | Show the core structure of the given binds in the given file. listBind :: FilePath -> [FilePath] -> String -> IO () listBind libdir filenames name = do (cores,_,_) <- loadModules libdir filenames Nothing bindings <- concatM $ mapM (findBinder (hasVarName name)) cores - mapM listBinding bindings + mapM_ listBinding bindings return () -- Change a DynFlag from within the Ghc monad. Strangely enough there seems to @@ -71,7 +83,7 @@ setDynFlag dflag = do -- just return an IO monad when they are evaluated). unsafeRunGhc :: FilePath -> GHC.Ghc a -> a unsafeRunGhc libDir m = - System.IO.Unsafe.unsafePerformIO $ do + System.IO.Unsafe.unsafePerformIO $ GHC.runGhc (Just libDir) $ do dflags <- GHC.getSessionDynFlags GHC.setSessionDynFlags dflags @@ -87,7 +99,7 @@ loadModules :: , [EntitySpec] ) -- ^ ( The loaded modules, the resulting ghc environment, the entities to build) loadModules libdir filenames finder = - GHC.defaultErrorHandler DynFlags.defaultDynFlags $ do + GHC.defaultErrorHandler DynFlags.defaultDynFlags $ GHC.runGhc (Just libdir) $ do dflags <- GHC.getSessionDynFlags GHC.setSessionDynFlags dflags @@ -129,7 +141,7 @@ findExprs criteria core = do binders <- findBinder criteria core case binders of [] -> return Nothing - bndrs -> return $ Just $ (map snd bndrs) + bndrs -> return $ Just (map snd bndrs) findExpr :: Monad m => @@ -162,8 +174,7 @@ findBinder :: -> m [(CoreSyn.CoreBndr, CoreSyn.CoreExpr)] -- ^ The binders to meet the criteria findBinder criteria core = do let binds = CoreSyn.flattenBinds $ HscTypes.cm_binds core - critbinds <- Monad.filterM (criteria . fst) binds - return critbinds + Monad.filterM (criteria . fst) binds -- | Determine if a binder has an Annotation meeting a certain criteria isCLasHAnnotation :: @@ -196,7 +207,7 @@ hasVarName :: String -- ^ The name the binder has to have -> Var.Var -- ^ The Binder -> m Bool -- ^ Indicate if the binder has the name -hasVarName lookfor bind = return $ lookfor == (Name.occNameString $ Name.nameOccName $ Name.getName bind) +hasVarName lookfor bind = return $ lookfor == Name.occNameString (Name.nameOccName $ Name.getName bind) findInitStates :: @@ -217,9 +228,9 @@ findInitStates statec annsc mod = do extractInits (InitState x) = Just x extractInits _ = Nothing zipMWith :: (a -> b -> c) -> (Maybe [a]) -> [b] -> (Maybe [c]) - zipMwith _ Nothing _ = Nothing + zipMWith _ Nothing _ = Nothing zipMWith f (Just as) bs = Just $ zipWith f as bs - + -- | Make a complete spec out of a three conditions findSpec :: (Var.Var -> GHC.Ghc Bool) -> (Var.Var -> GHC.Ghc Bool) -> (Var.Var -> GHC.Ghc [CLasHAnn]) -> (Var.Var -> GHC.Ghc Bool)