-- 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 CλaSH compiler transforms
-- these high-level descriptions to low-level synthesizable VHDL,
-- Verilog, or SystemVerilog.
--
-- Features of CλaSH:
--
--
-- - Strongly typed (like VHDL), yet with a very high degree of type
-- inference, which enables both safe and fast prototying using consise
-- descriptions (like Verilog)
-- - Interactive REPL: load your designs in an interpreter and easily
-- test all your component without needing to setup a test bench.
-- - Higher-order functions, with type inference, result in designs
-- that are fully parametric by default.
-- - Synchronous sequential circuit design based on streams of values,
-- called Signals.
-- - Support for multiple clock domains, with type safe clock domain
-- crossing.
--
--
-- 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
-- - Blackbox/Primitive Handling
--
--
-- Front-ends (for: parsing, typecheck, etc.) are provided by separate
-- packages:
--
--
--
-- Prelude library:
-- http://hackage.haskell.org/package/clash-prelude
@package clash-lib
@version 0.5.13
-- | Transform/format a Netlist Identifier so that it is acceptable as a
-- HDL identifier
module CLaSH.Netlist.Id
-- | Transform/format a text so that it is acceptable as a HDL identifier
mkBasicId :: Text -> Text
mkBasicId' :: Bool -> Text -> Text
stripDollarPrefixes :: Text -> Text
-- | Types used in BlackBox modules
module CLaSH.Netlist.BlackBox.Types
-- | 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
-- | Error value hole
Err :: !(Maybe Int) -> Element
-- | Select element type from a vector type
TypElem :: !Element -> Element
-- | Hole for the name of the component in which the blackbox is
-- instantiated
CompName :: Element
-- | Size of a type hole
Size :: !Element -> Element
-- | Length of a vector hole
Length :: !Element -> Element
-- | Hole containing a filepath for a data file
FilePath :: !Element -> Element
-- | Hole marking beginning (True) or end (False) of a generative construct
Gen :: !Bool -> Element
SigD :: [Element] -> !(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.
--
-- The LHS of the tuple is the name of the signal, while the RHS of the
-- tuple is the type of the signal
data Decl
Decl :: !Int -> [(BlackBoxTemplate, BlackBoxTemplate)] -> Decl
instance GHC.Show.Show CLaSH.Netlist.BlackBox.Types.Element
instance GHC.Show.Show CLaSH.Netlist.BlackBox.Types.Decl
-- | 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])
-- | Type and instance definitions for Primitive
module CLaSH.Primitives.Types
-- | Primitive Definitions
type PrimMap = HashMap Text Primitive
-- | Externally defined primitive
data Primitive
-- | A primitive that has a template that can be filled out by the backend
-- render
BlackBox :: !Text -> !(Either Text Text) -> Primitive
-- | Name of the primitive
[name] :: Primitive -> !Text
-- | Either a declaration or an expression template.
[template] :: Primitive -> !(Either Text Text)
-- | A primitive that carries additional information
Primitive :: !Text -> !Text -> Primitive
-- | Name of the primitive
[name] :: Primitive -> !Text
-- | Additional information
[primType] :: Primitive -> !Text
instance GHC.Show.Show CLaSH.Primitives.Types.Primitive
instance Data.Aeson.Types.Class.FromJSON CLaSH.Primitives.Types.Primitive
-- | Assortment of utility function used in the CLaSH library
module CLaSH.Util
-- | A class that can generate unique numbers
class MonadUnique m
-- | Get a new unique
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
makeCachedT3S :: (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))), NFData v) => 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)
combineM :: (Applicative f) => (a -> f b) -> (c -> f d) -> (a, c) -> f (b, d)
-- | 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])
clashLibVersion :: Version
-- | ceiling (log_2(c))
clog2 :: (Integral a, Integral c) => a -> c
-- | Build lenses (and traversals) with a sensible default configuration.
--
-- e.g.
--
--
-- data FooBar
-- = Foo { _x, _y :: Int }
-- | Bar { _x :: Int }
-- makeLenses ''FooBar
--
--
-- will create
--
--
-- x :: Lens' FooBar Int
-- x f (Foo a b) = (\a' -> Foo a' b) <$> f a
-- x f (Bar a) = Bar <$> f a
-- y :: Traversal' FooBar Int
-- y f (Foo a b) = (\b' -> Foo a b') <$> f b
-- y _ c@(Bar _) = pure c
--
--
--
-- makeLenses = makeLensesWith lensRules
--
makeLenses :: Name -> DecsQ
instance GHC.Base.Monad m => CLaSH.Util.MonadUnique (Control.Monad.Trans.State.Lazy.StateT GHC.Types.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
-- | 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 GHC.Generics.Selector CLaSH.Core.Var.S1_1_1Var
instance GHC.Generics.Selector CLaSH.Core.Var.S1_1_0Var
instance GHC.Generics.Selector CLaSH.Core.Var.S1_0_1Var
instance GHC.Generics.Selector CLaSH.Core.Var.S1_0_0Var
instance GHC.Generics.Constructor CLaSH.Core.Var.C1_1Var
instance GHC.Generics.Constructor CLaSH.Core.Var.C1_0Var
instance GHC.Generics.Datatype CLaSH.Core.Var.D1Var
instance Control.DeepSeq.NFData (CLaSH.Core.Var.Var a)
instance GHC.Generics.Generic (CLaSH.Core.Var.Var a)
instance GHC.Show.Show (CLaSH.Core.Var.Var a)
instance GHC.Classes.Eq (CLaSH.Core.Var.Var a)
instance (Data.Typeable.Internal.Typeable a, Unbound.Generics.LocallyNameless.Alpha.Alpha a) => Unbound.Generics.LocallyNameless.Alpha.Alpha (CLaSH.Core.Var.Var a)
instance GHC.Generics.Generic b => Unbound.Generics.LocallyNameless.Subst.Subst CLaSH.Core.Term.Term (CLaSH.Core.Var.Var b)
instance GHC.Generics.Generic b => Unbound.Generics.LocallyNameless.Subst.Subst CLaSH.Core.Type.Type (CLaSH.Core.Var.Var b)
-- | 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 Nothing is returned.
dataConInstArgTys :: DataCon -> [Type] -> Maybe [Type]
instance GHC.Generics.Selector CLaSH.Core.DataCon.S1_0_5DataCon
instance GHC.Generics.Selector CLaSH.Core.DataCon.S1_0_4DataCon
instance GHC.Generics.Selector CLaSH.Core.DataCon.S1_0_3DataCon
instance GHC.Generics.Selector CLaSH.Core.DataCon.S1_0_2DataCon
instance GHC.Generics.Selector CLaSH.Core.DataCon.S1_0_1DataCon
instance GHC.Generics.Selector CLaSH.Core.DataCon.S1_0_0DataCon
instance GHC.Generics.Constructor CLaSH.Core.DataCon.C1_0DataCon
instance GHC.Generics.Datatype CLaSH.Core.DataCon.D1DataCon
instance Control.DeepSeq.NFData CLaSH.Core.DataCon.DataCon
instance GHC.Generics.Generic CLaSH.Core.DataCon.DataCon
instance GHC.Show.Show CLaSH.Core.DataCon.DataCon
instance GHC.Classes.Eq CLaSH.Core.DataCon.DataCon
instance GHC.Classes.Ord CLaSH.Core.DataCon.DataCon
instance Unbound.Generics.LocallyNameless.Alpha.Alpha CLaSH.Core.DataCon.DataCon
instance Unbound.Generics.LocallyNameless.Subst.Subst a CLaSH.Core.DataCon.DataCon
-- | Type Constructors in CoreHW
module CLaSH.Core.TyCon
-- | Type Constructor
data TyCon
-- | Algorithmic DataCons
AlgTyCon :: !TyConName -> !Kind -> !Int -> !AlgTyConRhs -> TyCon
-- | Name of the TyCon
[tyConName] :: TyCon -> !TyConName
-- | Kind of the TyCon
[tyConKind] :: TyCon -> !Kind
-- | Number of type arguments
[tyConArity] :: TyCon -> !Int
-- | DataCon definitions
[algTcRhs] :: TyCon -> !AlgTyConRhs
-- | Function TyCons (e.g. type families)
FunTyCon :: !TyConName -> !Kind -> !Int -> [([Type], Type)] -> TyCon
-- | Name of the TyCon
[tyConName] :: TyCon -> !TyConName
-- | Kind of the TyCon
[tyConKind] :: TyCon -> !Kind
-- | Number of type arguments
[tyConArity] :: TyCon -> !Int
-- | List of: ([LHS match types], RHS type)
[tyConSubst] :: TyCon -> [([Type], Type)]
-- | Primitive TyCons
PrimTyCon :: !TyConName -> !Kind -> !Int -> TyCon
-- | Name of the TyCon
[tyConName] :: TyCon -> !TyConName
-- | Kind of the TyCon
[tyConKind] :: TyCon -> !Kind
-- | Number of type arguments
[tyConArity] :: TyCon -> !Int
-- | To close the loop on the type hierarchy
SuperKindTyCon :: !TyConName -> 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)
-- | Create a Kind out of a TyConName
mkKindTyCon :: TyConName -> Kind -> TyCon
-- | Does the TyCon look like a tuple TyCon
isTupleTyConLike :: TyConName -> Bool
-- | Get the DataCons belonging to a TyCon
tyConDataCons :: TyCon -> [DataCon]
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_1_1AlgTyConRhs
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_1_0AlgTyConRhs
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_0_0AlgTyConRhs
instance GHC.Generics.Constructor CLaSH.Core.TyCon.C1_1AlgTyConRhs
instance GHC.Generics.Constructor CLaSH.Core.TyCon.C1_0AlgTyConRhs
instance GHC.Generics.Datatype CLaSH.Core.TyCon.D1AlgTyConRhs
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_3_0TyCon
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_2_2TyCon
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_2_1TyCon
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_2_0TyCon
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_1_3TyCon
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_1_2TyCon
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_1_1TyCon
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_1_0TyCon
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_0_3TyCon
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_0_2TyCon
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_0_1TyCon
instance GHC.Generics.Selector CLaSH.Core.TyCon.S1_0_0TyCon
instance GHC.Generics.Constructor CLaSH.Core.TyCon.C1_3TyCon
instance GHC.Generics.Constructor CLaSH.Core.TyCon.C1_2TyCon
instance GHC.Generics.Constructor CLaSH.Core.TyCon.C1_1TyCon
instance GHC.Generics.Constructor CLaSH.Core.TyCon.C1_0TyCon
instance GHC.Generics.Datatype CLaSH.Core.TyCon.D1TyCon
instance Unbound.Generics.LocallyNameless.Alpha.Alpha CLaSH.Core.TyCon.AlgTyConRhs
instance Control.DeepSeq.NFData CLaSH.Core.TyCon.AlgTyConRhs
instance GHC.Generics.Generic CLaSH.Core.TyCon.AlgTyConRhs
instance GHC.Show.Show CLaSH.Core.TyCon.AlgTyConRhs
instance Control.DeepSeq.NFData CLaSH.Core.TyCon.TyCon
instance GHC.Generics.Generic CLaSH.Core.TyCon.TyCon
instance GHC.Show.Show CLaSH.Core.TyCon.TyCon
instance GHC.Classes.Eq CLaSH.Core.TyCon.TyCon
instance GHC.Classes.Ord CLaSH.Core.TyCon.TyCon
instance Unbound.Generics.LocallyNameless.Alpha.Alpha CLaSH.Core.TyCon.TyCon
-- | Builtin Type and Kind definitions
module CLaSH.Core.TysPrim
liftedTypeKind :: Type
typeNatKind :: Type
typeSymbolKind :: Type
intPrimTy :: Type
stringPrimTy :: Type
voidPrimTy :: Type
tysPrimMap :: HashMap TyConName TyCon
-- | Term Literal
module CLaSH.Core.Literal
-- | Term Literal
data Literal
IntegerLiteral :: !Integer -> Literal
StringLiteral :: !String -> Literal
RationalLiteral :: !Rational -> Literal
-- | Determines the Type of a Literal
literalType :: Literal -> Type
instance GHC.Generics.Constructor CLaSH.Core.Literal.C1_2Literal
instance GHC.Generics.Constructor CLaSH.Core.Literal.C1_1Literal
instance GHC.Generics.Constructor CLaSH.Core.Literal.C1_0Literal
instance GHC.Generics.Datatype CLaSH.Core.Literal.D1Literal
instance Control.DeepSeq.NFData CLaSH.Core.Literal.Literal
instance GHC.Generics.Generic CLaSH.Core.Literal.Literal
instance GHC.Show.Show CLaSH.Core.Literal.Literal
instance GHC.Classes.Ord CLaSH.Core.Literal.Literal
instance GHC.Classes.Eq CLaSH.Core.Literal.Literal
instance Unbound.Generics.LocallyNameless.Alpha.Alpha CLaSH.Core.Literal.Literal
instance Unbound.Generics.LocallyNameless.Subst.Subst a CLaSH.Core.Literal.Literal
-- | 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 :: !Text -> !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 GHC.Generics.Constructor CLaSH.Core.Term.C1_2Pat
instance GHC.Generics.Constructor CLaSH.Core.Term.C1_1Pat
instance GHC.Generics.Constructor CLaSH.Core.Term.C1_0Pat
instance GHC.Generics.Datatype CLaSH.Core.Term.D1Pat
instance GHC.Generics.Constructor CLaSH.Core.Term.C1_9Term
instance GHC.Generics.Constructor CLaSH.Core.Term.C1_8Term
instance GHC.Generics.Constructor CLaSH.Core.Term.C1_7Term
instance GHC.Generics.Constructor CLaSH.Core.Term.C1_6Term
instance GHC.Generics.Constructor CLaSH.Core.Term.C1_5Term
instance GHC.Generics.Constructor CLaSH.Core.Term.C1_4Term
instance GHC.Generics.Constructor CLaSH.Core.Term.C1_3Term
instance GHC.Generics.Constructor CLaSH.Core.Term.C1_2Term
instance GHC.Generics.Constructor CLaSH.Core.Term.C1_1Term
instance GHC.Generics.Constructor CLaSH.Core.Term.C1_0Term
instance GHC.Generics.Datatype CLaSH.Core.Term.D1Term
instance Unbound.Generics.LocallyNameless.Alpha.Alpha CLaSH.Core.Term.Pat
instance Control.DeepSeq.NFData CLaSH.Core.Term.Pat
instance GHC.Generics.Generic CLaSH.Core.Term.Pat
instance GHC.Show.Show CLaSH.Core.Term.Pat
instance Control.DeepSeq.NFData CLaSH.Core.Term.Term
instance GHC.Generics.Generic CLaSH.Core.Term.Term
instance GHC.Show.Show CLaSH.Core.Term.Term
instance GHC.Classes.Eq CLaSH.Core.Term.Term
instance GHC.Classes.Ord CLaSH.Core.Term.Term
instance Unbound.Generics.LocallyNameless.Alpha.Alpha CLaSH.Core.Term.Term
instance Unbound.Generics.LocallyNameless.Subst.Subst CLaSH.Core.Type.Type CLaSH.Core.Term.Pat
instance Unbound.Generics.LocallyNameless.Subst.Subst CLaSH.Core.Term.Term CLaSH.Core.Term.Pat
instance Unbound.Generics.LocallyNameless.Subst.Subst CLaSH.Core.Term.Term CLaSH.Core.Term.Term
instance Unbound.Generics.LocallyNameless.Subst.Subst CLaSH.Core.Type.Type CLaSH.Core.Term.Term
-- | 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 :: !TyConName -> [Type] -> TypeView
-- | Neither of the above
OtherType :: !Type -> TypeView
-- | Type Constants
data ConstTy
-- | TyCon type
TyCon :: !TyConName -> 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, and type functions are evaluated when possible.
coreView :: HashMap TyConName TyCon -> Type -> TypeView
-- | A transformation that renders Signal types transparent
transparentTy :: Type -> Type
-- | Determine the kind of a type
typeKind :: HashMap TyConName TyCon -> Type -> Kind
-- | Make a Type out of a TyCon
mkTyConTy :: TyConName -> 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 :: TyConName -> [Type] -> Type
-- | Split a function type in an argument and result type
splitFunTy :: HashMap TyConName TyCon -> Type -> Maybe (Type, Type)
splitFunTys :: HashMap TyConName TyCon -> Type -> ([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 (TyConName, [Type])
-- | Is a type a polymorphic or function type?
isPolyFunTy :: Type -> Bool
-- | Is a type a polymorphic or function type under coreView?
isPolyFunCoreTy :: HashMap TyConName TyCon -> Type -> Bool
-- | Is a type polymorphic?
isPolyTy :: Type -> Bool
-- | Is a type a function type?
isFunTy :: HashMap TyConName TyCon -> Type -> Bool
-- | Apply a function type to an argument type and get the result type
applyFunTy :: HashMap TyConName TyCon -> Type -> Type -> Type
-- | Substitute the type variable of a type (ForAllTy) with another
-- type
applyTy :: Fresh m => HashMap TyConName TyCon -> Type -> KindOrType -> m Type
findFunSubst :: [([Type], Type)] -> [Type] -> Maybe Type
instance GHC.Generics.Constructor CLaSH.Core.Type.C1_1ConstTy
instance GHC.Generics.Constructor CLaSH.Core.Type.C1_0ConstTy
instance GHC.Generics.Datatype CLaSH.Core.Type.D1ConstTy
instance GHC.Generics.Constructor CLaSH.Core.Type.C1_4Type
instance GHC.Generics.Constructor CLaSH.Core.Type.C1_3Type
instance GHC.Generics.Constructor CLaSH.Core.Type.C1_2Type
instance GHC.Generics.Constructor CLaSH.Core.Type.C1_1Type
instance GHC.Generics.Constructor CLaSH.Core.Type.C1_0Type
instance GHC.Generics.Datatype CLaSH.Core.Type.D1Type
instance GHC.Generics.Constructor CLaSH.Core.Type.C1_1LitTy
instance GHC.Generics.Constructor CLaSH.Core.Type.C1_0LitTy
instance GHC.Generics.Datatype CLaSH.Core.Type.D1LitTy
instance GHC.Show.Show CLaSH.Core.Type.TypeView
instance Unbound.Generics.LocallyNameless.Alpha.Alpha CLaSH.Core.Type.ConstTy
instance Control.DeepSeq.NFData CLaSH.Core.Type.ConstTy
instance GHC.Generics.Generic CLaSH.Core.Type.ConstTy
instance GHC.Show.Show CLaSH.Core.Type.ConstTy
instance Control.DeepSeq.NFData CLaSH.Core.Type.Type
instance GHC.Generics.Generic CLaSH.Core.Type.Type
instance GHC.Show.Show CLaSH.Core.Type.Type
instance Unbound.Generics.LocallyNameless.Alpha.Alpha CLaSH.Core.Type.LitTy
instance Control.DeepSeq.NFData CLaSH.Core.Type.LitTy
instance GHC.Generics.Generic CLaSH.Core.Type.LitTy
instance GHC.Show.Show CLaSH.Core.Type.LitTy
instance Unbound.Generics.LocallyNameless.Alpha.Alpha CLaSH.Core.Type.Type
instance Unbound.Generics.LocallyNameless.Subst.Subst a CLaSH.Core.Type.LitTy
instance Unbound.Generics.LocallyNameless.Subst.Subst a CLaSH.Core.Type.ConstTy
instance Unbound.Generics.LocallyNameless.Subst.Subst CLaSH.Core.Term.Term CLaSH.Core.Type.Type
instance Unbound.Generics.LocallyNameless.Subst.Subst CLaSH.Core.Type.Type CLaSH.Core.Type.Type
instance GHC.Classes.Eq CLaSH.Core.Type.Type
instance GHC.Classes.Ord CLaSH.Core.Type.Type
-- | Free variable calculations
module CLaSH.Core.FreeVars
-- | Gives the free type-variables in a Type
typeFreeVars :: Fold Type TyName
-- | Gives the free term-variables of a Term
termFreeIds :: Fold Term TmName
-- | Gives the free type-variables of a Term
termFreeTyVars :: Fold Term TyName
-- | 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 GHC.Classes.Ord CLaSH.Core.Pretty.TypePrec
instance GHC.Classes.Eq CLaSH.Core.Pretty.TypePrec
instance CLaSH.Core.Pretty.Pretty (Unbound.Generics.LocallyNameless.Name.Name a)
instance CLaSH.Core.Pretty.Pretty a => CLaSH.Core.Pretty.Pretty [a]
instance CLaSH.Core.Pretty.Pretty (CLaSH.Core.Var.Id, CLaSH.Core.Term.Term)
instance CLaSH.Core.Pretty.Pretty CLaSH.Core.Type.Type
instance CLaSH.Core.Pretty.Pretty (CLaSH.Core.Var.Var CLaSH.Core.Type.Type)
instance CLaSH.Core.Pretty.Pretty CLaSH.Core.TyCon.TyCon
instance CLaSH.Core.Pretty.Pretty CLaSH.Core.Type.LitTy
instance CLaSH.Core.Pretty.Pretty CLaSH.Core.Term.Term
instance CLaSH.Core.Pretty.Pretty (CLaSH.Core.Var.Var CLaSH.Core.Term.Term)
instance CLaSH.Core.Pretty.Pretty CLaSH.Core.DataCon.DataCon
instance CLaSH.Core.Pretty.Pretty CLaSH.Core.Literal.Literal
instance CLaSH.Core.Pretty.Pretty CLaSH.Core.Term.Pat
-- | 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) => HashMap TyConName TyCon -> 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 => HashMap TyConName TyCon -> 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) => HashMap TyConName TyCon -> Term -> m Bool
-- | Does a term have a function or polymorphic type?
isPolyFun :: (Functor m, Fresh m) => HashMap TyConName TyCon -> 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
termSize :: Term -> Int
-- | Create a vector of supplied elements
mkVec :: DataCon -> DataCon -> Type -> Int -> [Term] -> Term
-- | Create let-bindings with case-statements that select elements out of a
-- vector. Returns both the variables to which element-selections are
-- bound and the let-bindings
extractElems :: DataCon -> Type -> Char -> Int -> Term -> [(Term, [LetBinding])]
-- | Determine whether a type is isomorphic to
-- CLaSH.Signal.Internal.Signal'
--
-- It is i.e.:
--
--
-- - Signal' clk a
-- - (Signal' clk a, Signal' clk b)
-- - Vec n (Signal' clk a)
-- - data Wrap = W (Signal clk' Int)
-- - etc.
--
isSignalType :: HashMap TyConName TyCon -> Type -> Bool
-- | 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 (Set (Identifier, HWType)) (StateT NetlistState (FreshMT IO)) a -> NetlistMonad a
[runNetlist] :: NetlistMonad a -> WriterT (Set (Identifier, HWType)) (StateT NetlistState (FreshMT IO)) a
-- | State of the NetlistMonad
data NetlistState
NetlistState :: HashMap TmName (Type, Term) -> Gamma -> !Int -> !Int -> HashMap TmName Component -> PrimMap -> (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> HashMap TyConName TyCon -> !String -> !Identifier -> [(String, FilePath)] -> 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 -> PrimMap
-- | Hardcoded Type -> HWType translator
[_typeTranslator] :: NetlistState -> HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)
-- | TyCon cache
[_tcCache] :: NetlistState -> HashMap TyConName TyCon
-- | Name of the module containing the topEntity
[_modNm] :: NetlistState -> !String
[_curCompNm] :: NetlistState -> !Identifier
[_dataFiles] :: NetlistState -> [(String, FilePath)]
-- | 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 ports
[outputs] :: 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
-- | Boolean type
Bool :: HWType
-- | Integer type
Integer :: HWType
-- | BitVector of a specified size
BitVector :: !Size -> HWType
-- | Unsigned integer with specified (exclusive) upper bounder
Index :: !Size -> 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 name and period
Clock :: !Identifier -> !Int -> HWType
-- | Reset type corresponding to clock with a specified name and period
Reset :: !Identifier -> !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
-- - Type of the result/alternatives
-- - Scrutinized expression
-- - List of: (Maybe expression scrutinized expression is compared
-- with,RHS of alternative)
--
CondAssignment :: !Identifier -> !HWType -> !Expr -> [(Maybe Expr, Expr)] -> Declaration
-- | Instantiation of another component
InstDecl :: !Identifier -> !Identifier -> [(Identifier, Expr)] -> Declaration
-- | Instantiation of blackbox declaration
BlackBoxD :: !Text -> !BlackBoxTemplate -> BlackBoxContext -> Declaration
-- | Signal declaration
NetDecl :: !Identifier -> !HWType -> 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 (HWType, Size)) -> !Literal -> Expr
-- | DataCon application
DataCon :: !HWType -> !Modifier -> [Expr] -> Expr
-- | Signal reference
Identifier :: !Identifier -> !(Maybe Modifier) -> Expr
-- | Left e: tagToEnum
DataTag :: !HWType -> !(Either Identifier Identifier) -> Expr
-- | Instantiation of a BlackBox expression
BlackBoxE :: !Text -> !BlackBoxTemplate -> !BlackBoxContext -> !Bool -> Expr
-- | Literals used in an expression
data Literal
-- | Number literal
NumLit :: !Integer -> Literal
-- | Bit literal
BitLit :: !Bit -> Literal
-- | Boolean literal
BoolLit :: !Bool -> Literal
-- | Vector literal
VecLit :: [Literal] -> Literal
-- | String literal
StringLit :: !String -> Literal
-- | Bit literal
data Bit
-- | High
H :: Bit
-- | Low
L :: Bit
-- | Undefined
U :: Bit
-- | High-impedance
Z :: Bit
-- | Context used to fill in the holes of a BlackBox template
data BlackBoxContext
Context :: (SyncExpr, HWType) -> [(SyncExpr, HWType, Bool)] -> IntMap (Either BlackBoxTemplate Declaration, BlackBoxContext) -> BlackBoxContext
-- | Result name and type
[bbResult] :: BlackBoxContext -> (SyncExpr, HWType)
-- | Argument names, types, and whether it is a literal
[bbInputs] :: BlackBoxContext -> [(SyncExpr, HWType, Bool)]
-- | Function arguments (subset of inputs):
--
--
-- - (Blackbox Template,Partial Blackbox Concext)
--
[bbFunctions] :: BlackBoxContext -> IntMap (Either BlackBoxTemplate Declaration, BlackBoxContext)
emptyBBContext :: BlackBoxContext
-- | Either the name of the identifier, or a tuple of the identifier and
-- the corresponding clock
type SyncIdentifier = Either Identifier (Identifier, (Identifier, Int))
type SyncExpr = Either Expr (Expr, (Identifier, Int))
varEnv :: Lens' NetlistState Gamma
varCount :: Lens' NetlistState Int
typeTranslator :: Lens' NetlistState (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType))
tcCache :: Lens' NetlistState (HashMap TyConName TyCon)
primitives :: Lens' NetlistState PrimMap
modNm :: Lens' NetlistState String
dataFiles :: Lens' NetlistState [(String, FilePath)]
curCompNm :: Lens' NetlistState Identifier
components :: Lens' NetlistState (HashMap TmName Component)
cmpCount :: Lens' NetlistState Int
bindings :: Lens' NetlistState (HashMap TmName (Type, Term))
instance GHC.Generics.Constructor CLaSH.Netlist.Types.C1_12HWType
instance GHC.Generics.Constructor CLaSH.Netlist.Types.C1_11HWType
instance GHC.Generics.Constructor CLaSH.Netlist.Types.C1_10HWType
instance GHC.Generics.Constructor CLaSH.Netlist.Types.C1_9HWType
instance GHC.Generics.Constructor CLaSH.Netlist.Types.C1_8HWType
instance GHC.Generics.Constructor CLaSH.Netlist.Types.C1_7HWType
instance GHC.Generics.Constructor CLaSH.Netlist.Types.C1_6HWType
instance GHC.Generics.Constructor CLaSH.Netlist.Types.C1_5HWType
instance GHC.Generics.Constructor CLaSH.Netlist.Types.C1_4HWType
instance GHC.Generics.Constructor CLaSH.Netlist.Types.C1_3HWType
instance GHC.Generics.Constructor CLaSH.Netlist.Types.C1_2HWType
instance GHC.Generics.Constructor CLaSH.Netlist.Types.C1_1HWType
instance GHC.Generics.Constructor CLaSH.Netlist.Types.C1_0HWType
instance GHC.Generics.Datatype CLaSH.Netlist.Types.D1HWType
instance Control.Monad.IO.Class.MonadIO CLaSH.Netlist.Types.NetlistMonad
instance Unbound.Generics.LocallyNameless.Fresh.Fresh CLaSH.Netlist.Types.NetlistMonad
instance Control.Monad.State.Class.MonadState CLaSH.Netlist.Types.NetlistState CLaSH.Netlist.Types.NetlistMonad
instance Control.Monad.Writer.Class.MonadWriter (Data.Set.Base.Set (CLaSH.Netlist.Types.Identifier, CLaSH.Netlist.Types.HWType)) CLaSH.Netlist.Types.NetlistMonad
instance GHC.Base.Applicative CLaSH.Netlist.Types.NetlistMonad
instance GHC.Base.Monad CLaSH.Netlist.Types.NetlistMonad
instance GHC.Base.Functor CLaSH.Netlist.Types.NetlistMonad
instance GHC.Show.Show CLaSH.Netlist.Types.Component
instance GHC.Show.Show CLaSH.Netlist.Types.Declaration
instance GHC.Show.Show CLaSH.Netlist.Types.BlackBoxContext
instance GHC.Show.Show CLaSH.Netlist.Types.Expr
instance GHC.Show.Show CLaSH.Netlist.Types.Literal
instance GHC.Show.Show CLaSH.Netlist.Types.Bit
instance GHC.Show.Show CLaSH.Netlist.Types.Modifier
instance GHC.Generics.Generic CLaSH.Netlist.Types.HWType
instance GHC.Show.Show CLaSH.Netlist.Types.HWType
instance GHC.Classes.Ord CLaSH.Netlist.Types.HWType
instance GHC.Classes.Eq CLaSH.Netlist.Types.HWType
instance Control.DeepSeq.NFData CLaSH.Netlist.Types.Component
instance Data.Hashable.Class.Hashable CLaSH.Netlist.Types.HWType
instance Control.DeepSeq.NFData CLaSH.Netlist.Types.HWType
instance Control.DeepSeq.NFData CLaSH.Netlist.Types.Declaration
-- | 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 extra
RewriteState :: {-# UNPACK #-} !Int -> !(HashMap TmName (Type, Term)) -> !Supply -> TmName -> {-# UNPACK #-} !Int -> !extra -> RewriteState extra
-- | Number of applied transformations
[_transformCounter] :: RewriteState extra -> {-# UNPACK #-} !Int
-- | Global binders
[_bindings] :: RewriteState extra -> !(HashMap TmName (Type, Term))
-- | Supply of unique numbers
[_uniqSupply] :: RewriteState extra -> !Supply
-- | Function which is currently normalized
[_curFun] :: RewriteState extra -> TmName
-- | Used for Fresh
[_nameCounter] :: RewriteState extra -> {-# UNPACK #-} !Int
-- | Additional state
[_extra] :: RewriteState extra -> !extra
uniqSupply :: Lens' (RewriteState extra_a3xGu) Supply
transformCounter :: Lens' (RewriteState extra_a3xGu) Int
nameCounter :: Lens' (RewriteState extra_a3xGu) Int
extra :: Lens (RewriteState extra_a3xGu) (RewriteState extra_a3xJR) extra_a3xGu extra_a3xJR
curFun :: Lens' (RewriteState extra_a3xGu) TmName
bindings :: Lens' (RewriteState extra_a3xGu) (HashMap TmName (Type, Term))
-- | Debug Message Verbosity
data DebugLevel
-- | Don't show debug messages
DebugNone :: DebugLevel
-- | Show completely normalized expressions
DebugFinal :: DebugLevel
-- | Names of applied transformations
DebugName :: 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
data RewriteEnv
RewriteEnv :: DebugLevel -> (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> HashMap TyConName TyCon -> (HashMap TyConName TyCon -> Bool -> Term -> Term) -> RewriteEnv
-- | Lvl at which we print debugging messages
[_dbgLevel] :: RewriteEnv -> DebugLevel
-- | Hardcode Type -> HWType translator
[_typeTranslator] :: RewriteEnv -> HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)
-- | TyCon cache
[_tcCache] :: RewriteEnv -> HashMap TyConName TyCon
-- | Hardcoded evaluator (delta-reduction)}
[_evaluator] :: RewriteEnv -> HashMap TyConName TyCon -> Bool -> Term -> Term
typeTranslator :: Lens' RewriteEnv (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType))
tcCache :: Lens' RewriteEnv (HashMap TyConName TyCon)
evaluator :: Lens' RewriteEnv (HashMap TyConName TyCon -> Bool -> Term -> Term)
dbgLevel :: Lens' RewriteEnv DebugLevel
-- | Monad that keeps track how many transformations have been applied and
-- can generate fresh variables and unique identifiers. In addition, it
-- keeps track if a transformation/rewrite has been successfully applied.
newtype RewriteMonad extra a
R :: (RewriteEnv -> RewriteState extra -> (a, RewriteState extra, Any)) -> RewriteMonad extra a
[runR] :: RewriteMonad extra a -> RewriteEnv -> RewriteState extra -> (a, RewriteState extra, Any)
-- | 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 extra = Transform (RewriteMonad extra)
instance GHC.Base.Functor (CLaSH.Rewrite.Types.RewriteMonad extra)
instance GHC.Base.Applicative (CLaSH.Rewrite.Types.RewriteMonad extra)
instance GHC.Base.Monad (CLaSH.Rewrite.Types.RewriteMonad extra)
instance Control.Monad.State.Class.MonadState (CLaSH.Rewrite.Types.RewriteState extra) (CLaSH.Rewrite.Types.RewriteMonad extra)
instance Unbound.Generics.LocallyNameless.Fresh.Fresh (CLaSH.Rewrite.Types.RewriteMonad extra)
instance CLaSH.Util.MonadUnique (CLaSH.Rewrite.Types.RewriteMonad extra)
instance Control.Monad.Writer.Class.MonadWriter Data.Monoid.Any (CLaSH.Rewrite.Types.RewriteMonad extra)
instance Control.Monad.Reader.Class.MonadReader CLaSH.Rewrite.Types.RewriteEnv (CLaSH.Rewrite.Types.RewriteMonad extra)
instance GHC.Read.Read CLaSH.Rewrite.Types.DebugLevel
instance GHC.Classes.Ord CLaSH.Rewrite.Types.DebugLevel
instance GHC.Classes.Eq CLaSH.Rewrite.Types.DebugLevel
instance GHC.Show.Show CLaSH.Rewrite.Types.CoreContext
instance GHC.Classes.Eq CLaSH.Rewrite.Types.CoreContext
-- | Type definitions used by the Driver module
module CLaSH.Driver.Types
-- | Global function binders
type BindingMap = HashMap TmName (Type, Term)
data CLaSHOpts
CLaSHOpts :: Int -> Int -> Int -> DebugLevel -> CLaSHOpts
[opt_inlineLimit] :: CLaSHOpts -> Int
[opt_specLimit] :: CLaSHOpts -> Int
[opt_inlineBelow] :: CLaSHOpts -> Int
[opt_dbgLevel] :: CLaSHOpts -> DebugLevel
-- | Types used in Normalize modules
module CLaSH.Normalize.Types
-- | State of the NormalizeMonad
data NormalizeState
NormalizeState :: HashMap TmName (Type, Term) -> Map (TmName, Int, Either Term Type) (TmName, Type) -> HashMap TmName Int -> !Int -> HashMap TmName (HashMap TmName Int) -> !Int -> !Int -> NormalizeState
-- | Global binders
[_normalized] :: NormalizeState -> HashMap TmName (Type, 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)
--
[_specialisationCache] :: NormalizeState -> Map (TmName, Int, Either Term Type) (TmName, Type)
-- | Cache of how many times a function was specialized
[_specialisationHistory] :: NormalizeState -> HashMap TmName Int
-- | Number of time a function f can be specialized
[_specialisationLimit] :: NormalizeState -> !Int
-- | Cache of function where inlining took place:
--
--
-- - Key: function where inlining took place
-- - Elem: (functions which were inlined, number of times inlined)
--
[_inlineHistory] :: NormalizeState -> HashMap TmName (HashMap TmName Int)
-- | Number of times a function f can be inlined in a function
-- g
[_inlineLimit] :: NormalizeState -> !Int
-- | Size of a function below which it is always inlined if it is not
-- recursive
[_inlineBelow] :: NormalizeState -> !Int
specialisationLimit :: Lens' NormalizeState Int
specialisationHistory :: Lens' NormalizeState (HashMap TmName Int)
specialisationCache :: Lens' NormalizeState (Map (TmName, Int, Either Term Type) (TmName, Type))
normalized :: Lens' NormalizeState (HashMap TmName (Type, Term))
inlineLimit :: Lens' NormalizeState Int
inlineHistory :: Lens' NormalizeState (HashMap TmName (HashMap TmName Int))
inlineBelow :: Lens' NormalizeState Int
-- | State monad that stores specialisation and inlining information
type NormalizeMonad = State NormalizeState
-- | RewriteSession with extra Normalisation information
type NormalizeSession = RewriteMonad NormalizeState
-- | A Transform action in the context of the RewriteMonad
-- and NormalizeMonad
type NormRewrite = Rewrite NormalizeState
-- | 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 two transformations in succession, and perform a deepseq in
-- between.
(>-!->) :: (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
-- | Only apply the second transformation if the first one succeeds.
(!->) :: Rewrite m -> Rewrite m -> Rewrite m
-- | Only apply the second transformation if the first one fails.
(>-!) :: Rewrite m -> Rewrite m -> Rewrite m
-- | Keep applying a transformation until it fails.
repeatR :: Rewrite m -> Rewrite m
whenR :: Monad m => ([CoreContext] -> Term -> m Bool) -> Transform m -> Transform m
-- | Only traverse downwards when the assertion evaluates to true
bottomupWhenR :: (Monad m, Fresh m, Functor m) => ([CoreContext] -> Term -> m Bool) -> Transform m -> Transform 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) => HashMap TyConName TyCon -> 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 :: String -> (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> HashMap TyConName TyCon -> Type -> HWType
-- | Converts a Core type to a HWType within the NetlistMonad; errors on
-- failure
unsafeCoreTypeToHWTypeM :: String -> Type -> NetlistMonad HWType
-- | Converts a Core type to a HWType within the NetlistMonad;
-- Nothing on failure
coreTypeToHWTypeM :: Type -> NetlistMonad (Maybe HWType)
-- | Returns the name and period of the clock corresponding to a type
synchronizedClk :: HashMap TyConName TyCon -> Type -> Maybe (Identifier, Int)
-- | 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 :: (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> HashMap TyConName TyCon -> Type -> Either String HWType
-- | Converts an algebraic Core type (split into a TyCon and its argument)
-- to a HWType.
mkADT :: (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> HashMap TyConName TyCon -> String -> TyConName -> [Type] -> Either String HWType
-- | Simple check if a TyCon is recursively defined.
isRecursiveTy :: HashMap TyConName TyCon -> TyConName -> Bool
-- | Determines if a Core type is translatable to a HWType given a function
-- that translates certain builtin types.
representableType :: (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> HashMap TyConName TyCon -> 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 :: String -> Term -> NetlistMonad HWType
-- | Gives the HWType corresponding to a term. Returns Nothing if
-- the term has a Core type that is not translatable to a HWType.
termHWTypeM :: Term -> NetlistMonad (Maybe 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
dcToLiteral :: HWType -> Int -> Expr
-- | Utilities for rewriting: e.g. inlining, specialisation, etc.
module CLaSH.Rewrite.Util
-- | Lift an action working in the _extra state to the
-- RewriteMonad
zoomExtra :: State extra a -> RewriteMonad extra a
-- | Record if a transformation is succesfully applied
apply :: String -> Rewrite extra -> Rewrite extra
-- | Perform a transformation on a Term
runRewrite :: String -> Rewrite extra -> Term -> RewriteMonad extra Term
-- | Evaluate a RewriteSession to its inner monad
runRewriteSession :: RewriteEnv -> RewriteState extra -> RewriteMonad extra a -> a
-- | Notify that a transformation has changed the expression
setChanged :: RewriteMonad extra ()
-- | Identity function that additionally notifies that a transformation has
-- changed the expression
changed :: a -> RewriteMonad extra 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 :: [CoreContext] -> RewriteMonad extra (Gamma, Delta)
-- | Make a new binder and variable reference for a term
mkTmBinderFor :: (Functor m, Fresh m, MonadUnique m) => HashMap TyConName TyCon -> 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) => HashMap TyConName TyCon -> 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 :: (Term -> LetBinding -> RewriteMonad extra Bool) -> Rewrite extra
-- | Determine whether a binder is a join-point created for a complex case
-- expression.
--
-- A join-point is when a local function only occurs in tail-call
-- positions, and when it does, more than once.
isJoinPointIn :: Id -> Term -> Bool
-- | Count the number of (only) tail calls of a function in an expression.
-- Nothing indicates that the function was used in a non-tail call
-- position.
tailCalls :: Id -> Term -> Maybe Int
-- | 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.
localFreeIds :: (Applicative f, Contravariant f) => RewriteMonad extra ((TmName -> f TmName) -> Term -> f Term)
-- | Lift the binders in a let-binding to a global function that have a
-- certain property
liftBinders :: (Term -> LetBinding -> RewriteMonad extra Bool) -> Rewrite extra
-- | 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 :: Gamma -> Delta -> LetBinding -> RewriteMonad extra LetBinding
-- | Make a global function for a name-term tuple
mkFunction :: TmName -> Term -> RewriteMonad extra (TmName, Type)
-- | Add a function to the set of global binders
addGlobalBind :: TmName -> Type -> Term -> RewriteMonad extra ()
-- | Create a new name out of the given name, but with another unique
cloneVar :: TmName -> RewriteMonad extra TmName
-- | Test whether a term is a variable reference to a local binder
isLocalVar :: Term -> RewriteMonad extra Bool
-- | Determine if a term cannot be represented in hardware
isUntranslatable :: Term -> RewriteMonad extra Bool
-- | Determine if a type cannot be represented in hardware
isUntranslatableType :: Type -> RewriteMonad extra 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 -> HashMap TyConName TyCon -> [CoreContext] -> Term -> Int -> Int -> m Term
-- | Specialise an application on its argument
specialise :: Lens' extra (Map (TmName, Int, Either Term Type) (TmName, Type)) -> Lens' extra (HashMap TmName Int) -> Lens' extra Int -> Rewrite extra
-- | Specialise an application on its argument
specialise' :: Lens' extra (Map (TmName, Int, Either Term Type) (TmName, Type)) -> Lens' extra (HashMap TmName Int) -> Lens' extra Int -> [CoreContext] -> Term -> (Term, [Either Term Type]) -> Either Term Type -> RewriteMonad extra Term
-- | Create binders and variable references for free variables in
-- specArg
specArgBndrsAndVars :: [CoreContext] -> Either Term Type -> RewriteMonad extra ([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 -> TmName -> NormalizeMonad (Maybe Int)
addNewInline :: TmName -> TmName -> NormalizeMonad ()
-- | Specialize under the Normalization Monad
specializeNorm :: NormRewrite
-- | Determine if a term is closed
isClosed :: (Functor m, Fresh m) => HashMap TyConName TyCon -> Term -> m Bool
-- | Determine if a term represents a constant
isConstant :: Term -> Bool
-- | Create a call graph for a set of global binders, given a root
callGraph :: [TmName] -> HashMap TmName (Type, Term) -> TmName -> [(TmName, [TmName])]
-- | Determine the sets of recursive components given the edges of a
-- callgraph
recursiveComponents :: [(TmName, [TmName])] -> [[TmName]]
lambdaDropPrep :: HashMap TmName (Type, Term) -> TmName -> HashMap TmName (Type, Term)
lambdaDrop :: HashMap TmName (Type, Term) -> HashMap TmName [TmName] -> [TmName] -> (TmName, (Type, Term))
dominator :: HashMap TmName [TmName] -> [TmName] -> Gr TmName TmName
blockSink :: HashMap TmName (Type, Term) -> Gr TmName TmName -> LNode TmName -> (TmName, (Type, Term))
-- | 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, non-join-point, let-bindings
bindNonRep :: NormRewrite
-- | Lift 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
-- | 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
-- | 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
-- | Inline nullary/closed functions
inlineClosed :: NormRewrite
-- | Inline a function with functional arguments
inlineHO :: NormRewrite
-- | Inline small functions
inlineSmall :: NormRewrite
-- | Simplified CSE, only works on let-bindings, works from top to bottom
simpleCSE :: NormRewrite
reduceConst :: NormRewrite
-- | Replace primitives by their "definition" if they would lead to
-- let-bindings with a non-representable type when a function is in ANF.
-- This happens for example when CLaSH.Size.Vector.map consumes or
-- produces a vector of non-representable elements.
--
-- Basically what this transformation does is replace a primitive the
-- completely unrolled recursive definition that it represents. e.g.
--
--
-- zipWith ($) (xs :: Vec 2 (Int -> Int)) (ys :: Vec 2 Int)
--
--
-- is replaced by:
--
--
-- let (x0 :: (Int -> Int)) = case xs of (:>) _ x xr -> x
-- (xr0 :: Vec 1 (Int -> Int)) = case xs of (:>) _ x xr -> xr
-- (x1 :: (Int -> Int)( = case xr0 of (:>) _ x xr -> x
-- (y0 :: Int) = case ys of (:>) _ y yr -> y
-- (yr0 :: Vec 1 Int) = case ys of (:>) _ y yr -> xr
-- (y1 :: Int = case yr0 of (:>) _ y yr -> y
-- in (($) x0 y0 :> ($) x1 y1 :> Nil)
--
--
-- Currently, it only handles the following functions:
--
--
-- - CLaSH.Sized.Vector.map
-- - CLaSH.Sized.Vector.zipWith
-- - CLaSH.Sized.Vector.traverse#
--
reduceNonRepPrim :: NormRewrite
-- | Transformation process for normalization
module CLaSH.Normalize.Strategy
-- | Normalisation transformation
normalization :: NormRewrite
constantPropgation :: NormRewrite
-- | Topdown traversal, stops upon first success
topdownSucR :: Rewrite extra -> Rewrite extra
innerMost :: Rewrite extra -> Rewrite extra
applyMany :: [(String, Rewrite extra)] -> Rewrite extra
-- | Turn CoreHW terms into normalized CoreHW Terms
module CLaSH.Normalize
-- | Run a NormalizeSession in a given environment
runNormalization :: CLaSHOpts -> Supply -> HashMap TmName (Type, Term) -> (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> HashMap TyConName TyCon -> (HashMap TyConName TyCon -> Bool -> Term -> Term) -> NormalizeSession a -> a
normalize :: [TmName] -> NormalizeSession (HashMap TmName (Type, Term))
normalize' :: TmName -> NormalizeSession ([TmName], (TmName, (Type, Term)))
-- | Rewrite a term according to the provided transformation
rewriteExpr :: (String, NormRewrite) -> (String, Term) -> NormalizeSession 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 -> HashMap TmName (Type, Term) -> HashMap TmName (Type, Term)
-- | Perform general "clean up" of the normalized (non-recursive) function
-- hierarchy. This includes:
--
--
-- - Inlining functions that simply "wrap" another function
--
cleanupGraph :: TmName -> (HashMap TmName (Type, Term)) -> NormalizeSession (HashMap TmName (Type, Term))
data CallTree
CLeaf :: (TmName, (Type, Term)) -> CallTree
CBranch :: (TmName, (Type, Term)) -> [CallTree] -> CallTree
mkCallTree :: [TmName] -> HashMap TmName (Type, Term) -> TmName -> CallTree
stripArgs :: [TmName] -> [Id] -> [Either Term Type] -> Maybe [Either Term Type]
flattenNode :: CallTree -> NormalizeSession (Either CallTree ((TmName, Term), [CallTree]))
flattenCallTree :: CallTree -> NormalizeSession CallTree
callTreeToList :: [TmName] -> CallTree -> ([TmName], [(TmName, (Type, Term))])
module CLaSH.Backend
class Backend state
-- | Initial state for state monad
initBackend :: Backend state => state
-- | Location for the primitive definitions
primDir :: Backend state => state -> IO FilePath
-- | Name of backend, used for directory to put output files in. Should be
-- | constant function / ignore argument.
name :: Backend state => state -> String
-- | File extension for target langauge
extension :: Backend state => state -> String
-- | Get the set of types out of state
extractTypes :: Backend state => state -> HashSet HWType
-- | Generate HDL for a Netlist component
genHDL :: Backend state => String -> Component -> State state (String, Doc)
-- | Generate a HDL package containing type definitions for the given
-- HWTypes
mkTyPackage :: Backend state => String -> [HWType] -> State state [(String, Doc)]
-- | Convert a Netlist HWType to a target HDL type
hdlType :: Backend state => HWType -> State state Doc
-- | Convert a Netlist HWType to an HDL error value for that type
hdlTypeErrValue :: Backend state => HWType -> State state Doc
-- | Convert a Netlist HWType to the root of a target HDL type
hdlTypeMark :: Backend state => HWType -> State state Doc
-- | Create a signal declaration from an identifier (Text) and Netlist
-- HWType
hdlSig :: Backend state => Text -> HWType -> State state Doc
-- | Create a generative block statement marker
genStmt :: Backend state => Bool -> State state Doc
-- | Turn a Netlist Declaration to a HDL concurrent block
inst :: Backend state => Declaration -> State state (Maybe Doc)
-- | Turn a Netlist expression into a HDL expression
expr :: Backend state => Bool -> Expr -> State state 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 :: BlackBoxContext -> BlackBoxTemplate -> Bool
extractLiterals :: BlackBoxContext -> [Expr]
-- | Update all the symbol references in a template, and increment the
-- symbol counter for every newly encountered symbol.
setSym :: Int -> BlackBoxTemplate -> (BlackBoxTemplate, Int)
setCompName :: Identifier -> BlackBoxTemplate -> BlackBoxTemplate
setClocks :: (MonadWriter (Set (Identifier, HWType)) m, Applicative m) => BlackBoxContext -> BlackBoxTemplate -> m BlackBoxTemplate
findAndSetDataFiles :: BlackBoxContext -> [(String, FilePath)] -> BlackBoxTemplate -> ([(String, FilePath)], BlackBoxTemplate)
renderFilePath :: [(String, FilePath)] -> String -> ([(String, FilePath)], Element)
-- | Get the name of the clock of an identifier
clkSyncId :: SyncExpr -> (Identifier, Int)
-- | 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 :: Backend backend => BlackBoxTemplate -> BlackBoxContext -> State backend Text
-- | Render a single template element
renderElem :: Backend backend => BlackBoxContext -> Element -> State backend Text
parseFail :: Text -> BlackBoxTemplate
syncIdToSyncExpr :: (Text, HWType) -> (SyncExpr, HWType, Bool)
-- | 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 :: Backend backend => BlackBoxContext -> BlackBoxTemplate -> State backend Text
lineToType :: BlackBoxContext -> BlackBoxTemplate -> HWType
-- | Give a context and a tagged hole (of a template), returns part of the
-- context that matches the tag of the hole.
renderTag :: Backend backend => BlackBoxContext -> Element -> State backend Text
-- | 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])
prepareBlackBox :: Text -> Text -> BlackBoxContext -> NetlistMonad BlackBoxTemplate
mkArgument :: Term -> NetlistMonad ((SyncExpr, HWType, Bool), [Declaration])
mkPrimitive :: Bool -> Bool -> Text -> [Either Term Type] -> Type -> NetlistMonad (Expr, [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 -> NetlistMonad ((Either BlackBoxTemplate Declaration, BlackBoxContext), [Declaration])
-- | Instantiate symbols references with a new symbol and increment symbol
-- counter
instantiateSym :: BlackBoxTemplate -> NetlistMonad BlackBoxTemplate
instantiateCompName :: BlackBoxTemplate -> NetlistMonad BlackBoxTemplate
collectFilePaths :: BlackBoxContext -> 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 Int -> HashMap TmName (Type, Term) -> PrimMap -> HashMap TyConName TyCon -> (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> Maybe Int -> String -> [(String, FilePath)] -> TmName -> IO ([Component], [(String, FilePath)], Int)
-- | Run a NetlistMonad action in a given environment
runNetlistMonad :: Maybe Int -> HashMap TmName (Type, Term) -> PrimMap -> HashMap TyConName TyCon -> (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> String -> [(String, FilePath)] -> 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]
toSimpleVar :: (Expr, Type) -> NetlistMonad (Expr, [Declaration])
-- | Generate an expression for a term occurring on the RHS of a let-binder
mkExpr :: Bool -> 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])
-- | Generate a HDL testbench for a component given a set of stimuli and a
-- set of matching expected outputs
module CLaSH.Driver.TestbenchGen
-- | Generate a HDL testbench for a component given a set of stimuli and a
-- set of matching expected outputs
genTestBench :: CLaSHOpts -> Supply -> PrimMap -> (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> HashMap TyConName TyCon -> (HashMap TyConName TyCon -> Bool -> Term -> Term) -> Int -> HashMap TmName (Type, Term) -> Maybe TmName -> Maybe TmName -> String -> [(String, FilePath)] -> Component -> IO ([Component], [(String, FilePath)])
module CLaSH.Driver.TopWrapper
-- | Create a wrapper around a component, potentially initiating clock
-- sources
mkTopWrapper :: PrimMap -> Maybe TopEntity -> String -> Component -> Component
-- | Create extra input ports for the wrapper
extraIn :: Maybe TopEntity -> [(Identifier, HWType)]
-- | Create extra output ports for the wrapper
extraOut :: Maybe TopEntity -> [(Identifier, HWType)]
-- | Generate input port mappings
mkInput :: [Identifier] -> (Identifier, HWType) -> Int -> ([Identifier], ([(Identifier, HWType)], ([Declaration], Identifier)))
-- | Create a Vector chain for a list of Identifiers
mkVectorChain :: Int -> HWType -> [Identifier] -> Expr
-- | Generate output port mappings
mkOutput :: [Identifier] -> (Identifier, HWType) -> Int -> ([Identifier], ([(Identifier, HWType)], ([Declaration], Identifier)))
-- | Create clock generators
mkClocks :: PrimMap -> [(Identifier, HWType)] -> Maybe TopEntity -> [Declaration]
stringToVar :: String -> Expr
-- | Create a single clock generator
mkClock :: ClockSource -> ([Declaration], (Identifier, [String], Bool))
mkClockDecl :: String -> Declaration
-- | Create a single clock path
clockPorts :: Maybe (String, String) -> [(String, String)] -> ([(Identifier, Expr)], [String])
-- | Generate resets
mkResets :: PrimMap -> [(Identifier, HWType)] -> [(Identifier, [String], Bool)] -> [Declaration]
-- | Generate a reset synchroniser that synchronously de-asserts an
-- asynchronous reset signal
genSyncReset :: PrimMap -> Identifier -> Identifier -> Text -> Int -> NetlistMonad [Declaration]
-- | The NetListMonad is an transformer stack with IO at
-- the bottom. So we must use unsafePerformIO.
unsafeRunNetlist :: NetlistMonad a -> a
-- | Module that connects all the parts of the CLaSH compiler library
module CLaSH.Driver
-- | Create a set of target HDL files for a set of functions
generateHDL :: Backend backend => BindingMap -> Maybe backend -> PrimMap -> HashMap TyConName TyCon -> (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> (HashMap TyConName TyCon -> Bool -> Term -> Term) -> Maybe TopEntity -> CLaSHOpts -> IO ()
-- | Pretty print Components to HDL Documents
createHDL :: Backend backend => backend -> String -> [Component] -> [(String, Doc)]
-- | Prepares the directory for writing HDL files. This means creating the
-- dir if it does not exist and removing all existing .hdl files from it.
prepareDir :: String -> IO ()
-- | Writes a HDL file to the given directory
writeHDL :: Backend backend => backend -> FilePath -> (String, Doc) -> IO ()
copyDataFiles :: FilePath -> [(String, FilePath)] -> IO ()