-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | CAES Language for Synchronous Hardware - As a Library
--
-- CλaSH (pronounced ‘clash’) is a functional hardware description
-- language that borrows both its syntax and semantics from the
-- functional programming language Haskell. The merits of using a
-- functional language to describe hardware comes from the fact that
-- combinational circuits can be directly modeled as mathematical
-- functions and that functional languages lend themselves very well at
-- describing and (de-)composing mathematical functions.
--
-- This package provides:
--
--
-- - The CoreHW internal language: SystemF + Letrec +
-- Case-decomposition
-- - The normalisation process that brings CoreHW in a normal form that
-- can be converted to a netlist
-- - VHDL Backend
-- - Blackbox/Primitive Handling
--
--
-- Front-ends (for: parsing, typecheck, etc.) are provided by seperate
-- packages:
--
--
@package clash-lib
@version 0.2
-- | Transform/format a Netlist Identifier so that it is acceptable as a
-- VHDL identifier
module CLaSH.Netlist.Id
-- | Transform/format a text so that it is acceptable as a VHDL identifier
mkBasicId :: Text -> Text
-- | Type and instance definitions for Primitive
module CLaSH.Primitives.Types
-- | Primitive Definitions
type PrimMap = HashMap ByteString Primitive
-- | Externally defined primitive
data Primitive
-- | A primitive that has a template that can be filled out by the backend
-- render
BlackBox :: ByteString -> Either Text Text -> Primitive
-- | Name of the primitive
--
-- Name of the primitive
name :: Primitive -> ByteString
-- | Either a declaration or an expression template.
template :: Primitive -> Either Text Text
-- | A primitive that carries additional information
Primitive :: ByteString -> Text -> Primitive
-- | Name of the primitive
--
-- Name of the primitive
name :: Primitive -> ByteString
-- | Additional information
primType :: Primitive -> Text
instance FromJSON Primitive
-- | Assortment of utility function used in the CLaSH library
module CLaSH.Util
-- | A class that can generate unique numbers
class MonadUnique m
getUniqueM :: MonadUnique m => m Int
-- | Create a TH expression that returns the a formatted string containing
-- the name of the module curLoc is spliced into, and the line
-- where it was spliced.
curLoc :: Q Exp
-- | Cache the result of a monadic action
makeCached :: (MonadState s m, Hashable k, Eq k) => k -> Lens' s (HashMap k v) -> m v -> m v
-- | Cache the result of a monadic action in a State 3 transformer layers
-- down
makeCachedT3 :: (MonadTrans t2, MonadTrans t1, MonadTrans t, Eq k, Hashable k, MonadState s m, Monad (t2 m), Monad (t1 (t2 m)), Monad (t (t1 (t2 m)))) => k -> Lens' s (HashMap k v) -> (t (t1 (t2 m))) v -> (t (t1 (t2 m))) v
-- | Spine-strict cache variant of mkCachedT3
makeCachedT3' :: (MonadTrans t2, MonadTrans t1, MonadTrans t, Eq k, Hashable k, MonadState s m, Monad (t2 m), Monad (t1 (t2 m)), Monad (t (t1 (t2 m)))) => k -> Lens' s (HashMap k v) -> (t (t1 (t2 m))) v -> (t (t1 (t2 m))) v
-- | Run a State-action using the State that is stored in a higher-layer
-- Monad
liftState :: MonadState s m => Lens' s s' -> State s' a -> m a
-- | Functorial version of first
firstM :: Functor f => (a -> f c) -> (a, b) -> f (c, b)
-- | Functorial version of second
secondM :: Functor f => (b -> f c) -> (a, b) -> f (a, c)
-- | Performs trace when first argument evaluates to True
traceIf :: Bool -> String -> a -> a
-- | Monadic version of partition
partitionM :: Monad m => (a -> m Bool) -> [a] -> m ([a], [a])
-- | Monadic version of mapAccumL
mapAccumLM :: Monad m => (acc -> x -> m (acc, y)) -> acc -> [x] -> m (acc, [y])
-- | Composition of a unary function with a binary function
dot :: (c -> d) -> (a -> b -> c) -> a -> b -> d
-- | if-then-else as a function on an argument
ifThenElse :: (a -> Bool) -> (a -> b) -> (a -> b) -> a -> b
-- | Applicative version of 'GHC.Types.(:)'
(<:>) :: Applicative f => f a -> f [a] -> f [a]
-- | Safe indexing, returns a Nothing if the index does not exist
indexMaybe :: [a] -> Int -> Maybe a
-- | Unsafe indexing, return a custom error message when indexing fails
indexNote :: String -> [a] -> Int -> a
-- | Split the second list at the length of the first list
splitAtList :: [b] -> [a] -> ([a], [a])
-- | Build lenses (and traversals) with a sensible default configuration.
--
--
-- makeLenses = makeLensesWith lensRules
--
makeLenses :: Name -> Q [Dec]
instance Ord a => Ord (Embed a)
instance Hashable (Name a)
instance Monad m => MonadUnique (StateT Int m)
-- | Utility functions to generate Primitives
module CLaSH.Primitives.Util
-- | Generate a set of primitives that are found in the primitive
-- definition files in the given directories.
generatePrimMap :: [FilePath] -> IO PrimMap
-- | Parse a ByteString according to the given JSON template. Prints
-- failures on stdout, and returns Nothing if parsing
-- fails.
decodeAndReport :: FromJSON a => ByteString -> Maybe a
-- | Variables in CoreHW
module CLaSH.Core.Var
-- | Variables in CoreHW
data Var a
-- | Constructor for type variables
TyVar :: Name a -> Embed Kind -> Var a
varName :: Var a -> Name a
varKind :: Var a -> Embed Kind
-- | Constructor for term variables
Id :: Name a -> Embed Type -> Var a
varName :: Var a -> Name a
varType :: Var a -> Embed Type
-- | Term variable
type Id = Var Term
-- | Type variable
type TyVar = Var Type
-- | Change the name of a variable
modifyVarName :: (Name a -> Name a) -> Var a -> Var a
instance Subst Type Id
instance Subst Type TyVar
instance Subst Term TyVar
instance Subst Term Id
instance Alpha a => Alpha (Var a)
instance (Rep a0, Sat (ctx0 (Name a0)), Sat (ctx0 (Embed Kind)), Sat (ctx0 (Embed Type))) => Rep1 ctx0 (Var a0)
instance Rep a0 => Rep (Var a0)
instance Eq (Var a)
instance Ord (Var a)
instance Show (Var a)
-- | Type Constructors in CoreHW
module CLaSH.Core.TyCon
-- | Type Constructor
data TyCon
-- | Algorithmic DataCons
AlgTyCon :: TyConName -> Kind -> Int -> AlgTyConRhs -> TyCon
-- | Name of the TyCon
--
-- Name of the TyCon
--
-- Name of the TyCon
tyConName :: TyCon -> TyConName
-- | Kind of the TyCon
--
-- Kind of the TyCon
tyConKind :: TyCon -> Kind
-- | Number of type arguments
--
-- Number of type arguments
tyConArity :: TyCon -> Int
-- | DataCon definitions
algTcRhs :: TyCon -> AlgTyConRhs
-- | Primitive TyCons
PrimTyCon :: TyConName -> Kind -> Int -> PrimRep -> TyCon
-- | Name of the TyCon
--
-- Name of the TyCon
--
-- Name of the TyCon
tyConName :: TyCon -> TyConName
-- | Kind of the TyCon
--
-- Kind of the TyCon
tyConKind :: TyCon -> Kind
-- | Number of type arguments
--
-- Number of type arguments
tyConArity :: TyCon -> Int
-- | Representation
primTyConRep :: TyCon -> PrimRep
-- | To close the loop on the type hierarchy
SuperKindTyCon :: TyConName -> TyCon
-- | Name of the TyCon
--
-- Name of the TyCon
--
-- Name of the TyCon
tyConName :: TyCon -> TyConName
-- | TyCon reference
type TyConName = Name TyCon
-- | The RHS of an Algebraic Datatype
data AlgTyConRhs
DataTyCon :: [DataCon] -> AlgTyConRhs
-- | The DataCons of a TyCon
dataCons :: AlgTyConRhs -> [DataCon]
NewTyCon :: DataCon -> ([TyName], Type) -> AlgTyConRhs
-- | The newtype DataCon
dataCon :: AlgTyConRhs -> DataCon
-- | The argument type of the newtype DataCon in eta-reduced form, which is
-- just the representation of the TyCon. The TyName's are the
-- type-variables from the corresponding TyCon.
ntEtadRhs :: AlgTyConRhs -> ([TyName], Type)
-- | Representations for primitive types
data PrimRep
IntRep :: PrimRep
VoidRep :: PrimRep
-- | Create a Kind out of a TyConName
mkKindTyCon :: TyConName -> Kind -> TyCon
-- | Does the TyCon look like a tuple TyCon
isTupleTyConLike :: TyCon -> Bool
-- | Get the DataCons belonging to a TyCon
tyConDataCons :: TyCon -> [DataCon]
instance Subst Term PrimRep
instance Subst Term AlgTyConRhs
instance Subst Term TyCon
instance Subst Type PrimRep
instance Subst Type AlgTyConRhs
instance Subst Type TyCon
instance Alpha AlgTyConRhs
instance Alpha TyCon
instance Alpha PrimRep
instance Rep1 ctx0 PrimRep
instance Rep PrimRep
instance (Sat (ctx0 [DataCon]), Sat (ctx0 DataCon), Sat (ctx0 ([TyName], Type))) => Rep1 ctx0 AlgTyConRhs
instance Rep AlgTyConRhs
instance (Sat (ctx0 TyConName), Sat (ctx0 Kind), Sat (ctx0 Int), Sat (ctx0 AlgTyConRhs), Sat (ctx0 PrimRep)) => Rep1 ctx0 TyCon
instance Rep TyCon
instance Show PrimRep
instance Show AlgTyConRhs
instance Ord TyCon
instance Eq TyCon
instance Show TyCon
-- | Builtin Type and Kind definitions
module CLaSH.Core.TysPrim
-- | Builtin Kind
liftedTypeKind :: Kind
-- | Builtin Kind
typeNatKind :: Kind
-- | Builtin Kind
typeSymbolKind :: Kind
-- | Builtin Type
intPrimTy :: Type
-- | Builtin Type
voidPrimTy :: Type
-- | Term Literal
module CLaSH.Core.Literal
-- | Term Literal
data Literal
IntegerLiteral :: Integer -> Literal
StringLiteral :: String -> Literal
-- | Determines the Type of a Literal
literalType :: Literal -> Type
instance Subst Term Literal
instance Subst Type Literal
instance Alpha Literal
instance (Sat (ctx0 Integer), Sat (ctx0 String)) => Rep1 ctx0 Literal
instance Rep Literal
instance Eq Literal
instance Ord Literal
instance Show Literal
-- | Data Constructors in CoreHW
module CLaSH.Core.DataCon
-- | Data Constructor
data DataCon
MkData :: DcName -> ConTag -> Type -> [TyName] -> [TyName] -> [Type] -> DataCon
-- | Name of the DataCon
dcName :: DataCon -> DcName
-- | Syntactical position in the type definition
dcTag :: DataCon -> ConTag
-- | Type of the 'DataCon
dcType :: DataCon -> Type
-- | Universally quantified type-variables, these type variables are also
-- part of the result type of the DataCon
dcUnivTyVars :: DataCon -> [TyName]
-- | Existentially quantified type-variables, these type variables are not
-- part of the result of the DataCon, but only of the arguments.
dcExtTyVars :: DataCon -> [TyName]
-- | Argument types
dcArgTys :: DataCon -> [Type]
-- | DataCon reference
type DcName = Name DataCon
-- | Syntactical position of the DataCon in the type definition
type ConTag = Int
-- | Given a DataCon and a list of types, the type variables of the DataCon
-- type are substituted for the list of types. The argument types are
-- returned.
--
-- The list of types should be equal to the number of type variables,
-- otherwise an error is reported.
dataConInstArgTys :: DataCon -> [Type] -> [Type]
instance Subst Term DataCon
instance Subst Type DataCon
instance Alpha DataCon
instance (Sat (ctx0 DcName), Sat (ctx0 ConTag), Sat (ctx0 Type), Sat (ctx0 [TyName]), Sat (ctx0 [Type])) => Rep1 ctx0 DataCon
instance Rep DataCon
instance Ord DataCon
instance Eq DataCon
instance Show DataCon
-- | Term representation in the CoreHW language: System F + LetRec + Case
module CLaSH.Core.Term
-- | Term representation in the CoreHW language: System F + LetRec + Case
data Term
-- | Variable reference
Var :: Type -> TmName -> Term
-- | Datatype constructor
Data :: DataCon -> Term
-- | Literal
Literal :: Literal -> Term
-- | Primitive
Prim :: TmName -> Type -> Term
-- | Term-abstraction
Lam :: (Bind Id Term) -> Term
-- | Type-abstraction
TyLam :: (Bind TyVar Term) -> Term
-- | Application
App :: Term -> Term -> Term
-- | Type-application
TyApp :: Term -> Type -> Term
-- | Recursive let-binding
Letrec :: (Bind (Rec [LetBinding]) Term) -> Term
-- | Case-expression: subject, type of alternatives, list of alternatives
Case :: Term -> Type -> [Bind Pat Term] -> Term
-- | Term reference
type TmName = Name Term
-- | Binding in a LetRec construct
type LetBinding = (Id, Embed Term)
-- | Patterns in the LHS of a case-decomposition
data Pat
-- | Datatype pattern, '[TyVar]' bind existentially-quantified
-- type-variables of a DataCon
DataPat :: (Embed DataCon) -> (Rebind [TyVar] [Id]) -> Pat
-- | Literal pattern
LitPat :: (Embed Literal) -> Pat
-- | Default pattern
DefaultPat :: Pat
instance Subst Type Term
instance Subst Type Pat
instance Subst Term Term
instance Subst Term Pat
instance Alpha Pat
instance Alpha Term
instance Ord Term
instance Eq Term
instance (Sat (ctx0 (Embed DataCon)), Sat (ctx0 (Rebind [TyVar] [Id])), Sat (ctx0 (Embed Literal))) => Rep1 ctx0 Pat
instance Rep Pat
instance (Sat (ctx0 Type), Sat (ctx0 TmName), Sat (ctx0 DataCon), Sat (ctx0 Literal), Sat (ctx0 (Bind Id Term)), Sat (ctx0 (Bind TyVar Term)), Sat (ctx0 Term), Sat (ctx0 (Bind (Rec [LetBinding]) Term)), Sat (ctx0 [Bind Pat Term])) => Rep1 ctx0 Term
instance Rep Term
instance Show Term
instance Show Pat
-- | Capture-free substitution function for CoreHW
module CLaSH.Core.Subst
-- | Substitutes types in a type
substTys :: [(TyName, Type)] -> Type -> Type
-- | Substitutes a type in a type
substTy :: TyName -> Type -> Type -> Type
-- | Substitutes kinds in a kind
substKindWith :: [(KiName, Kind)] -> Kind -> Kind
-- | Substitutes a type in a term
substTyInTm :: TyName -> Type -> Term -> Term
-- | Substitutes types in a term
substTysinTm :: [(TyName, Type)] -> Term -> Term
-- | Substitutes a term in a term
substTm :: TmName -> Term -> Term -> Term
-- | Substitutes terms in a term
substTms :: [(TmName, Term)] -> Term -> Term
-- | Types in CoreHW
module CLaSH.Core.Type
-- | Types in CoreHW: function and polymorphic types
data Type
-- | Type variable
VarTy :: Kind -> TyName -> Type
-- | Type constant
ConstTy :: ConstTy -> Type
-- | Polymorphic Type
ForAllTy :: (Bind TyVar Type) -> Type
-- | Type Application
AppTy :: Type -> Type -> Type
-- | Type literal
LitTy :: LitTy -> Type
-- | An easier view on types
data TypeView
-- | Function type
FunTy :: Type -> Type -> TypeView
-- | Applied TyCon
TyConApp :: TyCon -> [Type] -> TypeView
-- | Neither of the above
OtherType :: Type -> TypeView
-- | Type Constants
data ConstTy
-- | TyCon type
TyCon :: TyCon -> ConstTy
-- | Function type
Arrow :: ConstTy
-- | Literal Types
data LitTy
NumTy :: Int -> LitTy
SymTy :: String -> LitTy
-- | The level above types
type Kind = Type
-- | Either a Kind or a Type
type KindOrType = Type
-- | Reference to a Kind
type KiName = Name Kind
-- | Reference to a Type
type TyName = Name Type
-- | Type variable
type TyVar = Var Type
-- | An easier view on types
tyView :: Type -> TypeView
-- | A view on types in which Signal types and newtypes are
-- transparent
coreView :: Type -> TypeView
-- | A transformation that renders Signal types transparent
transparentTy :: Type -> Type
-- | Determine the kind of a type
typeKind :: Type -> Kind
-- | Make a Type out of a TyCon
mkTyConTy :: TyCon -> Type
-- | Make a function type of an argument and result type
mkFunTy :: Type -> Type -> Type
-- | Make a TyCon Application out of a TyCon and a list of argument types
mkTyConApp :: TyCon -> [Type] -> Type
-- | Split a function type in an argument and result type
splitFunTy :: Type -> Maybe (Type, Type)
-- | Split a poly-function type in a: list of type-binders and argument
-- types, and the result type
splitFunForallTy :: Type -> ([Either TyVar Type], Type)
-- | Split a TyCon Application in a TyCon and its arguments
splitTyConAppM :: Type -> Maybe (TyCon, [Type])
-- | Is a type polymorphic?
isPolyTy :: Type -> Bool
-- | Is a type a function type?
isFunTy :: Type -> Bool
-- | Apply a function type to an argument type and get the result type
applyFunTy :: Type -> Type -> Type
-- | Substitute the type variable of a type (ForAllTy) with another
-- type
applyTy :: Fresh m => Type -> KindOrType -> m Type
instance Ord Type
instance Eq Type
instance Subst Type Type
instance Subst Term Type
instance Subst Term ConstTy
instance Subst Type ConstTy
instance Subst Term LitTy
instance Subst Type LitTy
instance Alpha LitTy
instance Alpha ConstTy
instance Alpha Type
instance Sat (ctx0 TyCon) => Rep1 ctx0 ConstTy
instance Rep ConstTy
instance (Sat (ctx0 Int), Sat (ctx0 String)) => Rep1 ctx0 LitTy
instance Rep LitTy
instance (Sat (ctx0 Kind), Sat (ctx0 TyName), Sat (ctx0 ConstTy), Sat (ctx0 (Bind TyVar Type)), Sat (ctx0 Type), Sat (ctx0 LitTy)) => Rep1 ctx0 Type
instance Rep Type
instance Show LitTy
instance Show Type
instance Show ConstTy
instance Show TypeView
-- | Free variable calculations
module CLaSH.Core.FreeVars
-- | Gives the free type-variables in a Type
typeFreeVars :: Collection c => Type -> c TyName
-- | Gives the free type-variables and free term-variables of a Term
termFreeVars :: Collection c => Term -> (c TyName, c TmName)
-- | Gives the free term-variables of a Term
termFreeIds :: Collection c => Term -> c TmName
-- | Gives the free type-variables of a Term
termFreeTyVars :: Collection c => Term -> c TyName
-- | Type definitions used by the Driver module
module CLaSH.Driver.Types
-- | Global function binders
type BindingMap = HashMap TmName (Type, Term)
-- | Pretty printing class and instances for CoreHW
module CLaSH.Core.Pretty
-- | Pretty printing Show-like typeclass
class Pretty p where ppr = pprPrec 0
ppr :: (Pretty p, Applicative m, LFresh m) => p -> m Doc
pprPrec :: (Pretty p, Applicative m, LFresh m) => Rational -> p -> m Doc
-- | Print a Pretty thing to a String
showDoc :: Pretty p => p -> String
instance Eq TypePrec
instance Ord TypePrec
instance Pretty Pat
instance Pretty Literal
instance Pretty DataCon
instance Pretty (Var Term)
instance Pretty Term
instance Pretty LitTy
instance Pretty TyCon
instance Pretty (Var Type)
instance Pretty Type
instance Pretty (Id, Term)
instance Pretty a => Pretty [a]
instance Pretty (Name a)
-- | Smart constructor and destructor functions for CoreHW
module CLaSH.Core.Util
-- | Type environment/context
type Gamma = HashMap TmName Type
-- | Kind environment/context
type Delta = HashMap TyName Kind
-- | Determine the type of a term
termType :: (Functor m, Fresh m) => Term -> m Type
-- | Split a (Type)Application in the applied term and it arguments
collectArgs :: Term -> (Term, [Either Term Type])
-- | Split a (Type)Abstraction in the bound variables and the abstracted
-- term
collectBndrs :: Fresh m => Term -> m ([Either Id TyVar], Term)
-- | Get the result type of a polymorphic function given a list of
-- arguments
applyTypeToArgs :: Fresh m => Type -> [Either Term Type] -> m Type
-- | Get the list of term-binders out of a DataType pattern
patIds :: Pat -> [Id]
-- | Make a type variable
mkTyVar :: Kind -> TyName -> TyVar
-- | Make a term variable
mkId :: Type -> TmName -> Id
-- | Abstract a term over a list of term and type variables
mkAbstraction :: Term -> [Either Id TyVar] -> Term
-- | Abstract a term over a list of term variables
mkTyLams :: Term -> [TyVar] -> Term
-- | Abstract a term over a list of type variables
mkLams :: Term -> [Id] -> Term
-- | Apply a list of types and terms to a term
mkApps :: Term -> [Either Term Type] -> Term
-- | Apply a list of terms to a term
mkTmApps :: Term -> [Term] -> Term
-- | Apply a list of types to a term
mkTyApps :: Term -> [Type] -> Term
-- | Does a term have a function type?
isFun :: (Functor m, Fresh m) => Term -> m Bool
-- | Is a term a term-abstraction?
isLam :: Term -> Bool
-- | Is a term a recursive let-binding?
isLet :: Term -> Bool
-- | Is a term a variable reference?
isVar :: Term -> Bool
-- | Is a term a datatype constructor?
isCon :: Term -> Bool
-- | Is a term a primitive?
isPrim :: Term -> Bool
-- | Make variable reference out of term variable
idToVar :: Id -> Term
-- | Make a term variable out of a variable reference
varToId :: Term -> Id
-- | Type and instance definitions for Netlist modules
module CLaSH.Netlist.Types
-- | Monad that caches generated components (StateT) and remembers hidden
-- inputs of components that are being generated (WriterT)
newtype NetlistMonad a
NetlistMonad :: WriterT [(Identifier, HWType)] (StateT NetlistState (FreshMT IO)) a -> NetlistMonad a
runNetlist :: NetlistMonad a -> WriterT [(Identifier, HWType)] (StateT NetlistState (FreshMT IO)) a
-- | State for the VHDLM monad:
--
--
-- - Previously encountered HWTypes
-- - Product type counter
-- - Cache for previously generated product type names
--
type VHDLState = (HashSet HWType, Int, HashMap HWType Doc)
-- | State of the NetlistMonad
data NetlistState
NetlistState :: HashMap TmName (Type, Term) -> Gamma -> Int -> Int -> HashMap TmName Component -> HashMap ByteString Primitive -> VHDLState -> (Type -> Maybe (Either String HWType)) -> NetlistState
-- | Global binders
_bindings :: NetlistState -> HashMap TmName (Type, Term)
-- | Type environment/context
_varEnv :: NetlistState -> Gamma
-- | Number of signal declarations
_varCount :: NetlistState -> Int
-- | Number of create components
_cmpCount :: NetlistState -> Int
-- | Cached components
_components :: NetlistState -> HashMap TmName Component
-- | Primitive Definitions
_primitives :: NetlistState -> HashMap ByteString Primitive
-- | State for the VHDLM Monad
_vhdlMState :: NetlistState -> VHDLState
-- | Hardcoded Type -> HWType translator
_typeTranslator :: NetlistState -> Type -> Maybe (Either String HWType)
-- | Signal reference
type Identifier = Text
-- | Component: base unit of a Netlist
data Component
Component :: Identifier -> [(Identifier, HWType)] -> [(Identifier, HWType)] -> (Identifier, HWType) -> [Declaration] -> Component
-- | Name of the component
componentName :: Component -> Identifier
-- | Ports that have no correspondence the original function definition
hiddenPorts :: Component -> [(Identifier, HWType)]
-- | Input ports
inputs :: Component -> [(Identifier, HWType)]
-- | Output port
output :: Component -> (Identifier, HWType)
-- | Internal declarations
declarations :: Component -> [Declaration]
-- | Size indication of a type (e.g. bit-size or number of elements)
type Size = Int
-- | Representable hardware types
data HWType
-- | Empty type
Void :: HWType
-- | Bit type
Bit :: HWType
-- | Boolean type
Bool :: HWType
-- | Integer type
Integer :: HWType
-- | Signed integer of a specified size
Signed :: Size -> HWType
-- | Unsigned integer of a specified size
Unsigned :: Size -> HWType
-- | Vector type
Vector :: Size -> HWType -> HWType
-- | Sum type: Name and Constructor names
Sum :: Identifier -> [Identifier] -> HWType
-- | Product type: Name and field types
Product :: Identifier -> [HWType] -> HWType
-- | Sum-of-Product type: Name and Constructor names + field types
SP :: Identifier -> [(Identifier, [HWType])] -> HWType
-- | Clock type with specified period
Clock :: Int -> HWType
-- | Reset type corresponding to clock with a specified period
Reset :: Int -> HWType
-- | Internals of a Component
data Declaration
-- | Signal assignment:
--
--
-- - Signal to assign
-- - Assigned expression
--
Assignment :: Identifier -> Expr -> Declaration
-- | Conditional signal assignment:
--
--
-- - Signal to assign
-- - Scrutinized expression
-- - List of: (Maybe expression scrutinized expression is compared
-- with,RHS of alternative)
--
CondAssignment :: Identifier -> Expr -> [(Maybe Expr, Expr)] -> Declaration
-- | Instantiation of another component
InstDecl :: Identifier -> Identifier -> [(Identifier, Expr)] -> Declaration
-- | Instantiation of blackbox declaration
BlackBoxD :: Text -> Declaration
-- | Signal declaration
NetDecl :: Identifier -> HWType -> (Maybe Expr) -> Declaration
-- | Expression Modifier
data Modifier
-- | Index the expression: (Type of expression,DataCon tag,Field Tag)
Indexed :: (HWType, Int, Int) -> Modifier
-- | See expression in a DataCon context: (Type of the expression, DataCon
-- tag)
DC :: (HWType, Int) -> Modifier
-- | See the expression in the context of a Vector append operation
VecAppend :: Modifier
-- | Expression used in RHS of a declaration
data Expr
-- | Literal expression
Literal :: (Maybe Size) -> Literal -> Expr
-- | DataCon application
DataCon :: HWType -> (Maybe Modifier) -> [Expr] -> Expr
-- | Signal reference
Identifier :: Identifier -> (Maybe Modifier) -> Expr
-- | Instantiation of a BlackBox expression
BlackBoxE :: Text -> (Maybe Modifier) -> Expr
-- | Literals used in an expression
data Literal
-- | Number literal
NumLit :: Int -> Literal
-- | Bit literal
BitLit :: Bit -> Literal
-- | Boolean literal
BoolLit :: Bool -> Literal
-- | Vector literal
VecLit :: [Literal] -> Literal
-- | Bit literal
data Bit
-- | High
H :: Bit
-- | Low
L :: Bit
-- | Undefined
U :: Bit
-- | High-impedance
Z :: Bit
vhdlMState :: Lens' NetlistState VHDLState
varEnv :: Lens' NetlistState Gamma
varCount :: Lens' NetlistState Int
typeTranslator :: Lens' NetlistState (Type -> Maybe (Either String HWType))
primitives :: Lens' NetlistState (HashMap ByteString Primitive)
components :: Lens' NetlistState (HashMap TmName Component)
cmpCount :: Lens' NetlistState Int
bindings :: Lens' NetlistState (HashMap TmName (Type, Term))
instance Eq HWType
instance Show HWType
instance Generic HWType
instance Show Modifier
instance Show Bit
instance Show Literal
instance Show Expr
instance Show Declaration
instance Show Component
instance Functor NetlistMonad
instance Monad NetlistMonad
instance Applicative NetlistMonad
instance MonadState NetlistState NetlistMonad
instance MonadWriter [(Identifier, HWType)] NetlistMonad
instance Fresh NetlistMonad
instance MonadIO NetlistMonad
instance Datatype D1HWType
instance Constructor C1_0HWType
instance Constructor C1_1HWType
instance Constructor C1_2HWType
instance Constructor C1_3HWType
instance Constructor C1_4HWType
instance Constructor C1_5HWType
instance Constructor C1_6HWType
instance Constructor C1_7HWType
instance Constructor C1_8HWType
instance Constructor C1_9HWType
instance Constructor C1_10HWType
instance Constructor C1_11HWType
instance Hashable HWType
-- | Type and instance definitions for Rewrite modules
module CLaSH.Rewrite.Types
-- | Context in which a term appears
data CoreContext
-- | Function position of an application
AppFun :: CoreContext
-- | Argument position of an application
AppArg :: CoreContext
-- | Function position of a type application
TyAppC :: CoreContext
-- | RHS of a Let-binder with the sibling LHS'
LetBinding :: [Id] -> CoreContext
-- | Body of a Let-binding with the bound LHS'
LetBody :: [Id] -> CoreContext
-- | Body of a lambda-term with the abstracted variable
LamBody :: Id -> CoreContext
-- | Body of a TyLambda-term with the abstracted type-variable
TyLamBody :: TyVar -> CoreContext
-- | RHS of a case-alternative with the variables bound by the pattern on
-- the LHS
CaseAlt :: [Id] -> CoreContext
-- | Subject of a case-decomposition
CaseScrut :: CoreContext
-- | State of a rewriting session
data RewriteState
RewriteState :: Int -> HashMap TmName (Type, Term) -> Supply -> (Type -> Maybe (Either String HWType)) -> RewriteState
-- | Number of applied transformations
_transformCounter :: RewriteState -> Int
-- | Global binders
_bindings :: RewriteState -> HashMap TmName (Type, Term)
-- | Supply of unique numbers
_uniqSupply :: RewriteState -> Supply
-- | Hardcode Type -> HWType translator
_typeTranslator :: RewriteState -> Type -> Maybe (Either String HWType)
uniqSupply :: Lens' RewriteState Supply
typeTranslator :: Lens' RewriteState (Type -> Maybe (Either String HWType))
transformCounter :: Lens' RewriteState Int
bindings :: Lens' RewriteState (HashMap TmName (Type, Term))
-- | Debug Message Verbosity
data DebugLevel
-- | Don't show debug messages
DebugNone :: DebugLevel
-- | Show completely normalized expressions
DebugFinal :: DebugLevel
-- | Show sub-expressions after a successful rewrite
DebugApplied :: DebugLevel
-- | Show all sub-expressions on which a rewrite is attempted
DebugAll :: DebugLevel
-- | Read-only environment of a rewriting session
newtype RewriteEnv
RE :: DebugLevel -> RewriteEnv
_dbgLevel :: RewriteEnv -> DebugLevel
dbgLevel :: Iso' RewriteEnv DebugLevel
-- | Monad that keeps track how many transformations have been applied and
-- can generate fresh variables and unique identifiers
type RewriteSession m = ReaderT RewriteEnv (StateT RewriteState (FreshMT m))
-- | Monad that can do the same as RewriteSession and in addition
-- keeps track if a transformation/rewrite has been successfully applied.
type RewriteMonad m = WriterT Any (RewriteSession m)
-- | MTL convenience wrapper around RewriteMonad
newtype R m a
R :: RewriteMonad m a -> R m a
runR :: R m a -> RewriteMonad m a
-- | Monadic action that transforms a term given a certain context
type Transform m = [CoreContext] -> Term -> m Term
-- | A Transform action in the context of the RewriteMonad
type Rewrite m = Transform (R m)
instance Monad m => Monad (R m)
instance Functor m => Functor (R m)
instance Monad m => MonadReader RewriteEnv (R m)
instance Monad m => MonadState RewriteState (R m)
instance Monad m => MonadWriter Any (R m)
instance Monad m => MonadUnique (R m)
instance Monad m => Fresh (R m)
instance Monad m => MonadUnique (RewriteMonad m)
instance Eq DebugLevel
instance Ord DebugLevel
instance Show CoreContext
-- | Types used in Normalize modules
module CLaSH.Normalize.Types
-- | State of the NormalizeMonad
data NormalizeState
NormalizeState :: HashMap TmName Term -> Map (TmName, Int, Either Term Type) (TmName, Type) -> HashMap TmName [TmName] -> [TmName] -> TmName -> NormalizeState
-- | Global binders
_normalized :: NormalizeState -> HashMap TmName Term
-- | Cache of previously specialised functions:
--
--
-- - Key: (name of the original function, argument position,
-- specialised term/type)
-- - Elem: (name of specialised function,type of specialised
-- function)
--
_specialisations :: NormalizeState -> Map (TmName, Int, Either Term Type) (TmName, Type)
-- | Cache of function where inlining took place:
--
--
-- - Key: function where inlining took place
-- - Elem: functions which were inlined
--
_inlined :: NormalizeState -> HashMap TmName [TmName]
-- | Inlined functions in the current traversal
_newInlined :: NormalizeState -> [TmName]
-- | Function which is currently normalized
_curFun :: NormalizeState -> TmName
specialisations :: Lens' NormalizeState (Map (TmName, Int, Either Term Type) (TmName, Type))
normalized :: Lens' NormalizeState (HashMap TmName Term)
newInlined :: Lens' NormalizeState [TmName]
inlined :: Lens' NormalizeState (HashMap TmName [TmName])
curFun :: Lens' NormalizeState TmName
-- | State monad that stores specialisation and inlining information
type NormalizeMonad = State NormalizeState
-- | RewriteSession with extra Normalisation information
type NormalizeSession = RewriteSession NormalizeMonad
-- | A Transform action in the context of the
-- RewriteMonad and NormalizeMonad
type NormRewrite = Rewrite NormalizeMonad
-- | Types used in BlackBox modules
module CLaSH.Netlist.BlackBox.Types
-- | Context used to fill in the holes of a BlackBox template
data BlackBoxContext
Context :: (SyncIdentifier, HWType) -> [(SyncIdentifier, HWType)] -> [Identifier] -> [(BlackBoxTemplate, BlackBoxContext)] -> BlackBoxContext
-- | Result name and type
result :: BlackBoxContext -> (SyncIdentifier, HWType)
-- | Argument names and types
inputs :: BlackBoxContext -> [(SyncIdentifier, HWType)]
-- | Literal arguments (subset of inputs)
litInputs :: BlackBoxContext -> [Identifier]
-- | Function arguments (subset of inputs):
--
--
-- - (Blackbox Template,Partial Blackbox Concext)
--
funInputs :: BlackBoxContext -> [(BlackBoxTemplate, BlackBoxContext)]
-- | Either the name of the identifier, or a tuple of the identifier and
-- the corresponding clock
type SyncIdentifier = Either Identifier (Identifier, Identifier)
-- | A BlackBox Template is a List of Elements
type BlackBoxTemplate = [Element]
-- | Elements of a blackbox context
data Element
-- | Constant
C :: Text -> Element
-- | Component instantiation hole
D :: Decl -> Element
-- | Output hole
O :: Element
-- | Input hole
I :: Int -> Element
-- | Literal hole
L :: Int -> Element
-- | Symbol hole
Sym :: Int -> Element
-- | Clock hole (Maybe clk corresponding to input, clk corresponding to
-- output if Nothing)
Clk :: (Maybe Int) -> Element
-- | Reset hole
Rst :: (Maybe Int) -> Element
-- | Type declaration hole
Typ :: (Maybe Int) -> Element
-- | Type root hole
TypM :: (Maybe Int) -> Element
-- | Default value hole
Def :: (Maybe Int) -> Element
-- | Component instantiation hole. First argument indicates which function
-- argument to instantiate. Second argument corresponds to output and
-- input assignments, where the first element is the output assignment,
-- and the subsequent elements are the consecutive input assignments.
data Decl
Decl :: Int -> [BlackBoxTemplate] -> Decl
-- | Monad that caches VHDL information and remembers hidden inputs of
-- black boxes that are being generated (WriterT)
newtype BlackBoxMonad a
B :: WriterT [(Identifier, HWType)] (State VHDLState) a -> BlackBoxMonad a
runBlackBoxM :: BlackBoxMonad a -> WriterT [(Identifier, HWType)] (State VHDLState) a
instance Show Decl
instance Show Element
instance Show BlackBoxContext
instance Functor BlackBoxMonad
instance Monad BlackBoxMonad
instance MonadWriter [(Identifier, HWType)] BlackBoxMonad
instance MonadState VHDLState BlackBoxMonad
-- | Parser definitions for BlackBox templates
module CLaSH.Netlist.BlackBox.Parser
-- | Parse a text as a BlackBoxTemplate, returns a list of errors in case
-- parsing fails
runParse :: Text -> (BlackBoxTemplate, [Error LineColPos])
-- | Rewriting combinators and traversals
module CLaSH.Rewrite.Combinators
-- | Apply a transformation on the subtrees of an term
allR :: (Functor m, Monad m, Fresh m) => Bool -> Transform m -> Transform m
-- | Apply two transformations in succession
(>->) :: Monad m => Transform m -> Transform m -> Transform m
-- | Apply a transformation in a topdown traversal
topdownR :: (Fresh m, Functor m, Monad m) => Transform m -> Transform m
-- | Apply a transformation in a topdown traversal. Doesn't freshen bound
-- variables
unsafeTopdownR :: (Fresh m, Functor m, Monad m) => Transform m -> Transform m
-- | Apply a transformation in a bottomup traversal
bottomupR :: (Fresh m, Functor m, Monad m) => Transform m -> Transform m
-- | Apply a transformation in a bottomup traversal. Doesn't freshen bound
-- variables
unsafeBottomupR :: (Fresh m, Functor m, Monad m) => Transform m -> Transform m
-- | Apply a transformation in a bottomup traversal, when a transformation
-- succeeds in a certain node, apply the transformation further in a
-- topdown traversal starting at that node.
upDownR :: (Functor m, Monad m) => Rewrite m -> Rewrite m
-- | Apply a transformation in a bottomup traversal, when a transformation
-- succeeds in a certain node, apply the transformation further in a
-- topdown traversal starting at that node. Doesn't freshen bound
-- variables
unsafeUpDownR :: (Functor m, Monad m) => Rewrite m -> Rewrite m
-- | Only apply the second transformation if the first one succeeds.
(!->) :: Monad m => Rewrite m -> Rewrite m -> Rewrite m
-- | Keep applying a transformation until it fails.
repeatR :: Monad m => Rewrite m -> Rewrite m
-- | Utilities for converting Core Type/Term to Netlist datatypes
module CLaSH.Netlist.Util
-- | Split a normalized term into: a list of arguments, a list of
-- let-bindings, and a variable reference that is the body of the
-- let-binding. Returns a String containing the error is the term was not
-- in a normalized form.
splitNormalized :: (Fresh m, Functor m) => Term -> m (Either String ([Id], [LetBinding], Id))
-- | Converts a Core type to a HWType given a function that translates
-- certain builtin types. Errors if the Core type is not translatable.
unsafeCoreTypeToHWType :: (Type -> Maybe (Either String HWType)) -> Type -> HWType
-- | Converts a Core type to a HWType within the NetlistMonad
unsafeCoreTypeToHWTypeM :: Type -> NetlistMonad HWType
-- | Returns the name of the clock corresponding to a type
synchronizedClk :: Type -> Maybe Identifier
-- | Converts a Core type to a HWType given a function that translates
-- certain builtin types. Returns a string containing the error message
-- when the Core type is not translatable.
coreTypeToHWType :: (Type -> Maybe (Either String HWType)) -> Type -> Either String HWType
-- | Converts an algebraic Core type (split into a TyCon and its argument)
-- to a HWType.
mkADT :: (Type -> Maybe (Either String HWType)) -> String -> TyCon -> [Type] -> Either String HWType
-- | Simple check if a TyCon is recursively defined.
isRecursiveTy :: TyCon -> Bool
-- | Determines if a Core type is translatable to a HWType given a function
-- that translates certain builtin types.
representableType :: (Type -> Maybe (Either String HWType)) -> Type -> Bool
-- | Determines the bitsize of a type
typeSize :: HWType -> Int
-- | Determines the bitsize of the constructor of a type
conSize :: HWType -> Int
-- | Gives the length of length-indexed types
typeLength :: HWType -> Int
-- | Gives the HWType corresponding to a term. Returns an error if the term
-- has a Core type that is not translatable to a HWType.
termHWType :: Term -> NetlistMonad HWType
-- | Turns a Core variable reference to a Netlist expression. Errors if the
-- term is not a variable.
varToExpr :: Term -> Expr
-- | Uniquely rename all the variables and their references in a normalized
-- term
mkUniqueNormalized :: ([Id], [LetBinding], Id) -> NetlistMonad ([Id], [LetBinding], TmName)
-- | Append a string to a name
appendToName :: TmName -> String -> TmName
-- | Preserve the Netlist _varEnv and _varCount when
-- executing a monadic action
preserveVarEnv :: NetlistMonad a -> NetlistMonad a
-- | Generate VHDL for assorted Netlist datatypes
module CLaSH.Netlist.VHDL
-- | Generate VHDL for a Netlist component
genVHDL :: Component -> VHDLM (String, Doc)
-- | Generate a VHDL package containing type definitions for the given
-- HWTypes
mkTyPackage :: [HWType] -> VHDLM Doc
-- | Convert a Netlist HWType to a VHDL type
vhdlType :: HWType -> VHDLM Doc
-- | Convert a Netlist HWType to a default VHDL value for that type
vhdlTypeDefault :: HWType -> VHDLM Doc
-- | Convert a Netlist HWType to the root of a VHDL type
vhdlTypeMark :: HWType -> VHDLM Doc
-- | Turn a Netlist Declaration to a VHDL concurrent block
inst :: Declaration -> VHDLM (Maybe Doc)
-- | Turn a Netlist expression into a VHDL expression
expr :: Bool -> Expr -> VHDLM Doc
-- | Utilties to verify blackbox contexts against templates and rendering
-- filled in templates
module CLaSH.Netlist.BlackBox.Util
-- | Determine if the number of normalliteralfunction inputs of a
-- blackbox context at least matches the number of argument that is
-- expected by the template.
verifyBlackBoxContext :: BlackBoxTemplate -> BlackBoxContext -> Bool
-- | Count the number of argument tags/holes in a blackbox template
countArgs :: BlackBoxTemplate -> Int
-- | Counter the number of literal tags/holes in a blackbox template
countLits :: BlackBoxTemplate -> Int
-- | Count the number of function instantiations in a blackbox template
countFuns :: BlackBoxTemplate -> Int
-- | Update all the symbol references in a template, and increment the
-- symbol counter for every newly encountered symbol.
setSym :: Int -> BlackBoxTemplate -> (BlackBoxTemplate, Int)
-- | Get the name of the clock of an identifier
clkSyncId :: SyncIdentifier -> Identifier
-- | Render a blackbox given a certain context. Returns a filled out
-- template and a list of hidden inputs that must be added to
-- the encompassing component.
renderBlackBox :: BlackBoxTemplate -> BlackBoxContext -> VHDLState -> ((Text, [(Identifier, HWType)]), VHDLState)
-- | Render a single template element
renderElem :: BlackBoxContext -> Element -> BlackBoxMonad Text
-- | Fill out the template corresponding to an output/input assignment of a
-- component instantiation, and turn it into a single identifier so it
-- can be used for a new blackbox context.
lineToIdentifier :: BlackBoxContext -> BlackBoxTemplate -> BlackBoxMonad (SyncIdentifier, HWType)
-- | Give a context and a tagged hole (of a template), returns part of the
-- context that matches the tag of the hole.
mkSyncIdentifier :: BlackBoxContext -> Element -> BlackBoxMonad SyncIdentifier
-- | Utilities for rewriting: e.g. inlining, specialisation, etc.
module CLaSH.Rewrite.Util
-- | Lift an action working in the inner monad to the RewriteMonad
liftR :: Monad m => m a -> RewriteMonad m a
-- | Lift an action working in the inner monad to the RewriteSession
liftRS :: Monad m => m a -> RewriteSession m a
-- | Record if a transformation is succesfully applied
apply :: (Monad m, Functor m) => String -> Rewrite m -> Rewrite m
-- | Perform a transformation on a Term
runRewrite :: (Monad m, Functor m) => String -> Rewrite m -> Term -> RewriteSession m Term
-- | Evaluate a RewriteSession to its inner monad
runRewriteSession :: Monad m => DebugLevel -> RewriteState -> RewriteSession m a -> m a
-- | Notify that a transformation has changed the expression
setChanged :: Monad m => RewriteMonad m ()
-- | Identity function that additionally notifies that a transformation has
-- changed the expression
changed :: Monad m => a -> RewriteMonad m a
-- | Create a type and kind context out of a transformation context
contextEnv :: [CoreContext] -> (Gamma, Delta)
-- | Create a complete type and kind context out of the global binders and
-- the transformation context
mkEnv :: (Functor m, Monad m) => [CoreContext] -> RewriteMonad m (Gamma, Delta)
-- | Make a new binder and variable reference for a term
mkTmBinderFor :: (Functor m, Fresh m, MonadUnique m) => String -> Term -> m (Id, Term)
-- | Make a new binder and variable reference for either a term or a type
mkBinderFor :: (Functor m, Monad m, MonadUnique m, Fresh m) => String -> Either Term Type -> m (Either (Id, Term) (TyVar, Type))
-- | Make a new, unique, identifier and corresponding variable reference
mkInternalVar :: (Functor m, Monad m, MonadUnique m) => String -> KindOrType -> m (Id, Term)
-- | Inline the binders in a let-binding that have a certain property
inlineBinders :: Monad m => (LetBinding -> RewriteMonad m Bool) -> Rewrite m
-- | Substitute the RHS of the first set of Let-binders for references to
-- the first set of Let-binders in: the second set of Let-binders and the
-- additional term
substituteBinders :: [LetBinding] -> [LetBinding] -> Term -> ([LetBinding], Term)
-- | Calculate the local free variable of an expression: the free
-- variables that are not bound in the global environment.
localFreeVars :: (Functor m, Monad m, Collection c) => Term -> RewriteMonad m (c TyName, c TmName)
-- | Lift the binders in a let-binding to a global function that have a
-- certain property
liftBinders :: (Functor m, Monad m) => (LetBinding -> RewriteMonad m Bool) -> Rewrite m
-- | Create a global function for a Let-binding and return a Let-binding
-- where the RHS is a reference to the new global function applied to the
-- free variables of the original RHS
liftBinding :: (Functor m, Monad m) => Gamma -> Delta -> LetBinding -> RewriteMonad m LetBinding
-- | Make a global function for a name-term tuple
mkFunction :: (Functor m, Monad m) => TmName -> Term -> RewriteMonad m (TmName, Type)
-- | Add a function to the set of global binders
addGlobalBind :: (Functor m, Monad m) => TmName -> Type -> Term -> RewriteMonad m ()
-- | Create a new name out of the given name, but with another unique
cloneVar :: (Functor m, Monad m) => TmName -> RewriteMonad m TmName
-- | Test whether a term is a variable reference to a local binder
isLocalVar :: (Functor m, Monad m) => Term -> RewriteMonad m Bool
-- | Determine if a term cannot be represented in hardware
isUntranslatable :: (Functor m, Monad m) => Term -> RewriteMonad m Bool
-- | Is the Context a Lambda/Term-abstraction context?
isLambdaBodyCtx :: CoreContext -> Bool
-- | Make a binder that should not be referenced
mkWildValBinder :: (Functor m, Monad m, MonadUnique m) => Type -> m Id
-- | Make a case-decomposition that extracts a field out of a
-- (Sum-of-)Product type
mkSelectorCase :: (Functor m, Monad m, MonadUnique m, Fresh m) => String -> [CoreContext] -> Term -> Int -> Int -> m Term
-- | Specialise an application on its argument
specialise :: (Functor m, MonadState s m) => Lens' s (Map (TmName, Int, Either Term Type) (TmName, Type)) -> Rewrite m
-- | Specialise an application on its argument
specialise' :: (Functor m, MonadState s m) => Lens' s (Map (TmName, Int, Either Term Type) (TmName, Type)) -> [CoreContext] -> Term -> (Term, [Either Term Type]) -> Either Term Type -> R m Term
-- | Create binders and variable references for free variables in
-- specArg
specArgBndrsAndVars :: (Functor m, Monad m) => [CoreContext] -> Either Term Type -> RewriteMonad m ([Either Id TyVar], [Either Term Type])
-- | Utility functions used by the normalisation transformations
module CLaSH.Normalize.Util
-- | Determine if a function is already inlined in the context of the
-- NetlistMonad
alreadyInlined :: TmName -> NormalizeMonad Bool
-- | Move the names of inlined functions collected during a traversal into
-- the permanent inlined function cache
commitNewInlined :: NormRewrite
-- | Determine if a term is closed
isClosed :: (Functor m, Fresh m) => Term -> m Bool
-- | Determine if a term represents a constant
isConstant :: Term -> Bool
-- | Get the "Wrapped" function out of a normalized Term. Returns
-- Nothing if the normalized term is not actually a wrapper.
getWrappedF :: (Fresh m, Functor m) => Term -> m (Maybe Term)
-- | Create a call graph for a set of global binders, given a root
callGraph :: [TmName] -> HashMap TmName Term -> TmName -> [(TmName, [TmName])]
-- | Determine the sets of recursive components given the edges of a
-- callgraph
recursiveComponents :: [(TmName, [TmName])] -> [[TmName]]
-- | Functions to create BlackBox Contexts and fill in BlackBox templates
module CLaSH.Netlist.BlackBox
-- | Generate the context for a BlackBox instantiation.
mkBlackBoxContext :: Id -> [Term] -> NetlistMonad (BlackBoxContext, [Declaration])
-- | Instantiate a BlackBox template according to the given context
mkBlackBox :: Text -> BlackBoxContext -> NetlistMonad Text
-- | Create an template instantiation text for an argument term
mkInput :: (Term, Bool) -> MaybeT NetlistMonad ((SyncIdentifier, HWType), [Declaration])
-- | Create an template instantiation text for an argument term, given that
-- the term is a literal. Returns Nothing if the term is not a
-- literal.
mkLitInput :: Term -> MaybeT NetlistMonad ((Identifier, HWType), [Declaration])
-- | Create an template instantiation text and a partial blackbox content
-- for an argument term, given that the term is a function. Errors if the
-- term is not a function
mkFunInput :: Id -> Term -> MaybeT NetlistMonad ((BlackBoxTemplate, BlackBoxContext), [Declaration])
-- | Instantiate symbols references with a new symbol and increment symbol
-- counter
instantiateSym :: BlackBoxTemplate -> NetlistMonad BlackBoxTemplate
-- | Create Netlists out of normalized CoreHW Terms
module CLaSH.Netlist
-- | Generate a hierarchical netlist out of a set of global binders with
-- topEntity at the top.
genNetlist :: Maybe VHDLState -> HashMap TmName (Type, Term) -> PrimMap -> (Type -> Maybe (Either String HWType)) -> Maybe Int -> TmName -> IO ([Component], VHDLState)
-- | Run a NetlistMonad action in a given environment
runNetlistMonad :: Maybe VHDLState -> HashMap TmName (Type, Term) -> PrimMap -> (Type -> Maybe (Either String HWType)) -> NetlistMonad a -> IO (a, NetlistState)
-- | Generate a component for a given function (caching)
genComponent :: TmName -> Maybe Int -> NetlistMonad Component
-- | Generate a component for a given function
genComponentT :: TmName -> Term -> Maybe Int -> NetlistMonad Component
-- | Generate a list of Declarations for a let-binder
mkDeclarations :: Id -> Term -> NetlistMonad [Declaration]
-- | Generate a list of Declarations for a let-binder where the RHS is a
-- function application
mkFunApp :: Id -> TmName -> [Term] -> NetlistMonad [Declaration]
-- | Generate an expression for a term occurring on the RHS of a let-binder
mkExpr :: Type -> Term -> NetlistMonad (Expr, [Declaration])
-- | Generate an expression for a DataCon application occurring on the RHS
-- of a let-binder
mkDcApplication :: HWType -> DataCon -> [Term] -> NetlistMonad (Expr, [Declaration])
-- | Transformations of the Normalization process
module CLaSH.Normalize.Transformations
-- | Propagate arguments of application inwards; except for Lam
-- where the argument becomes let-bound.
appProp :: NormRewrite
-- | Inline non-recursive, non-representable let-bindings
bindNonRep :: NormRewrite
-- | Lift recursive, non-representable let-bindings
liftNonRep :: NormRewrite
-- | Lift the let-bindings out of the subject of a Case-decomposition
caseLet :: NormRewrite
-- | Specialize a Case-decomposition (replace by the RHS of an alternative)
-- if the subject is (an application of) a DataCon; or if there is only a
-- single alternative that doesn't reference variables bound by the
-- pattern.
caseCon :: NormRewrite
-- | Move a Case-decomposition from the subject of a Case-decomposition to
-- the alternatives
caseCase :: NormRewrite
-- | Inline function with a non-representable result if it's the subject of
-- a Case-decomposition
inlineNonRep :: NormRewrite
-- | Specialize functions on their type
typeSpec :: NormRewrite
-- | Specialize functions on their non-representable argument
nonRepSpec :: NormRewrite
-- | Eta-expand top-level lambda's (DON'T use in a traversal!)
etaExpansionTL :: NormRewrite
-- | Inline nullary/closed functions
inlineClosedTerm :: String -> NormRewrite -> NormRewrite
-- | Bring an application of a DataCon or Primitive in ANF, when the
-- argument is is considered non-representable
nonRepANF :: NormRewrite
-- | Inline let-bindings when the RHS is either a local variable reference
-- or is constant
bindConstantVar :: NormRewrite
-- | Specialise functions on arguments which are constant
constantSpec :: NormRewrite
-- | Turn an expression into a modified ANF-form. As opposed to standard
-- ANF, constants do not become let-bound.
makeANF :: NormRewrite
-- | Remove unused let-bindings
deadCode :: NormRewrite
-- | Ensure that top-level lambda's eventually bind a let-expression of
-- which the body is a variable-reference.
topLet :: NormRewrite
-- | Inline functions which simply "wrap" another function
inlineWrapper :: NormRewrite
-- | Turn a normalized recursive function, where the recursive calls only
-- pass along the unchanged original arguments, into let-recursive
-- function. This means that all recursive calls are replaced by the same
-- variable reference as found in the body of the top-level
-- let-expression.
recToLetRec :: NormRewrite
-- | Transformation process for normalization
module CLaSH.Normalize.Strategy
-- | Normalisation transformation
normalization :: NormRewrite
-- | Simple cleanup transformation, currently only inlines "Wrappers"
cleanup :: NormRewrite
-- | Unsure that functions have representable arguments, results, and
-- let-bindings
representable :: NormRewrite
-- | Brings representable function in the desired normal form:
--
--
-- - Only top-level lambda's
-- - Single Lambda-bound top-level Let-binding, where the body is a
-- variable reference
-- - Modified ANF (constants are not let-bound, non-representable
-- arguments to primitives are not let-bound)
-- - All let-bindings are representable
--
simplification :: NormRewrite
-- | Perform an inlining transformation using a bottomup traversal, and
-- commit inlined function names to the inlining log/cachce
doInline :: String -> NormRewrite -> NormRewrite
-- | Repeatedly apply a set of transformation in a bottom-up traversal
repeatBottomup :: [(String, NormRewrite)] -> NormRewrite
-- | Turn CoreHW terms into normalized CoreHW Terms
module CLaSH.Normalize
-- | Run a NormalizeSession in a given environment
runNormalization :: DebugLevel -> Supply -> HashMap TmName (Type, Term) -> (Type -> Maybe (Either String HWType)) -> NormalizeSession a -> a
-- | Normalize a list of global binders
normalize :: [TmName] -> NormalizeSession [(TmName, (Type, Term))]
-- | Rewrite a term according to the provided transformation
rewriteExpr :: (String, NormRewrite) -> (String, Term) -> NormalizeSession Term
-- | Perform general "clean up" of the normalized (non-recursive) function
-- hierarchy. This includes:
--
--
-- - Inlining functions that simply "wrap" another function
--
cleanupGraph :: [TmName] -> [(TmName, (Type, Term))] -> NormalizeSession [(TmName, (Type, Term))]
-- | Check if the call graph (second argument), starting at the
-- topEnity (first argument) is non-recursive. Returns the list
-- of normalized terms if call graph is indeed non-recursive, errors
-- otherwise.
checkNonRecursive :: TmName -> [(TmName, (Type, Term))] -> [(TmName, (Type, Term))]
-- | Generate a VHDL testbench for a component given a set of stimuli and a
-- set of matching expected outputs
module CLaSH.Driver.TestbenchGen
-- | Generate a VHDL testbench for a component given a set of stimuli and a
-- set of matching expected outputs
genTestBench :: DebugLevel -> Supply -> PrimMap -> (Type -> Maybe (Either String HWType)) -> VHDLState -> HashMap TmName (Type, Term) -> Maybe TmName -> Maybe TmName -> Component -> IO ([Component], VHDLState)
-- | Module that connects all the parts of the CLaSH compiler library
module CLaSH.Driver
-- | Create a set of .VHDL files for a set of functions
generateVHDL :: BindingMap -> PrimMap -> (Type -> Maybe (Either String HWType)) -> DebugLevel -> IO ()
-- | Pretty print Components to VHDL Documents
createVHDL :: VHDLState -> [Component] -> [(String, Doc)]
-- | Prepares the directory for writing VHDL files. This means creating the
-- dir if it does not exist and removing all existing .vhdl files from
-- it.
prepareDir :: String -> IO ()
-- | Writes a VHDL file to the given directory
writeVHDL :: FilePath -> (String, Doc) -> IO ()