X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=c%CE%BBash%2FCLasH%2FTranslator%2FTranslatorTypes.hs;h=257c543e2f9f799980f8035ab89bb7ac4b009050;hb=14c4b2bf87d936f2123c237a26503011ccace963;hp=6871861f839c52b8e8e13a18c658689ce215c51c;hpb=bf9f8e9e9cfce93ae1e35cf524b371beb34f5010;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git "a/c\316\273ash/CLasH/Translator/TranslatorTypes.hs" "b/c\316\273ash/CLasH/Translator/TranslatorTypes.hs" index 6871861..257c543 100644 --- "a/c\316\273ash/CLasH/Translator/TranslatorTypes.hs" +++ "b/c\316\273ash/CLasH/Translator/TranslatorTypes.hs" @@ -12,6 +12,7 @@ import qualified Data.Accessor.Template import Data.Accessor -- GHC API +import qualified GHC import qualified CoreSyn import qualified Type import qualified HscTypes @@ -23,6 +24,20 @@ import qualified Language.VHDL.AST as AST -- 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 @@ -79,6 +94,10 @@ $( Data.Accessor.Template.deriveAccessors ''TranslatorState ) type TranslatorSession = State.State TranslatorState +----------------------------------------------------------------------------- +-- Some accessors +----------------------------------------------------------------------------- + -- Does the given binder reference a top level binder in the current -- module(s)? isTopLevelBinder :: CoreSyn.CoreBndr -> TranslatorSession Bool @@ -86,4 +105,20 @@ isTopLevelBinder bndr = do 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: