1 {-# LANGUAGE TemplateHaskell #-}
2 module CLasH.Normalize.NormalizeTypes where
6 import qualified Control.Monad.Trans.Writer as Writer
7 import qualified Control.Monad.Trans.State as State
8 import qualified Data.Monoid as Monoid
9 import qualified Data.Accessor.Template
11 import qualified Data.Map as Map
16 import qualified VarSet
17 import Outputable ( Outputable, showSDoc, ppr )
20 import CLasH.Utils.Core.CoreShow
21 import CLasH.Utils.Pretty
22 import CLasH.Translator.TranslatorTypes
24 -- Wrap a writer around a TransformSession, to run a single transformation
25 -- over a single expression and track if the expression was changed.
26 type TransformMonad = Writer.WriterT Monoid.Any TransformSession
28 -- | Transforms a CoreExpr and keeps track if it has changed.
29 type Transform = CoreExpr -> TransformMonad CoreExpr
31 -- Finds the value of a global binding, if available
32 getGlobalBind :: CoreBndr -> TransformSession (Maybe CoreExpr)
33 getGlobalBind bndr = do
34 bindings <- getA tsBindings
35 return $ Map.lookup bndr bindings
37 -- Adds a new global binding with the given value
38 addGlobalBind :: CoreBndr -> CoreExpr -> TransformSession ()
39 addGlobalBind bndr expr = modA tsBindings (Map.insert bndr expr)
41 -- Returns a list of all global binders
42 getGlobalBinders :: TransformSession [CoreBndr]
44 bindings <- getA tsBindings
45 return $ Map.keys bindings