<commit_before>{-# LANGUAGE TemplateHaskell     #-}

-- | Module that connects all the parts of the CLaSH compiler library
module CLaSH.Driver where

import qualified Control.Concurrent.Supply    as Supply
import           Control.Monad.State          (evalState)
import           Control.Lens                 (_1, use)
import qualified Data.HashMap.Lazy            as HashMap
import qualified Data.HashSet                 as HashSet
import           Data.List                    (isSuffixOf)
import           Data.Maybe                   (listToMaybe)
import qualified Data.Text.Lazy               as Text
import qualified System.Directory             as Directory
import qualified System.FilePath              as FilePath
import qualified System.IO                    as IO
import           Text.PrettyPrint.Leijen.Text (Doc, hPutDoc)
import           Unbound.LocallyNameless      (name2String)

import           CLaSH.Core.Type              (Type)
import           CLaSH.Driver.TestbenchGen
import           CLaSH.Driver.Types
import           CLaSH.Netlist                (genNetlist)
import           CLaSH.Netlist.Types          (Component (..), HWType,
                                               VHDLState)
import           CLaSH.Netlist.VHDL           (genVHDL, mkTyPackage)
import           CLaSH.Normalize              (checkNonRecursive, cleanupGraph,
                                               normalize, runNormalization)
import           CLaSH.Primitives.Types
import           CLaSH.Rewrite.Types          (DebugLevel (..))
import           CLaSH.Util

import qualified Data.Time.Clock              as Clock

-- | Create a set of .VHDL files for a set of functions
generateVHDL :: BindingMap -- ^ Set of functions
             -> PrimMap -- ^ Primitive / BlackBox Definitions
             -> (Type -> Maybe (Either String HWType)) -- ^ Hardcoded 'Type' -> 'HWType' translator
             -> DebugLevel -- ^ Debug information level for the normalization process
             -> IO ()
generateVHDL bindingsMap primMap typeTrans dbgLevel = do
  start <- Clock.getCurrentTime

  let topEntities = HashMap.toList
                  $ HashMap.filterWithKey
                      (\var _ -> isSuffixOf "topEntity" $ name2String var)
                      bindingsMap

      testInputs  = HashMap.toList
                  $ HashMap.filterWithKey
                      (\var _ -> isSuffixOf "testInput" $ name2String var)
                      bindingsMap

      expectedOutputs = HashMap.toList
                      $ HashMap.filterWithKey
                          (\var _ -> isSuffixOf "expectedOutput" $ name2String var)
                          bindingsMap

  case topEntities of<commit_msg>force calculation of 'start' time<commit_after>{-# LANGUAGE TemplateHaskell     #-}

-- | Module that connects all the parts of the CLaSH compiler library
module CLaSH.Driver where

import qualified Control.Concurrent.Supply    as Supply
import           Control.Monad.State          (evalState)
import           Control.Lens                 (_1, use)
import qualified Data.HashMap.Lazy            as HashMap
import qualified Data.HashSet                 as HashSet
import           Data.List                    (isSuffixOf)
import           Data.Maybe                   (listToMaybe)
import qualified Data.Text.Lazy               as Text
import qualified System.Directory             as Directory
import qualified System.FilePath              as FilePath
import qualified System.IO                    as IO
import           Text.PrettyPrint.Leijen.Text (Doc, hPutDoc)
import           Unbound.LocallyNameless      (name2String)

import           CLaSH.Core.Type              (Type)
import           CLaSH.Driver.TestbenchGen
import           CLaSH.Driver.Types
import           CLaSH.Netlist                (genNetlist)
import           CLaSH.Netlist.Types          (Component (..), HWType,
                                               VHDLState)
import           CLaSH.Netlist.VHDL           (genVHDL, mkTyPackage)
import           CLaSH.Normalize              (checkNonRecursive, cleanupGraph,
                                               normalize, runNormalization)
import           CLaSH.Primitives.Types
import           CLaSH.Rewrite.Types          (DebugLevel (..))
import           CLaSH.Util

import qualified Data.Time.Clock              as Clock

-- | Create a set of .VHDL files for a set of functions
generateVHDL :: BindingMap -- ^ Set of functions
             -> PrimMap -- ^ Primitive / BlackBox Definitions
             -> (Type -> Maybe (Either String HWType)) -- ^ Hardcoded 'Type' -> 'HWType' translator
             -> DebugLevel -- ^ Debug information level for the normalization process
             -> IO ()
generateVHDL bindingsMap primMap typeTrans dbgLevel = do
  start <- Clock.getCurrentTime

  let topEntities = HashMap.toList
                  $ HashMap.filterWithKey
                      (\var _ -> isSuffixOf "topEntity" $ name2String var)
                      bindingsMap

      testInputs  = HashMap.toList
                  $ HashMap.filterWithKey
                      (\var _ -> isSuffixOf "testInput" $ name2String var)
                      bindingsMap

      expectedOutputs = HashMap.toList
                      $ HashMap.filterWithKey
                          (\var _ -> isSuffixOf "expectedOutput" $ name2String var)
                          bindingsMap

  start `seq` case topEntities of
{'fraction_non_alphanumeric': 0.06378299120234604, 'fraction_numerical': 0.0018328445747800588, 'mean_word_length': 1.522884882108183, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6158513', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1288, 'n_words': 377}