module CLasH.Translator.TranslatorTypes where
import qualified Control.Monad.Trans.State as State
import qualified Data.Map as Map
import qualified Data.Accessor.Template
import qualified Data.Accessor.Monad.Trans.State as MonadState
import qualified GHC
import qualified CoreSyn
import qualified Type
import qualified HscTypes
import qualified UniqSupply
import qualified Language.VHDL.AST as AST
import CLasH.VHDL.VHDLTypes
type EntitySpec = (Maybe CoreSyn.CoreBndr, Maybe [(CoreSyn.CoreBndr, CoreSyn.CoreBndr)], Maybe CoreSyn.CoreExpr)
type Finder =
HscTypes.CoreModule
-> GHC.Ghc [EntitySpec]
newtype OrdType = OrdType Type.Type
instance Eq OrdType where
(OrdType a) == (OrdType b) = Type.tcEqType a b
instance Ord OrdType where
compare (OrdType a) (OrdType b) = Type.tcCmpType a b
data HType = AggrType String [HType] |
EnumType String [String] |
VecType Int HType |
UVecType HType |
SizedWType Int |
RangedWType Int |
SizedIType Int |
BuiltinType String |
StateType
deriving (Eq, Ord, Show)
type TypeMapRec = Maybe (AST.VHDLId, Maybe (Either AST.TypeDef AST.SubtypeIn))
type TypeMap = Map.Map HType TypeMapRec
type TypeFunMap = Map.Map (HType, String) (AST.VHDLId, AST.SubProgBody)
type TfpIntMap = Map.Map OrdType Int
data TypeState = TypeState {
tsTypes_ :: TypeMap,
tsTypeDecls_ :: [Maybe AST.PackageDecItem],
tsTypeFuns_ :: TypeFunMap,
tsTfpInts_ :: TfpIntMap,
tsHscEnv_ :: HscTypes.HscEnv
}
Data.Accessor.Template.deriveAccessors ''TypeState
type TypeSession = State.State TypeState
data TranslatorState = TranslatorState {
tsUniqSupply_ :: UniqSupply.UniqSupply
, tsType_ :: TypeState
, tsBindings_ :: Map.Map CoreSyn.CoreBndr CoreSyn.CoreExpr
, tsNormalized_ :: Map.Map CoreSyn.CoreBndr CoreSyn.CoreExpr
, tsEntityCounter_ :: Integer
, tsEntities_ :: Map.Map CoreSyn.CoreBndr Entity
, tsArchitectures_ :: Map.Map CoreSyn.CoreBndr (Architecture, [CoreSyn.CoreBndr])
, tsInitStates_ :: Map.Map CoreSyn.CoreBndr CoreSyn.CoreBndr
, tsTransformCounter_ :: Int
}
Data.Accessor.Template.deriveAccessors ''TranslatorState
type TranslatorSession = State.State TranslatorState
isTopLevelBinder :: CoreSyn.CoreBndr -> TranslatorSession Bool
isTopLevelBinder bndr = do
bindings <- MonadState.get tsBindings
return $ Map.member bndr bindings
getGlobalBind :: CoreSyn.CoreBndr -> TranslatorSession (Maybe CoreSyn.CoreExpr)
getGlobalBind bndr = do
bindings <- MonadState.get tsBindings
return $ Map.lookup bndr bindings
addGlobalBind :: CoreSyn.CoreBndr -> CoreSyn.CoreExpr -> TranslatorSession ()
addGlobalBind bndr expr = MonadState.modify tsBindings (Map.insert bndr expr)
getGlobalBinders :: TranslatorSession [CoreSyn.CoreBndr]
getGlobalBinders = do
bindings <- MonadState.get tsBindings
return $ Map.keys bindings