X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=c%CE%BBash%2FCLasH%2FTranslator.hs;h=6177dabaca9fc069374da39caf6995e4f8c69ba7;hb=e1ef152dc63f28dddce2de4950ec739c79c8d18f;hp=04b7beb0900b14950dec9f5f0f00bc5454635666;hpb=f3951a1376fc7d7f8addbe9e9fed071320502100;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git "a/c\316\273ash/CLasH/Translator.hs" "b/c\316\273ash/CLasH/Translator.hs" index 04b7beb..6177dab 100644 --- "a/c\316\273ash/CLasH/Translator.hs" +++ "b/c\316\273ash/CLasH/Translator.hs" @@ -12,6 +12,8 @@ import qualified Control.Monad.Trans.State as State import Text.PrettyPrint.HughesPJ (render) import Data.Accessor.Monad.Trans.State import qualified Data.Map as Map +import qualified Data.Time.Clock as Clock +import Debug.Trace -- GHC API import qualified CoreSyn @@ -32,23 +34,6 @@ import CLasH.VHDL import CLasH.VHDL.VHDLTools import CLasH.VHDL.Testbench --- | Turn Haskell to VHDL, Usings Strings to indicate the Top Entity, Initial --- State and Test Inputs. --- makeVHDLStrings :: --- FilePath -- ^ The GHC Library Dir --- -> [FilePath] -- ^ The FileNames --- -> String -- ^ The TopEntity --- -> String -- ^ The InitState --- -> String -- ^ The TestInput --- -> IO () --- makeVHDLStrings libdir filenames topentity initstate testinput = do --- makeVHDL libdir filenames finder --- where --- finder = findSpec (hasVarName topentity) --- (hasVarName initstate) --- (isCLasHAnnotation isInitState) --- (hasVarName testinput) - -- | Turn Haskell to VHDL, Using the Annotations for Top Entity, Initial State -- and Test Inputs found in the Files. makeVHDLAnnotations :: @@ -71,6 +56,7 @@ makeVHDL :: -> Finder -> IO () makeVHDL libdir filenames finder = do + start <- Clock.getCurrentTime -- Load the modules (cores, env, specs) <- loadModules libdir filenames (Just finder) -- Translate to VHDL @@ -80,7 +66,9 @@ makeVHDL libdir filenames finder = do let dir = "./vhdl/" ++ (show top_entity) ++ "/" prepareDir dir mapM_ (writeVHDL dir) vhdl - return () + end <- Clock.getCurrentTime + trace ("\nTotal compilation took " ++ show (Clock.diffUTCTime end start)) $ + return () -- | Translate the specified entities in the given modules to VHDL. moduleToVHDL :: @@ -89,7 +77,7 @@ moduleToVHDL :: -> [EntitySpec] -- ^ The entities to generate -> IO [(AST.VHDLId, AST.DesignFile)] moduleToVHDL env cores specs = do - vhdl <- runTranslatorSession env $ do + (vhdl, count) <- runTranslatorSession env $ do let all_bindings = concatMap (\x -> CoreSyn.flattenBinds (HscTypes.cm_binds x)) cores -- Store the bindings we loaded tsBindings %= Map.fromList all_bindings @@ -97,10 +85,13 @@ moduleToVHDL env cores specs = do tsInitStates %= Map.fromList all_initstates test_binds <- catMaybesM $ Monad.mapM mkTest specs let topbinds = Maybe.catMaybes $ map (\(top, _, _) -> top) specs - case topbinds of + vhdl <- case topbinds of [] -> error "Could not find top entity requested" tops -> createDesignFiles (tops ++ test_binds) + count <- get tsTransformCounter + return (vhdl, count) mapM_ (putStr . render . Ppr.ppr . snd) vhdl + putStr $ "Total number of transformations applied: " ++ (show count) ++ "\n" return vhdl where mkTest :: EntitySpec -> TranslatorSession (Maybe CoreSyn.CoreBndr) @@ -122,7 +113,7 @@ runTranslatorSession env session = do -- a unique supply anywhere. uniqSupply <- UniqSupply.mkSplitUniqSupply 'z' let init_typestate = TypeState builtin_types [] Map.empty Map.empty env - let init_state = TranslatorState uniqSupply init_typestate Map.empty Map.empty 0 Map.empty Map.empty Map.empty + let init_state = TranslatorState uniqSupply init_typestate Map.empty Map.empty 0 Map.empty Map.empty Map.empty 0 return $ State.evalState session init_state -- | Prepares the directory for writing VHDL files. This means creating the