import Data.Accessor
-- GHC API
+import qualified GHC
import qualified CoreSyn
import qualified Type
import qualified HscTypes
-- Local imports
import CLasH.VHDL.VHDLTypes
+-- | A specification of an entity we can generate VHDL for. Consists of the
+-- binder of the top level entity, an optional initial state and an optional
+-- test input.
+type EntitySpec = (CoreSyn.CoreBndr, Maybe CoreSyn.CoreExpr, Maybe CoreSyn.CoreExpr)
+
+-- | A function that knows which parts of a module to compile
+type Finder =
+ HscTypes.CoreModule -- ^ The module to look at
+ -> GHC.Ghc [EntitySpec]
+
+-----------------------------------------------------------------------------
+-- The TranslatorSession
+-----------------------------------------------------------------------------
+
-- A orderable equivalent of CoreSyn's Type for use as a map key
newtype OrdType = OrdType { getType :: Type.Type }
instance Eq OrdType where
-- Derive accessors
$( Data.Accessor.Template.deriveAccessors ''TypeState )
--- Compatibility with old VHDLSession
-vsTypes = tsTypes
-vsTypeDecls = tsTypeDecls
-vsTypeFuns = tsTypeFuns
-vsTfpInts = tsTfpInts
-vsHscEnv = tsHscEnv
-
-- Define a session
type TypeSession = State.State TypeState
-- A global state for the translator
type TranslatorSession = State.State TranslatorState
--- Compatibility for the old VHDLSesssion
-vsType = tsType
-type VHDLSession = TranslatorSession
-
--- Compatibility for the old TransformSession
-type TransformSession = TranslatorSession
+-----------------------------------------------------------------------------
+-- Some accessors
+-----------------------------------------------------------------------------
-- Does the given binder reference a top level binder in the current
-- module(s)?
bindings <- getA tsBindings
return $ Map.member bndr bindings
+-- Finds the value of a global binding, if available
+getGlobalBind :: CoreSyn.CoreBndr -> TranslatorSession (Maybe CoreSyn.CoreExpr)
+getGlobalBind bndr = do
+ bindings <- getA tsBindings
+ return $ Map.lookup bndr bindings
+
+-- Adds a new global binding with the given value
+addGlobalBind :: CoreSyn.CoreBndr -> CoreSyn.CoreExpr -> TranslatorSession ()
+addGlobalBind bndr expr = modA tsBindings (Map.insert bndr expr)
+
+-- Returns a list of all global binders
+getGlobalBinders :: TranslatorSession [CoreSyn.CoreBndr]
+getGlobalBinders = do
+ bindings <- getA tsBindings
+ return $ Map.keys bindings
+
-- vim: set ts=8 sw=2 sts=2 expandtab: