-- 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: -- --
-- 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) -- | Type and instance definitions for Primitive module CLaSH.Primitives.Types -- | Primitive Definitions type PrimMap a = HashMap Text (Primitive a) -- | Externally defined primitive data Primitive a -- | A primitive that has a template that can be filled out by the backend -- render BlackBox :: !Text -> [Text] -> [Text] -> Maybe (Text, a) -> !(Either a a) -> Primitive a -- | Name of the primitive [name] :: Primitive a -> !Text [library] :: Primitive a -> [Text] [imports] :: Primitive a -> [Text] [qsysInclude] :: Primitive a -> Maybe (Text, a) -- | Either a declaration or an expression template. [template] :: Primitive a -> !(Either a a) -- | A primitive that carries additional information Primitive :: !Text -> !Text -> Primitive a -- | Name of the primitive [name] :: Primitive a -> !Text -- | Additional information [primType] :: Primitive a -> !Text instance GHC.Show.Show a => GHC.Show.Show (CLaSH.Primitives.Types.Primitive a) instance Data.Aeson.Types.FromJSON.FromJSON (CLaSH.Primitives.Types.Primitive Data.Text.Internal.Lazy.Text) -- | 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 Text) -- | Transform/format a Netlist Identifier so that it is acceptable as a -- HDL identifier module CLaSH.Netlist.Id 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 :: !Text -> !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 QSysIncludeName :: Element -- | Index data type hole, the field is the (exclusive) maximum index IndexType :: !Element -> Element -- | Size of a type hole Size :: !Element -> Element -- | Length of a vector hole Length :: !Element -> Element -- | Depth of a tree hole Depth :: !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 IF :: !Element -> [Element] -> [Element] -> Element And :: [Element] -> Element -- | Hole indicating whether IntWordInteger are 64-Bit IW64 :: Element -- | Hole indicating which synthesis tool we're generating HDL for HdlSyn :: HdlSyn -> Element -- | Convert to (True)/from(False) a bit-vector BV :: !Bool -> [Element] -> !Element -> Element IsLit :: !Int -> Element IsVar :: !Int -> Element Vars :: !Int -> Element GenSym :: [Element] -> !Int -> 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 data HdlSyn Vivado :: HdlSyn Other :: HdlSyn instance GHC.Show.Show CLaSH.Netlist.BlackBox.Types.Decl instance GHC.Show.Show CLaSH.Netlist.BlackBox.Types.Element instance GHC.Read.Read CLaSH.Netlist.BlackBox.Types.HdlSyn instance GHC.Show.Show CLaSH.Netlist.BlackBox.Types.HdlSyn instance GHC.Classes.Eq CLaSH.Netlist.BlackBox.Types.HdlSyn -- | 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]) -- | 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 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 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 Control.DeepSeq.NFData CLaSH.Core.TyCon.TyCon instance GHC.Generics.Generic CLaSH.Core.TyCon.TyCon 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 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 integerPrimTy :: Type charPrimTy :: Type stringPrimTy :: Type voidPrimTy :: Type wordPrimTy :: Type int64PrimTy :: Type word64PrimTy :: Type floatPrimTy :: Type doublePrimTy :: Type tysPrimMap :: HashMap TyConName TyCon -- | Term Literal module CLaSH.Core.Literal -- | Term Literal data Literal IntegerLiteral :: !Integer -> Literal IntLiteral :: !Integer -> Literal WordLiteral :: !Integer -> Literal Int64Literal :: !Integer -> Literal Word64Literal :: !Integer -> Literal StringLiteral :: !String -> Literal FloatLiteral :: !Rational -> Literal DoubleLiteral :: !Rational -> Literal CharLiteral :: !Char -> Literal -- | Determines the Type of a Literal literalType :: Literal -> Type 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 Control.DeepSeq.NFData CLaSH.Core.Term.Term instance GHC.Generics.Generic CLaSH.Core.Term.Term instance GHC.Show.Show CLaSH.Core.Term.Term 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 GHC.Classes.Eq CLaSH.Core.Term.Pat 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 :: !Integer -> 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 newtypes are transparent, the Signal type is -- transparent, and type functions are evaluated to WHNF (when possible). -- -- Only strips away one "layer". coreView :: HashMap TyConName TyCon -> Type -> Maybe 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 poly-function type in a: list of type-binders and argument -- types, and the result type. Looks through Signal and type -- functions. splitCoreFunForallTy :: HashMap TyConName TyCon -> 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 :: HashMap TyConName TyCon -> [([Type], Type)] -> [Type] -> Maybe Type reduceTypeFamily :: HashMap TyConName TyCon -> Type -> Maybe Type -- | The type of GHC.Err.undefined :: forall a . a undefinedTy :: Type 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, LFresh m) => p -> m Doc pprPrec :: (Pretty p, 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 :: 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 :: Fresh m => HashMap TyConName TyCon -> Term -> m Bool -- | Does a term have a function or polymorphic type? isPolyFun :: 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 -> Integer -> [Term] -> Term -- | Append elements to the supplied vector appendToVec :: DataCon -> Type -> Term -> Integer -> [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 -> Integer -> Term -> [(Term, [LetBinding])] -- | Create let-bindings with case-statements that select elements out of a -- tree. Returns both the variables to which element-selections are bound -- and the let-bindings extractTElems :: DataCon -> DataCon -> Type -> Char -> Integer -> Term -> ([Term], [LetBinding]) -- | Create a vector of supplied elements mkRTree :: DataCon -> DataCon -> Type -> Integer -> [Term] -> Term -- | Determine whether a type is isomorphic to -- CLaSH.Signal.Internal.Signal' -- -- It is i.e.: -- --
-- \(w :: Void) -> f a b c ---- -- i.e. is a wrapper around a (partially) applied function f, -- where the introduced argument w is not used by f isVoidWrapper :: Term -> Bool -- | 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) inlineOrLiftBinders :: (LetBinding -> RewriteMonad extra Bool) -> (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 -> SrcSpan -> Term -> RewriteMonad extra (TmName, Type) -- | Add a function to the set of global binders addGlobalBind :: TmName -> Type -> SrcSpan -> 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 :: (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 -> 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]) -- | Reductions of primitives -- -- Currently, it contains reductions for: -- --
-- (:>) <$> x0 <*> ((:>) <$> x1 <*> pure Nil) --mkTravVec :: TyConName -> DataCon -> DataCon -> Term -> Term -> Term -> Type -> Integer -> [Term] -> Term -- | Replace an application of the CLaSH.Sized.Vector.foldr -- primitive on vectors of a known length n, by the fully -- unrolled recursive "definition" of CLaSH.Sized.Vector.foldr reduceFoldr :: Integer -> Type -> Term -> Term -> Term -> NormalizeSession Term -- | Replace an application of the CLaSH.Sized.Vector.fold -- primitive on vectors of a known length n, by the fully -- unrolled recursive "definition" of CLaSH.Sized.Vector.fold reduceFold :: Integer -> Type -> Term -> Term -> NormalizeSession Term -- | Replace an application of the CLaSH.Sized.Vector.dfold -- primitive on vectors of a known length n, by the fully -- unrolled recursive "definition" of CLaSH.Sized.Vector.dfold reduceDFold :: Integer -> Type -> Term -> Term -> Term -> NormalizeSession Term -- | Replace an application of the CLaSH.Sized.Vector.head -- primitive on vectors of a known length n, by a projection of -- the first element of a vector. reduceHead :: Integer -> Type -> Term -> NormalizeSession Term -- | Replace an application of the CLaSH.Sized.Vector.tail -- primitive on vectors of a known length n, by a projection of -- the tail of a vector. reduceTail :: Integer -> Type -> Term -> NormalizeSession Term -- | Replace an application of the CLaSH.Sized.Vector.last -- primitive on vectors of a known length n, by a projection of -- the last element of a vector. reduceLast :: Integer -> Type -> Term -> NormalizeSession Term -- | Replace an application of the CLaSH.Sized.Vector.init -- primitive on vectors of a known length n, by a projection of -- the init of a vector. reduceInit :: Integer -> Type -> Term -> NormalizeSession Term -- | Replace an application of the CLaSH.Sized.Vector.(++) -- primitive on vectors of a known length n, by the fully -- unrolled recursive "definition" of CLaSH.Sized.Vector.(++) reduceAppend :: Integer -> Integer -> Type -> Term -> Term -> NormalizeSession Term -- | Replace an application of the CLaSH.Sized.Vector.unconcat -- primitive on vectors of a known length n, by the fully -- unrolled recursive "definition" of -- CLaSH.Sized.Vector.unconcat reduceUnconcat :: Integer -> Integer -> Type -> Term -> NormalizeSession Term -- | Replace an application of the CLaSH.Sized.Vector.transpose -- primitive on vectors of a known length n, by the fully -- unrolled recursive "definition" of -- CLaSH.Sized.Vector.transpose reduceTranspose :: Integer -> Integer -> Type -> Term -> NormalizeSession Term reduceReplicate :: Integer -> Type -> Type -> Term -> NormalizeSession Term -- | Replace an application of the CLaSH.Sized.Vector.dtfold -- primitive on vectors of a known length n, by the fully -- unrolled recursive "definition" of CLaSH.Sized.Vector.dtfold reduceDTFold :: Integer -> Type -> Term -> Term -> Term -> NormalizeSession Term -- | Replace an application of the CLaSH.Sized.RTree.tdfold -- primitive on trees of a known depth n, by the fully unrolled -- recursive "definition" of CLaSH.Sized.RTree.tdfold reduceTFold :: Integer -> Type -> Term -> Term -> Term -> NormalizeSession Term reduceTReplicate :: Integer -> Type -> Type -> Term -> NormalizeSession Term -- | 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 :: Fresh m => HashMap TyConName TyCon -> Term -> m Bool -- | Determine if a term represents a constant isConstant :: Term -> Bool isRecursiveBndr :: TmName -> NormalizeSession Bool -- | Create a call graph for a set of global binders, given a root callGraph :: [TmName] -> HashMap TmName (Type, SrcSpan, Term) -> TmName -> [(TmName, [TmName])] -- | Determine the sets of recursive components given the edges of a -- callgraph mkRecursiveComponents :: [(TmName, [TmName])] -> [[TmName]] lambdaDropPrep :: HashMap TmName (Type, SrcSpan, Term) -> TmName -> HashMap TmName (Type, SrcSpan, Term) lambdaDrop :: HashMap TmName (Type, SrcSpan, Term) -> HashMap TmName [TmName] -> [TmName] -> (TmName, (Type, SrcSpan, Term)) dominator :: HashMap TmName [TmName] -> [TmName] -> Gr TmName TmName blockSink :: HashMap TmName (Type, SrcSpan, Term) -> Gr TmName TmName -> LNode TmName -> (TmName, (Type, SrcSpan, Term)) -- | Helper functions for the disjointExpressionConsolidation -- transformation -- -- The disjointExpressionConsolidation transformation lifts -- applications of global binders out of alternatives of case-statements. -- -- e.g. It converts: -- --
-- case x of -- A -> f 3 y -- B -> f x x -- C -> h x ---- -- into: -- --
-- let f_arg0 = case x of {A -> 3; B -> x}
-- f_arg1 = case x of {A -> y; B -> x}
-- f_out = f f_arg0 f_arg1
-- in case x of
-- A -> f_out
-- B -> f_out
-- C -> h x
--
module CLaSH.Normalize.DEC
-- | Collect CaseTrees for (potentially) disjoint applications of
-- globals out of an expression. Also substitute truly disjoint
-- applications of globals by a reference to a lifted out application.
collectGlobals :: Set TmName -> [(Term, Term)] -> [Term] -> Term -> RewriteMonad NormalizeState (Term, [(Term, ([Term], CaseTree [(Either Term Type)]))])
-- | Test if a CaseTree collected from an expression indicates that
-- application of a global binder is disjoint: occur in separate branches
-- of a case-expression.
isDisjoint :: CaseTree ([Either Term Type]) -> Bool
-- | Given a case-tree corresponding to a disjoint interesting "term-in-a-
-- function-position", return a let-expression: where the let-binding
-- holds a case-expression selecting between the uncommon arguments of
-- the case-tree, and the body is an application of the term applied to
-- the common arguments of the case tree, and projections of let-binding
-- corresponding to the uncommon argument positions.
mkDisjointGroup :: Set TmName -> (Term, ([Term], CaseTree [(Either Term Type)])) -> RewriteMonad NormalizeState (Term, [Term])
instance Data.Foldable.Foldable CLaSH.Normalize.DEC.CaseTree
instance GHC.Base.Functor CLaSH.Normalize.DEC.CaseTree
instance GHC.Show.Show a => GHC.Show.Show (CLaSH.Normalize.DEC.CaseTree a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (CLaSH.Normalize.DEC.CaseTree a)
module CLaSH.Backend
type ModName = String
class Backend state
-- | Initial state for state monad
initBackend :: Backend state => Int -> HdlSyn -> 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 -> SrcSpan -> Component -> State state ((String, Doc), [(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
-- | Bit-width of IntWordInteger
iwWidth :: Backend state => State state Int
-- | Convert to a bit-vector
toBV :: Backend state => HWType -> Text -> State state Doc
-- | Convert from a bit-vector
fromBV :: Backend state => HWType -> Text -> State state Doc
-- | Synthesis tool we're generating HDL for
hdlSyn :: Backend state => State state HdlSyn
-- | mkBasicId
mkBasicId :: Backend state => State state (Identifier -> Identifier)
-- | setModName
setModName :: Backend state => ModName -> state -> state
-- | setSrcSpan
setSrcSpan :: Backend state => SrcSpan -> State state ()
-- | getSrcSpan
getSrcSpan :: Backend state => State state SrcSpan
-- | 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 :: BlackBoxTemplate -> NetlistMonad BlackBoxTemplate
setCompName :: Identifier -> BlackBoxTemplate -> BlackBoxTemplate
setClocks :: MonadWriter (Set (Identifier, HWType)) 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, Integer)
-- | 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
prettyBlackBox :: Monad m => BlackBoxTemplate -> m Text
prettyElem :: Monad m => Element -> m Text
usedArguments :: BlackBoxTemplate -> [Int]
-- | 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 -> BlackBoxTemplate -> BlackBoxContext -> NetlistMonad BlackBoxTemplate
mkArgument :: Identifier -> Term -> NetlistMonad ((SyncExpr, HWType, Bool), [Declaration])
mkPrimitive :: Bool -> Bool -> (Either Identifier Id) -> 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 instantiateSym l = do i <- Lens.use varCount ids
-- <- Lens.use seenIds let (l',(ids',i')) = setSym ids i l varCount .=
-- i' seenIds .= ids' return l'
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 :: HashMap TmName (Type, SrcSpan, Term) -> PrimMap BlackBoxTemplate -> HashMap TyConName TyCon -> (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> Maybe Int -> String -> [(String, FilePath)] -> Int -> (Identifier -> Identifier) -> [Identifier] -> TmName -> IO ([(SrcSpan, Component)], [(String, FilePath)], [Identifier])
-- | Run a NetlistMonad action in a given environment
runNetlistMonad :: HashMap TmName (Type, SrcSpan, Term) -> PrimMap BlackBoxTemplate -> HashMap TyConName TyCon -> (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> String -> [(String, FilePath)] -> Int -> (Identifier -> Identifier) -> [Identifier] -> NetlistMonad a -> IO (a, NetlistState)
genNames :: (Identifier -> Identifier) -> String -> [Identifier] -> HashMap TmName Identifier -> [TmName] -> ([Identifier], HashMap TmName Identifier)
-- | Generate a component for a given function (caching)
genComponent :: TmName -> Maybe Int -> NetlistMonad (SrcSpan, Component)
-- | Generate a component for a given function
genComponentT :: TmName -> Term -> Maybe Int -> NetlistMonad (SrcSpan, Component)
genComponentName :: [Identifier] -> (Identifier -> Identifier) -> String -> TmName -> Identifier
-- | 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 :: Id -> (Expr, Type) -> NetlistMonad (Expr, [Declaration])
-- | Generate an expression for a term occurring on the RHS of a let-binder
mkExpr :: Bool -> (Either Identifier Id) -> Type -> Term -> NetlistMonad (Expr, [Declaration])
-- | Generate an expression for a DataCon application occurring on the RHS
-- of a let-binder
mkDcApplication :: HWType -> (Either Identifier Id) -> DataCon -> [Term] -> NetlistMonad (Expr, [Declaration])
module CLaSH.Driver.TopWrapper
-- | Create a wrapper around a component, potentially initiating clock
-- sources
mkTopWrapper :: PrimMap BlackBoxTemplate -> (Identifier -> Identifier) -> Maybe TopEntity -> String -> Int -> 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
-- | Create a RTree chain for a list of Identifiers
mkRTreeChain :: Int -> HWType -> [Identifier] -> Expr
-- | Generate output port mappings
mkOutput :: [Identifier] -> (Identifier, HWType) -> Int -> ([Identifier], ([(Identifier, HWType)], ([Declaration], Identifier)))
-- | Create clock generators
mkClocks :: PrimMap BlackBoxTemplate -> [(Identifier, HWType)] -> Int -> 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 :: [(String, String)] -> [(String, String)] -> ([(Identifier, PortDirection, HWType, Expr)], [String])
-- | Generate resets
mkResets :: PrimMap BlackBoxTemplate -> [(Identifier, HWType)] -> Int -> [(Identifier, [String], Bool)] -> [Declaration]
-- | Generate a reset synchroniser that synchronously de-asserts an
-- asynchronous reset signal
genSyncReset :: PrimMap BlackBoxTemplate -> Identifier -> Identifier -> Text -> Integer -> NetlistMonad [Declaration]
-- | The NetListMonad is a transformer stack with IO at the
-- bottom. So we must use unsafePerformIO.
unsafeRunNetlist :: Int -> NetlistMonad a -> a
-- | 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
-- | 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
inlineOrLiftNonRep :: 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: -- --
-- f :: Unsigned 4 -> Unsigned 4 -- f x = case x of -- 0 -> 3 -- 1 -> 2 -- 2 -> 1 -- 3 -> 0 ---- -- GHC generates Core that looks like: -- --
-- f = (x :: Unsigned 4) -> case x == fromInteger 3 of -- False -> case x == fromInteger 2 of -- False -> case x == fromInteger 1 of -- False -> case x == fromInteger 0 of -- False -> error "incomplete case" -- True -> fromInteger 3 -- True -> fromInteger 2 -- True -> fromInteger 1 -- True -> fromInteger 0 ---- -- Which would result in a priority decoder circuit where a normal -- decoder circuit was desired. -- -- This transformation transforms the above Core to the saner: -- --
-- f = (x :: Unsigned 4) -> case x of -- _ -> error "incomplete case" -- 0 -> fromInteger 3 -- 1 -> fromInteger 2 -- 2 -> fromInteger 1 -- 3 -> fromInteger 0 --caseFlat :: NormRewrite -- | This transformation lifts applications of global binders out of -- alternatives of case-statements. -- -- e.g. It converts: -- --
-- case x of -- A -> f 3 y -- B -> f x x -- C -> h x ---- -- into: -- --
-- let f_arg0 = case x of {A -> 3; B -> x}
-- f_arg1 = case x of {A -> y; B -> x}
-- f_out = f f_arg0 f_arg1
-- in case x of
-- A -> f_out
-- B -> f_out
-- C -> h x
--
disjointExpressionConsolidation :: NormRewrite
removeUnusedExpr :: 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, SrcSpan, Term) -> (HashMap TyConName TyCon -> Type -> Maybe (Either String HWType)) -> HashMap TyConName TyCon -> IntMap TyConName -> (HashMap TyConName TyCon -> Bool -> Term -> Term) -> PrimMap BlackBoxTemplate -> HashMap TmName Bool -> NormalizeSession a -> a
normalize :: [TmName] -> NormalizeSession (HashMap TmName (Type, SrcSpan, Term))
normalize' :: TmName -> NormalizeSession ([TmName], (TmName, (Type, SrcSpan, 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, SrcSpan, Term) -> HashMap TmName (Type, SrcSpan, Term)
-- | Perform general "clean up" of the normalized (non-recursive) function
-- hierarchy. This includes:
--
--