-- 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, but with a very high degree of type inference,
-- enabling both safe and fast prototyping using concise
-- descriptions.
-- - 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, lead to natural descriptions of feedback
-- loops.
-- - 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.99
-- | 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; Bool asserts escape marker stripping
O :: !Bool -> Element
-- | Input hole; Bool asserts escape marker stripping
I :: !Bool -> !Int -> Element
-- | Name hole
N :: !Int -> Element
-- | Literal hole
L :: !Int -> Element
Var :: [Element] -> !Int -> Element
-- | Symbol hole
Sym :: !Text -> !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
IncludeName :: 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
IsGated :: !Int -> Element
IsSync :: !Int -> Element
StrCmp :: [Element] -> !Int -> Element
OutputWireReg :: !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]) runParse = PCC.parse ((,) $ pBlackBoxD *
-- pEnd) . createStr (LineColPos 0 0 0)
runParse :: Text -> Result BlackBoxTemplate
-- | Transform/format a Netlist Identifier so that it is acceptable as a
-- HDL identifier
module Clash.Netlist.Id
data IdType
Basic :: IdType
Extended :: IdType
mkBasicId' :: Bool -> Text -> Text
stripDollarPrefixes :: Text -> Text
-- | 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 -> Bool -> [a] -> [a] -> Maybe ((Text, Text), a) -> !(Either a a) -> Primitive a
-- | Name of the primitive
[name] :: Primitive a -> !Text
-- | Verilog only: whether the result should be a reg(True)
-- or wire (False); when not specified in the
-- .json file, the value will default to False (i.e.
-- wire).
[outputReg] :: Primitive a -> Bool
-- | VHDL only: add library declarations for the given names
[library] :: Primitive a -> [a]
-- | VHDL only: add use declarations for the given names
[imports] :: Primitive a -> [a]
-- | IntelQuartus only: create a .qsys/ file from the given
-- template. Defaults to Nothing when not specified in the
-- .json file
[include] :: Primitive a -> Maybe ((Text, 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)
-- | 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]
infixr 5 <:>
-- | 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
-- | x y -> floor (logBase x y), x > 1 && y > 0
flogBase :: Integer -> Integer -> Maybe Int
-- | x y -> ceiling (logBase x y), x > 1 && y > 0
clogBase :: Integer -> Integer -> Maybe Int
-- | 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
parsePrimitive :: (FromJSON a) => FilePath -> IO [a]
-- | Generate a set of primitives that are found in the primitive
-- definition files in the given directories.
generatePrimMap :: [FilePath] -> IO (PrimMap Text)
-- | Names
module Clash.Core.Name
data Name a
Name :: NameSort -> OccName a -> !SrcSpan -> Name a
[nameSort] :: Name a -> NameSort
[nameOcc] :: Name a -> OccName a
[nameLoc] :: Name a -> !SrcSpan
type OccName a = Name a
data NameSort
User :: NameSort
System :: NameSort
Internal :: NameSort
name2String :: Name a -> String
name2Integer :: Name a -> Integer
string2OccName :: String -> OccName a
string2SystemName :: String -> Name a
string2InternalName :: String -> Name a
makeOccName :: String -> Integer -> OccName a
makeSystemName :: String -> Integer -> Name a
coerceName :: Name a -> Name b
appendToName :: Name a -> String -> Name a
-- | Built-in "bad" SrcSpans for common sources of location
-- uncertainty
noSrcSpan :: SrcSpan
instance Unbound.Generics.LocallyNameless.Alpha.Alpha Clash.Core.Name.NameSort
instance Unbound.Generics.LocallyNameless.Subst.Subst b (Clash.Core.Name.Name a)
instance Data.Hashable.Class.Hashable (Clash.Core.Name.Name a)
instance Control.DeepSeq.NFData (Clash.Core.Name.Name a)
instance GHC.Generics.Generic (Clash.Core.Name.Name a)
instance GHC.Show.Show (Clash.Core.Name.Name a)
instance Data.Hashable.Class.Hashable Clash.Core.Name.NameSort
instance Control.DeepSeq.NFData Clash.Core.Name.NameSort
instance GHC.Generics.Generic Clash.Core.Name.NameSort
instance GHC.Show.Show Clash.Core.Name.NameSort
instance GHC.Classes.Ord Clash.Core.Name.NameSort
instance GHC.Classes.Eq Clash.Core.Name.NameSort
instance GHC.Classes.Eq (Clash.Core.Name.Name a)
instance GHC.Classes.Ord (Clash.Core.Name.Name a)
instance Data.Typeable.Internal.Typeable a => Unbound.Generics.LocallyNameless.Alpha.Alpha (Clash.Core.Name.Name a)
-- | Variables in CoreHW
module Clash.Core.Var
-- | Variables in CoreHW
data Var a
-- | Constructor for type variables
TyVar :: Name a -> Embed Kind -> Var a
[varName] :: Var a -> Name a
[varKind] :: Var a -> Embed Kind
-- | Constructor for term variables
Id :: Name a -> Embed Type -> Var a
[varName] :: Var a -> Name a
[varType] :: Var a -> Embed Type
-- | Term variable
type Id = Var Term
-- | Type variable
type TyVar = Var Type
-- | Change the name of a variable
modifyVarName :: (Name a -> Name a) -> Var a -> Var a
instance Data.Hashable.Class.Hashable (Clash.Core.Var.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 Data.Hashable.Class.Hashable Clash.Core.DataCon.DataCon
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
type TyConOccName = OccName TyCon
type TyConMap = HashMap TyConOccName 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
naturalPrimTy :: Type
tysPrimMap :: HashMap TyConOccName 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
NaturalLiteral :: !Integer -> Literal
-- | Determines the Type of a Literal
literalType :: Literal -> Type
instance Data.Hashable.Class.Hashable Clash.Core.Literal.Literal
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 -> [Alt] -> Term
-- | Cast a term from one type to another
Cast :: !Term -> !Type -> !Type -> Term
-- | Term reference
type TmName = Name Term
type TmOccName = OccName 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
type Alt = Bind Pat Term
instance Data.Hashable.Class.Hashable Clash.Core.Term.Term
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 Data.Hashable.Class.Hashable Clash.Core.Term.Pat
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 :: [(TyOccName, Type)] -> Type -> Type
-- | Substitutes a type in a type
substTy :: TyOccName -> Type -> Type -> Type
-- | Substitutes kinds in a kind
substKindWith :: [(KiOccName, Kind)] -> Kind -> Kind
-- | Substitutes a type in a term
substTyInTm :: TyOccName -> Type -> Term -> Term
-- | Substitutes types in a term
substTysinTm :: [(TyOccName, Type)] -> Term -> Term
-- | Substitutes a term in a term
substTm :: TmOccName -> Term -> Term -> Term
-- | Substitutes terms in a term
substTms :: [(TmOccName, Term)] -> Term -> Term
-- | Substitutes a term in a let-binding
substBndr :: TmOccName -> Term -> LetBinding -> LetBinding
-- | 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
type KiOccName = OccName Kind
-- | Reference to a Type
type TyName = Name Type
type TyOccName = OccName 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 TyConOccName TyCon -> Type -> Maybe Type
-- | Determine the kind of a type
typeKind :: HashMap TyConOccName 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 TyConOccName TyCon -> Type -> Maybe (Type, Type)
splitFunTys :: HashMap TyConOccName 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 TyConOccName 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 TyConOccName TyCon -> Type -> Bool
-- | Is a type polymorphic?
isPolyTy :: Type -> Bool
-- | Is a type a function type?
isFunTy :: HashMap TyConOccName TyCon -> Type -> Bool
-- | Apply a function type to an argument type and get the result type
applyFunTy :: HashMap TyConOccName TyCon -> Type -> Type -> Type
-- | Substitute the type variable of a type (ForAllTy) with another
-- type
applyTy :: Fresh m => HashMap TyConOccName TyCon -> Type -> KindOrType -> m Type
findFunSubst :: HashMap TyConOccName TyCon -> [([Type], Type)] -> [Type] -> Maybe Type
reduceTypeFamily :: HashMap TyConOccName TyCon -> Type -> Maybe Type
-- | The type of GHC.Err.undefined :: forall a . a
undefinedTy :: Type
isIntegerTy :: Type -> Bool
normalizeType :: HashMap TyConOccName TyCon -> Type -> Type
instance GHC.Show.Show Clash.Core.Type.TypeView
instance Data.Hashable.Class.Hashable Clash.Core.Type.ConstTy
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 Data.Hashable.Class.Hashable Clash.Core.Type.Type
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 Data.Hashable.Class.Hashable Clash.Core.Type.LitTy
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.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
instance Unbound.Generics.LocallyNameless.Subst.Subst a Clash.Core.Type.LitTy
-- | Type definitions used by the Driver module
module Clash.Driver.Types
-- | Global function binders
--
-- Global functions cannot be mutually recursive, only self-recursive
type BindingMap = HashMap TmOccName (TmName, Type, SrcSpan, InlineSpec, 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
data ClashOpts
ClashOpts :: Int -> Int -> Word -> Word -> DebugLevel -> Bool -> Bool -> Int -> Maybe String -> HdlSyn -> Bool -> Bool -> Bool -> [FilePath] -> ClashOpts
[opt_inlineLimit] :: ClashOpts -> Int
[opt_specLimit] :: ClashOpts -> Int
[opt_inlineFunctionLimit] :: ClashOpts -> Word
[opt_inlineConstantLimit] :: ClashOpts -> Word
[opt_dbgLevel] :: ClashOpts -> DebugLevel
[opt_cachehdl] :: ClashOpts -> Bool
[opt_cleanhdl] :: ClashOpts -> Bool
[opt_intWidth] :: ClashOpts -> Int
[opt_hdlDir] :: ClashOpts -> Maybe String
[opt_hdlSyn] :: ClashOpts -> HdlSyn
[opt_errorExtra] :: ClashOpts -> Bool
[opt_floatSupport] :: ClashOpts -> Bool
[opt_allowZero] :: ClashOpts -> Bool
[opt_importPaths] :: ClashOpts -> [FilePath]
data ClashException
ClashException :: SrcSpan -> String -> (Maybe String) -> ClashException
-- | Information about the generated HDL between (sub)runs of the compiler
data Manifest
Manifest :: (Int, Maybe Int) -> [Text] -> [Text] -> [Text] -> [Text] -> [Text] -> Manifest
-- | Hash of the TopEntity and all its dependencies + (maybe) Hash of the
-- TestBench and all its dependencies
[manifestHash] :: Manifest -> (Int, Maybe Int)
[portInNames] :: Manifest -> [Text]
-- | The rendered versions of the types of the input ports of the TopEntity
--
-- Used when dealing with multiple TopEntitys who have different
-- names for types which are structurally equal
[portInTypes] :: Manifest -> [Text]
[portOutNames] :: Manifest -> [Text]
-- | The rendered versions of the types of the output ports of the
-- TopEntity
--
-- Used when dealing with multiple TopEntitys who have different
-- names for types which are structurally equal
[portOutTypes] :: Manifest -> [Text]
-- | Names of all the generated components for the TopEntity (does
-- not include the names of the components of the TestBench
-- accompanying the TopEntity).
[componentNames] :: Manifest -> [Text]
-- | Source Span
--
-- A SrcSpan identifies either a specific portion of a text file
-- or a human-readable description of a location.
data SrcSpan :: *
-- | Built-in "bad" SrcSpans for common sources of location
-- uncertainty
noSrcSpan :: SrcSpan
instance GHC.Read.Read Clash.Driver.Types.Manifest
instance GHC.Show.Show Clash.Driver.Types.Manifest
instance GHC.Read.Read Clash.Driver.Types.DebugLevel
instance GHC.Classes.Ord Clash.Driver.Types.DebugLevel
instance GHC.Classes.Eq Clash.Driver.Types.DebugLevel
instance GHC.Show.Show Clash.Driver.Types.ClashException
instance GHC.Exception.Exception Clash.Driver.Types.ClashException
-- | Type and instance definitions for Netlist modules
module Clash.Netlist.Types
-- | 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
-- - Type of the scrutinee
-- - List of: (Maybe expression scrutinized expression is compared
-- with,RHS of alternative)
--
CondAssignment :: !Identifier -> !HWType -> !Expr -> !HWType -> [(Maybe Literal, Expr)] -> Declaration
-- | Instantiation of another component
InstDecl :: (Maybe Identifier) -> !Identifier -> !Identifier -> [(Expr, PortDirection, HWType, Expr)] -> Declaration
-- | Instantiation of blackbox declaration
BlackBoxD :: !Text -> [BlackBoxTemplate] -> [BlackBoxTemplate] -> (Maybe ((Text, Text), BlackBoxTemplate)) -> !BlackBoxTemplate -> BlackBoxContext -> Declaration
-- | Signal declaration
NetDecl' :: (Maybe Identifier) -> WireOrReg -> !Identifier -> (Either Identifier HWType) -> Declaration
-- | Monad that caches generated components (StateT) and remembers hidden
-- inputs of components that are being generated (WriterT)
newtype NetlistMonad a
NetlistMonad :: StateT NetlistState (FreshMT IO) a -> NetlistMonad a
[runNetlist] :: NetlistMonad a -> StateT NetlistState (FreshMT IO) a
-- | State of the NetlistMonad
data NetlistState
NetlistState :: BindingMap -> !Int -> HashMap TmOccName (SrcSpan, Component) -> PrimMap BlackBoxTemplate -> (HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)) -> HashMap TyConOccName TyCon -> !(Identifier, SrcSpan) -> [(String, FilePath)] -> Int -> (IdType -> Identifier -> Identifier) -> (IdType -> Identifier -> Identifier -> Identifier) -> [Identifier] -> [Identifier] -> HashMap TmOccName Identifier -> HashMap TmOccName (Type, Maybe TopEntity) -> FilePath -> NetlistState
-- | Global binders
[_bindings] :: NetlistState -> BindingMap
-- | Number of signal declarations
[_varCount] :: NetlistState -> !Int
-- | Cached components
[_components] :: NetlistState -> HashMap TmOccName (SrcSpan, Component)
-- | Primitive Definitions
[_primitives] :: NetlistState -> PrimMap BlackBoxTemplate
-- | Hardcoded Type -> HWType translator
[_typeTranslator] :: NetlistState -> HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)
-- | TyCon cache
[_tcCache] :: NetlistState -> HashMap TyConOccName TyCon
[_curCompNm] :: NetlistState -> !(Identifier, SrcSpan)
[_dataFiles] :: NetlistState -> [(String, FilePath)]
[_intWidth] :: NetlistState -> Int
[_mkIdentifierFn] :: NetlistState -> IdType -> Identifier -> Identifier
[_extendIdentifierFn] :: NetlistState -> IdType -> Identifier -> Identifier -> Identifier
[_seenIds] :: NetlistState -> [Identifier]
[_seenComps] :: NetlistState -> [Identifier]
[_componentNames] :: NetlistState -> HashMap TmOccName Identifier
[_topEntityAnns] :: NetlistState -> HashMap TmOccName (Type, Maybe TopEntity)
[_hdlDir] :: NetlistState -> FilePath
-- | Signal reference
type Identifier = Text
-- | Component: base unit of a Netlist
data Component
Component :: !Identifier -> [(Identifier, HWType)] -> [(WireOrReg, (Identifier, HWType))] -> [Declaration] -> Component
-- | Name of the component
[componentName] :: Component -> !Identifier
-- | Input ports
[inputs] :: Component -> [(Identifier, HWType)]
-- | Output ports
[outputs] :: Component -> [(WireOrReg, (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. Just Size for "empty" Vectors so we can still
-- have primitives that can traverse e.g. Vectors of unit and know the
-- lenght of that vector.
Void :: (Maybe HWType) -> HWType
-- | String type
String :: HWType
-- | Boolean type
Bool :: HWType
-- | Bit type
Bit :: HWType
-- | BitVector of a specified size
BitVector :: !Size -> HWType
-- | Unsigned integer with specified (exclusive) upper bounder
Index :: !Integer -> HWType
-- | Signed integer of a specified size
Signed :: !Size -> HWType
-- | Unsigned integer of a specified size
Unsigned :: !Size -> HWType
-- | Vector type
Vector :: !Size -> !HWType -> HWType
-- | RTree type
RTree :: !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 -> !Integer -> !ClockKind -> HWType
-- | Reset type corresponding to clock with a specified name and period
Reset :: !Identifier -> !Integer -> !ResetKind -> 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
-- - Type of the scrutinee
-- - List of: (Maybe expression scrutinized expression is compared
-- with,RHS of alternative)
--
CondAssignment :: !Identifier -> !HWType -> !Expr -> !HWType -> [(Maybe Literal, Expr)] -> Declaration
-- | Instantiation of another component
InstDecl :: (Maybe Identifier) -> !Identifier -> !Identifier -> [(Expr, PortDirection, HWType, Expr)] -> Declaration
-- | Instantiation of blackbox declaration
BlackBoxD :: !Text -> [BlackBoxTemplate] -> [BlackBoxTemplate] -> (Maybe ((Text, Text), BlackBoxTemplate)) -> !BlackBoxTemplate -> BlackBoxContext -> Declaration
-- | Signal declaration
NetDecl' :: (Maybe Identifier) -> WireOrReg -> !Identifier -> (Either Identifier HWType) -> Declaration
data WireOrReg
Wire :: WireOrReg
Reg :: WireOrReg
data PortDirection
In :: PortDirection
Out :: PortDirection
-- | 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
-- | See the expression in the context of a Tree append operation
RTreeAppend :: Modifier
Nested :: Modifier -> Modifier -> 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] -> [BlackBoxTemplate] -> (Maybe ((Text, Text), BlackBoxTemplate)) -> !BlackBoxTemplate -> !BlackBoxContext -> !Bool -> Expr
ConvBV :: (Maybe Identifier) -> HWType -> Bool -> Expr -> 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 :: (Expr, HWType) -> [(Expr, HWType, Bool)] -> IntMap (Either BlackBoxTemplate (Identifier, [Declaration]), WireOrReg, [BlackBoxTemplate], [BlackBoxTemplate], Maybe ((Text, Text), BlackBoxTemplate), BlackBoxContext) -> Maybe Identifier -> BlackBoxContext
-- | Result name and type
[bbResult] :: BlackBoxContext -> (Expr, HWType)
-- | Argument names, types, and whether it is a literal
[bbInputs] :: BlackBoxContext -> [(Expr, HWType, Bool)]
-- | Function arguments (subset of inputs):
--
--
-- - ( Blackbox Template , Whether the result should be reg or a
-- wire (Verilog only) , Partial Blackbox Context )
--
[bbFunctions] :: BlackBoxContext -> IntMap (Either BlackBoxTemplate (Identifier, [Declaration]), WireOrReg, [BlackBoxTemplate], [BlackBoxTemplate], Maybe ((Text, Text), BlackBoxTemplate), BlackBoxContext)
[bbQsysIncName] :: BlackBoxContext -> Maybe Identifier
emptyBBContext :: BlackBoxContext
varCount :: Lens' NetlistState Int
typeTranslator :: Lens' NetlistState (HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType))
topEntityAnns :: Lens' NetlistState (HashMap TmOccName (Type, Maybe TopEntity))
tcCache :: Lens' NetlistState (HashMap TyConOccName TyCon)
seenIds :: Lens' NetlistState [Identifier]
seenComps :: Lens' NetlistState [Identifier]
primitives :: Lens' NetlistState (PrimMap BlackBoxTemplate)
mkIdentifierFn :: Lens' NetlistState (IdType -> Identifier -> Identifier)
intWidth :: Lens' NetlistState Int
hdlDir :: Lens' NetlistState FilePath
extendIdentifierFn :: Lens' NetlistState (IdType -> Identifier -> Identifier -> Identifier)
dataFiles :: Lens' NetlistState [(String, FilePath)]
curCompNm :: Lens' NetlistState (Identifier, SrcSpan)
components :: Lens' NetlistState (HashMap TmOccName (SrcSpan, Component))
componentNames :: Lens' NetlistState (HashMap TmOccName Identifier)
bindings :: Lens' NetlistState BindingMap
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 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.Expr
instance GHC.Show.Show Clash.Netlist.Types.BlackBoxContext
instance GHC.Show.Show Clash.Netlist.Types.Literal
instance GHC.Classes.Eq Clash.Netlist.Types.Literal
instance GHC.Show.Show Clash.Netlist.Types.Bit
instance GHC.Classes.Eq Clash.Netlist.Types.Bit
instance GHC.Show.Show Clash.Netlist.Types.Modifier
instance GHC.Show.Show Clash.Netlist.Types.PortDirection
instance GHC.Generics.Generic Clash.Netlist.Types.WireOrReg
instance GHC.Show.Show Clash.Netlist.Types.WireOrReg
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 Control.DeepSeq.NFData Clash.Netlist.Types.Declaration
instance Control.DeepSeq.NFData Clash.Netlist.Types.WireOrReg
instance Data.Hashable.Class.Hashable Clash.Netlist.Types.HWType
instance Control.DeepSeq.NFData Clash.Netlist.Types.HWType
instance Data.Hashable.Class.Hashable Clash.Signal.Internal.ClockKind
instance Data.Hashable.Class.Hashable Clash.Signal.Internal.ResetKind
module Clash.Backend
type ModName = String
-- | Is a type used for internal or external use
data Usage
-- | Internal use
Internal :: Usage
-- | External use, field indicates the library name
External :: Text -> Usage
class Backend state
-- | Initial state for state monad
initBackend :: Backend state => Int -> HdlSyn -> state
-- | What HDL is the backend generating
hdlKind :: Backend state => state -> HDL
-- | Location for the primitive definitions
primDirs :: 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 -> Mon (State state) ((String, Doc), [(String, Doc)])
-- | Generate a HDL package containing type definitions for the given
-- HWTypes
mkTyPackage :: Backend state => String -> [HWType] -> Mon (State state) [(String, Doc)]
-- | Convert a Netlist HWType to a target HDL type
hdlType :: Backend state => Usage -> HWType -> Mon (State state) Doc
-- | Convert a Netlist HWType to an HDL error value for that type
hdlTypeErrValue :: Backend state => HWType -> Mon (State state) Doc
-- | Convert a Netlist HWType to the root of a target HDL type
hdlTypeMark :: Backend state => HWType -> Mon (State state) Doc
-- | Create a signal declaration from an identifier (Text) and Netlist
-- HWType
hdlSig :: Backend state => Text -> HWType -> Mon (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 -> Mon (State state) (Maybe Doc)
-- | Turn a Netlist expression into a HDL expression
expr :: Backend state => Bool -> Expr -> Mon (State state) Doc
-- | Bit-width of IntWordInteger
iwWidth :: Backend state => State state Int
-- | Convert to a bit-vector
toBV :: Backend state => HWType -> Text -> Mon (State state) Doc
-- | Convert from a bit-vector
fromBV :: Backend state => HWType -> Text -> Mon (State state) Doc
-- | Synthesis tool we're generating HDL for
hdlSyn :: Backend state => State state HdlSyn
-- | mkIdentifier
mkIdentifier :: Backend state => State state (IdType -> Identifier -> Identifier)
-- | mkIdentifier
extendIdentifier :: Backend state => State state (IdType -> Identifier -> Identifier -> Identifier)
-- | setModName
setModName :: Backend state => ModName -> state -> state
-- | setSrcSpan
setSrcSpan :: Backend state => SrcSpan -> State state ()
-- | getSrcSpan
getSrcSpan :: Backend state => State state SrcSpan
-- | Block of declarations
blockDecl :: Backend state => Text -> [Declaration] -> Mon (State state) Doc
-- | unextend/unescape identifier
unextend :: Backend state => State state (Identifier -> Identifier)
addInclude :: Backend state => (String, Doc) -> State state ()
addLibraries :: Backend state => [Text] -> State state ()
addImports :: Backend state => [Text] -> State state ()
-- | Try to merge nested modifiers into a single modifier, needed by the
-- VHDL and SystemVerilog backend.
nestM :: Modifier -> Modifier -> Maybe Modifier
-- | Replace a normal HDL template placeholder with an unescaped/unextended
-- template placeholder.
--
-- Needed when the the place-holder is filled with an escaped/extended
-- identifier inside an escaped/extended identifier and we want to strip
-- the escape /extension markers. Otherwise we end up with illegal
-- identifiers.
escapeTemplate :: Identifier -> Identifier
-- | Free variable calculations
module Clash.Core.FreeVars
-- | Gives the free type-variables in a Type
typeFreeVars :: Fold Type TyOccName
-- | Gives the free term-variables of a Term
termFreeIds :: Fold Term TmOccName
-- | Gives the free type-variables of a Term
termFreeTyVars :: Fold Term TyOccName
-- | Pretty printing class and instances for CoreHW
module Clash.Core.Pretty
-- | Pretty printing Show-like typeclass
class Pretty p
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 Clash.Core.Term.Pat
instance Clash.Core.Pretty.Pretty (Clash.Core.Name.OccName a)
instance Clash.Core.Pretty.Pretty (Clash.Core.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 Data.Text.Internal.Text
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
-- | Smart constructor and destructor functions for CoreHW
module Clash.Core.Util
-- | Type environment/context
type Gamma = HashMap TmOccName Type
-- | Kind environment/context
type Delta = HashMap TyOccName Kind
-- | Determine the type of a term
termType :: Fresh m => HashMap TyConOccName 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 TyConOccName 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 TyConOccName TyCon -> Term -> m Bool
-- | Does a term have a function or polymorphic type?
isPolyFun :: Fresh m => HashMap TyConOccName 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 -> Word
-- | 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.:
--
--
-- - Signal' clk a
-- - (Signal' clk a, Signal' clk b)
-- - Vec n (Signal' clk a)
-- - data Wrap = W (Signal clk' Int)
-- - etc.
--
isSignalType :: HashMap TyConOccName TyCon -> Type -> Bool
isClockOrReset :: HashMap TyConOccName TyCon -> Type -> Bool
tyNatSize :: HashMap TyConOccName TyCon -> Type -> Except String Integer
-- | Utilities for converting Core Type/Term to Netlist datatypes
module Clash.Netlist.Util
isVoid :: HWType -> Bool
mkIdentifier :: IdType -> Identifier -> NetlistMonad Identifier
extendIdentifier :: IdType -> Identifier -> Identifier -> NetlistMonad Identifier
-- | 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 => HashMap TyConOccName 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 :: SrcSpan -> String -> (HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)) -> HashMap TyConOccName TyCon -> Bool -> 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 TyConOccName TyCon -> Type -> Maybe (Identifier, Integer)
-- | 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 TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)) -> HashMap TyConOccName TyCon -> Bool -> Type -> Either String HWType
-- | Converts an algebraic Core type (split into a TyCon and its argument)
-- to a HWType.
mkADT :: (HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)) -> HashMap TyConOccName TyCon -> String -> Bool -> TyConName -> [Type] -> Either String HWType
-- | Simple check if a TyCon is recursively defined.
isRecursiveTy :: HashMap TyConOccName TyCon -> TyConName -> Bool
-- | Determines if a Core type is translatable to a HWType given a function
-- that translates certain builtin types.
representableType :: (HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)) -> Bool -> Bool -> HashMap TyConOccName 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)
-- | Uniquely rename all the variables and their references in a normalized
-- term
mkUniqueNormalized :: Maybe (Maybe TopEntity) -> ([Id], [LetBinding], Id) -> NetlistMonad ([(Identifier, HWType)], [Declaration], [(Identifier, HWType)], [Declaration], [LetBinding], TmName)
mkUniqueArguments :: Maybe (Maybe TopEntity) -> [Id] -> NetlistMonad ([(Identifier, HWType)], [Declaration], [(TmOccName, Term)])
mkUniqueResult :: Maybe (Maybe TopEntity) -> Id -> NetlistMonad ([(Identifier, HWType)], [Declaration], Id, (TmOccName, Term))
idToPort :: Id -> NetlistMonad (Identifier, HWType)
repName :: String -> Name a -> Name a
-- | Make a set of IDs unique; also returns a substitution from old ID to
-- new updated unique ID.
mkUnique :: [(TmOccName, Term)] -> [Id] -> NetlistMonad ([Id], [(TmOccName, Term)])
mkUniqueIdentifier :: IdType -> Identifier -> NetlistMonad Identifier
-- | Preserve the Netlist _varEnv and _varCount when
-- executing a monadic action
preserveVarEnv :: NetlistMonad a -> NetlistMonad a
dcToLiteral :: HWType -> Int -> Literal
extendPorts :: [PortName] -> [Maybe PortName]
appendNumber :: (Identifier, HWType) -> Int -> (Identifier, HWType)
portName :: String -> Identifier -> Identifier
appendIdentifier :: (Identifier, HWType) -> Int -> NetlistMonad (Identifier, HWType)
uniquePortName :: String -> Identifier -> NetlistMonad Identifier
mkInput :: Maybe PortName -> (Identifier, HWType) -> NetlistMonad ([(Identifier, HWType)], [Declaration], Expr, Identifier)
filterVoid :: HWType -> HWType
-- | Create a Vector chain for a list of Identifiers
mkVectorChain :: Int -> HWType -> [Expr] -> Expr
-- | Create a RTree chain for a list of Identifiers
mkRTreeChain :: Int -> HWType -> [Expr] -> Expr
genComponentName :: [Identifier] -> (IdType -> Identifier -> Identifier) -> TmName -> Identifier
-- | Generate output port mappings
mkOutput :: Maybe PortName -> (Identifier, HWType) -> NetlistMonad ([(Identifier, HWType)], [Declaration], Identifier)
-- | Instantiate a TopEntity, and add the proper type-conversions where
-- needed
mkTopUnWrapper :: TmName -> Maybe TopEntity -> Manifest -> (Identifier, HWType) -> [(Expr, HWType)] -> NetlistMonad [Declaration]
-- | Convert between BitVector for an argument
argBV :: Maybe Identifier -> Either Identifier (Identifier, HWType) -> Expr -> Declaration
-- | Convert between BitVector for the result
resBV :: Maybe Identifier -> Either Identifier (Identifier, HWType) -> Expr
-- | Add to/from-BitVector conversion logic
doConv :: HWType -> Maybe (Maybe Identifier) -> Bool -> Expr -> Expr
-- | Generate input port mappings for the TopEntity
mkTopInput :: Maybe Identifier -> [(Identifier, Identifier)] -> Maybe PortName -> (Identifier, HWType) -> NetlistMonad ([(Identifier, Identifier)], ([(Identifier, Identifier, HWType)], [Declaration], Either Identifier (Identifier, HWType)))
-- | Generate output port mappings for the TopEntity
mkTopOutput :: Maybe Identifier -> [(Identifier, Identifier)] -> Maybe PortName -> (Identifier, HWType) -> NetlistMonad ([(Identifier, Identifier)], ([(Identifier, Identifier, HWType)], [Declaration], Either Identifier (Identifier, HWType)))
concatPortDecls3 :: [([(Identifier, Identifier, HWType)], [Declaration], Either Identifier (Identifier, HWType))] -> ([(Identifier, Identifier, HWType)], [Declaration], [Either Identifier (Identifier, HWType)])
-- | 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 :: BlackBoxContext -> BlackBoxTemplate -> NetlistMonad (BlackBoxTemplate, [Declaration])
setCompName :: Identifier -> BlackBoxTemplate -> BlackBoxTemplate
findAndSetDataFiles :: BlackBoxContext -> [(String, FilePath)] -> BlackBoxTemplate -> ([(String, FilePath)], BlackBoxTemplate)
renderFilePath :: [(String, FilePath)] -> String -> ([(String, FilePath)], Element)
-- | 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.
renderTemplate :: Backend backend => BlackBoxContext -> BlackBoxTemplate -> State backend (Int -> Text)
renderBlackBox :: Backend backend => [BlackBoxTemplate] -> [BlackBoxTemplate] -> Maybe ((Text, Text), BlackBoxTemplate) -> BlackBoxTemplate -> BlackBoxContext -> State backend (Int -> Doc)
-- | Assign Var holes in the context of a primitive HDL template
-- that is passed as an argument of a higher-order HDL template. For the
-- general case, use setSym
--
-- This functions errors when the Var hole cannot be filled with
-- a variable, as it is (currently) impossible to create unique names
-- this late in the pipeline.
setSimpleVar :: BlackBoxContext -> BlackBoxTemplate -> BlackBoxTemplate
-- | Render a single template element
renderElem :: Backend backend => BlackBoxContext -> Element -> State backend (Int -> Text)
parseFail :: Text -> BlackBoxTemplate
idToExpr :: (Text, HWType) -> (Expr, 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
exprToText :: Expr -> Maybe Text
prettyBlackBox :: Monad m => BlackBoxTemplate -> Mon m Text
prettyElem :: Monad m => Element -> Mon m Text
usedArguments :: BlackBoxTemplate -> [Int]
-- | Generate Verilog for assorted Netlist datatypes
module Clash.Backend.Verilog
-- | State for the VerilogM monad:
data VerilogState
include :: Monad m => [Text] -> Mon m Doc
instance Clash.Backend.Backend Clash.Backend.Verilog.VerilogState
-- | Generate VHDL for assorted Netlist datatypes
module Clash.Backend.VHDL
-- | State for the VHDLM monad:
data VHDLState
instance Clash.Backend.Backend Clash.Backend.VHDL.VHDLState
-- | Generate SystemVerilog for assorted Netlist datatypes
module Clash.Backend.SystemVerilog
-- | State for the SystemVerilogM monad:
data SystemVerilogState
instance Clash.Backend.Backend Clash.Backend.SystemVerilog.SystemVerilogState
-- | Call-by-need evaluator based on the evaluator described in:
--
-- Maximilian Bolingbroke, Simon Peyton Jones, "Supercompilation by
-- evaluation", Haskell '10, Baltimore, Maryland, USA.
module Clash.Core.Evaluator
-- | The heap
data Heap
Heap :: PureHeap -> Supply -> Heap
type PureHeap = Map TmOccName Term
-- | The stack
type Stack = [StackFrame]
data StackFrame
Update :: Id -> StackFrame
Apply :: Id -> StackFrame
Instantiate :: Type -> StackFrame
PrimApply :: Text -> Type -> [Type] -> [Value] -> [Term] -> StackFrame
Scrutinise :: Type -> [Alt] -> StackFrame
data Value
-- | Functions
Lambda :: (Bind Id Term) -> Value
-- | Type abstractions
TyLambda :: (Bind TyVar Term) -> Value
-- | Data constructors
DC :: DataCon -> [Either Term Type] -> Value
-- | Literals
Lit :: Literal -> Value
-- | Clash's number types are represented by their "fromInteger#" primitive
-- function. So some primitives are values.
PrimVal :: Text -> Type -> [Type] -> [Value] -> Value
-- | State of the evaluator
type State = (Heap, Stack, Term)
-- | Function that can evaluator primitives, i.e., perform delta-reduction
type PrimEvaluator = Bool -> BindingMap -> TyConMap -> Heap -> Stack -> Text -> Type -> [Type] -> [Value] -> Maybe State
-- | Evaluate to WHNF starting with an empty Heap and Stack
whnf' :: PrimEvaluator -> BindingMap -> TyConMap -> Supply -> Bool -> Term -> Term
-- | Evaluate to WHNF given an existing Heap and Stack
whnf :: PrimEvaluator -> BindingMap -> TyConMap -> Bool -> State -> State
-- | Are we in a context where special primitives must be forced.
--
-- See [Note: forcing special primitives]
isScrut :: Stack -> Bool
-- | Completely unwind the stack to get back the complete term
unwindStack :: State -> Maybe State
-- | Small-step operational semantics.
step :: PrimEvaluator -> BindingMap -> TyConMap -> State -> Maybe State
newLetBinding :: TyConMap -> Heap -> Term -> (Heap, Id)
newLetBindings' :: TyConMap -> Heap -> [Either Term Type] -> (Heap, [Either Term Type])
mkAbstr :: (Heap, Term) -> [Either TyVar Type] -> (Heap, Term)
-- | Force the evaluation of a variable.
force :: BindingMap -> Heap -> Stack -> Id -> Maybe State
-- | Unwind the stack by 1
unwind :: PrimEvaluator -> BindingMap -> TyConMap -> Heap -> Stack -> Value -> Maybe State
-- | Update the Heap with the evaluated term
update :: Heap -> Stack -> Id -> Value -> State
valToTerm :: Value -> Term
toVar :: Id -> Term
toType :: TyVar -> Type
-- | Apply a value to a function
apply :: Heap -> Stack -> Value -> Id -> State
-- | Instantiate a type-abstraction
instantiate :: Heap -> Stack -> Value -> Type -> State
-- | Evaluation of primitive operations
primop :: PrimEvaluator -> BindingMap -> TyConMap -> Heap -> Stack -> Text -> Type -> [Type] -> [Value] -> Value -> [Term] -> Maybe State
-- | Evaluate a case-expression
scrutinise :: Heap -> Stack -> Value -> [Alt] -> State
matchLit :: DataCon -> Literal -> Bool
substAlt :: DataCon -> Rebind [TyVar] [Id] -> [Either Term Type] -> Term -> Term
-- | Allocate let-bindings on the heap
allocate :: Heap -> Stack -> (Bind (Rec [LetBinding]) Term) -> State
-- | Create a unique name and substitution for a let-binder
letSubst :: PureHeap -> Supply -> Id -> (Supply, (TmOccName, (TmOccName, Term)))
-- | Create a name that's unique in the heap
uniqueInHeap :: PureHeap -> Supply -> TmOccName -> (Supply, TmName)
instance GHC.Show.Show Clash.Core.Evaluator.StackFrame
instance GHC.Show.Show Clash.Core.Evaluator.Value
instance GHC.Show.Show Clash.Core.Evaluator.Heap
instance Clash.Core.Pretty.Pretty Clash.Core.Evaluator.StackFrame
-- | 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 -> [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
-- | Body of a Cast
CastBody :: CoreContext
-- | State of a rewriting session
data RewriteState extra
RewriteState :: {-# UNPACK #-} !Int -> !BindingMap -> !Supply -> (TmName, SrcSpan) -> {-# UNPACK #-} !Int -> !extra -> RewriteState extra
-- | Number of applied transformations
[_transformCounter] :: RewriteState extra -> {-# UNPACK #-} !Int
-- | Global binders
[_bindings] :: RewriteState extra -> !BindingMap
-- | Supply of unique numbers
[_uniqSupply] :: RewriteState extra -> !Supply
-- | Function which is currently normalized
[_curFun] :: RewriteState extra -> (TmName, SrcSpan)
-- | Used for Fresh
[_nameCounter] :: RewriteState extra -> {-# UNPACK #-} !Int
-- | Additional state
[_extra] :: RewriteState extra -> !extra
uniqSupply :: forall extra_a46c3. Lens' (RewriteState extra_a46c3) Supply
transformCounter :: forall extra_a46c3. Lens' (RewriteState extra_a46c3) Int
nameCounter :: forall extra_a46c3. Lens' (RewriteState extra_a46c3) Int
extra :: forall extra_a46c3 extra_a46gN. Lens (RewriteState extra_a46c3) (RewriteState extra_a46gN) extra_a46c3 extra_a46gN
curFun :: forall extra_a46c3. Lens' (RewriteState extra_a46c3) (TmName, SrcSpan)
bindings :: forall extra_a46c3. Lens' (RewriteState extra_a46c3) BindingMap
-- | Read-only environment of a rewriting session
data RewriteEnv
RewriteEnv :: DebugLevel -> (HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)) -> HashMap TyConOccName TyCon -> IntMap TyConName -> PrimEvaluator -> Bool -> HashSet TmOccName -> RewriteEnv
-- | Lvl at which we print debugging messages
[_dbgLevel] :: RewriteEnv -> DebugLevel
-- | Hardcode Type -> HWType translator
[_typeTranslator] :: RewriteEnv -> HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)
-- | TyCon cache
[_tcCache] :: RewriteEnv -> HashMap TyConOccName TyCon
-- | Tuple TyCon cache
[_tupleTcCache] :: RewriteEnv -> IntMap TyConName
-- | Hardcoded evaluator (delta-reduction)}
[_evaluator] :: RewriteEnv -> PrimEvaluator
-- | Zero bit wide things are representable
[_allowZero] :: RewriteEnv -> Bool
-- | Functions that are considered TopEntities
[_topEntities] :: RewriteEnv -> HashSet TmOccName
typeTranslator :: Lens' RewriteEnv (HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType))
tupleTcCache :: Lens' RewriteEnv (IntMap TyConName)
topEntities :: Lens' RewriteEnv (HashSet TmOccName)
tcCache :: Lens' RewriteEnv (HashMap TyConOccName TyCon)
evaluator :: Lens' RewriteEnv PrimEvaluator
dbgLevel :: Lens' RewriteEnv DebugLevel
allowZero :: Lens' RewriteEnv Bool
-- | 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 Control.Monad.Fix.MonadFix (Clash.Rewrite.Types.RewriteMonad extra)
instance GHC.Show.Show Clash.Rewrite.Types.CoreContext
instance GHC.Classes.Eq Clash.Rewrite.Types.CoreContext
-- | 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)
closestLetBinder :: [CoreContext] -> Maybe Id
mkDerivedName :: [CoreContext] -> String -> TmName
-- | 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 :: (Fresh m, MonadUnique m) => HashMap TyConOccName TyCon -> Name a -> Term -> m (Id, Term)
-- | Make a new binder and variable reference for either a term or a type
mkBinderFor :: (Monad m, MonadUnique m, Fresh m) => HashMap TyConOccName TyCon -> Name a -> Either Term Type -> m (Either (Id, Term) (TyVar, Type))
-- | Make a new, unique, identifier and corresponding variable reference
mkInternalVar :: (Monad m, MonadUnique m) => TmName -> 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
-- | Determines whether a function has the following shape:
--
--
-- \(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 ((TmOccName -> f TmOccName) -> 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 -> InlineSpec -> Term -> RewriteMonad extra (TmName, Type)
-- | Add a function to the set of global binders
addGlobalBind :: TmName -> Type -> SrcSpan -> InlineSpec -> Term -> RewriteMonad extra ()
-- | Create a new name out of the given name, but with another unique
cloneVar :: (Monad m, MonadUnique m) => Name a -> m (Name a)
-- | 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 :: Bool -> Term -> RewriteMonad extra Bool
-- | Determine if a type cannot be represented in hardware
isUntranslatableType :: Bool -> 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 TyConOccName TyCon -> Term -> Int -> Int -> m Term
-- | Specialise an application on its argument
specialise :: Lens' extra (Map (TmOccName, Int, Either Term Type) (TmName, Type)) -> Lens' extra (HashMap TmOccName Int) -> Lens' extra Int -> Rewrite extra
-- | Specialise an application on its argument
specialise' :: Lens' extra (Map (TmOccName, Int, Either Term Type) (TmName, Type)) -> Lens' extra (HashMap TmOccName Int) -> Lens' extra Int -> [CoreContext] -> Term -> (Term, [Either Term Type]) -> Either Term Type -> RewriteMonad extra Term
normalizeTermTypes :: HashMap TyConOccName TyCon -> Term -> Term
normalizeId :: HashMap TyConOccName TyCon -> Id -> Id
-- | Create binders and variable references for free variables in
-- specArg
specArgBndrsAndVars :: [CoreContext] -> Either Term Type -> RewriteMonad extra ([Either Id TyVar], [Either Term Type])
-- | Rewriting combinators and traversals
module Clash.Rewrite.Combinators
-- | Apply a transformation on the subtrees of an term
allR :: forall m. (Monad m, Fresh m) => Bool -> Transform m -> Transform m
-- | Apply two transformations in succession
(>->) :: Monad m => Transform m -> Transform m -> Transform m
infixr 6 >->
-- | Apply two transformations in succession, and perform a deepseq in
-- between.
(>-!->) :: Monad m => Transform m -> Transform m -> Transform m
infixr 6 >-!->
-- | Apply a transformation in a topdown traversal
topdownR :: Rewrite m -> Rewrite m
-- | Apply a transformation in a topdown traversal. Doesn't freshen bound
-- variables
unsafeTopdownR :: Rewrite m -> Rewrite m
-- | Apply a transformation in a bottomup traversal
bottomupR :: Fresh m => Transform m -> Transform m
-- | Apply a transformation in a bottomup traversal. Doesn't freshen bound
-- variables
unsafeBottomupR :: Fresh m => Transform m -> Transform m
-- | Only apply the second transformation if the first one succeeds.
(!->) :: Rewrite m -> Rewrite m -> Rewrite m
infixr 5 !->
-- | Only apply the second transformation if the first one fails.
(>-!) :: Rewrite m -> Rewrite m -> Rewrite m
infixr 5 >-!
-- | 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 :: Fresh m => ([CoreContext] -> Term -> m Bool) -> Transform m -> Transform m
-- | Types used in Normalize modules
module Clash.Normalize.Types
-- | State of the NormalizeMonad
data NormalizeState
NormalizeState :: BindingMap -> Map (TmOccName, Int, Either Term Type) (TmName, Type) -> HashMap TmOccName Int -> !Int -> HashMap TmOccName (HashMap TmOccName Int) -> !Int -> !Word -> !Word -> PrimMap BlackBoxTemplate -> HashMap TmOccName Bool -> NormalizeState
-- | Global binders
[_normalized] :: NormalizeState -> BindingMap
-- | 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 (TmOccName, Int, Either Term Type) (TmName, Type)
-- | Cache of how many times a function was specialized
[_specialisationHistory] :: NormalizeState -> HashMap TmOccName 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 TmOccName (HashMap TmOccName 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
[_inlineFunctionLimit] :: NormalizeState -> !Word
-- | Size of a constant below which it is always inlined; 0 = no limit
[_inlineConstantLimit] :: NormalizeState -> !Word
-- | Primitive Definitions
[_primitives] :: NormalizeState -> PrimMap BlackBoxTemplate
-- | Map telling whether a components is recursively defined.
--
-- NB: there are only no mutually-recursive component, only
-- self-recursive ones.
[_recursiveComponents] :: NormalizeState -> HashMap TmOccName Bool
specialisationLimit :: Lens' NormalizeState Int
specialisationHistory :: Lens' NormalizeState (HashMap TmOccName Int)
specialisationCache :: Lens' NormalizeState (Map (TmOccName, Int, Either Term Type) (TmName, Type))
recursiveComponents :: Lens' NormalizeState (HashMap TmOccName Bool)
primitives :: Lens' NormalizeState (PrimMap BlackBoxTemplate)
normalized :: Lens' NormalizeState BindingMap
inlineLimit :: Lens' NormalizeState Int
inlineHistory :: Lens' NormalizeState (HashMap TmOccName (HashMap TmOccName Int))
inlineFunctionLimit :: Lens' NormalizeState Word
inlineConstantLimit :: Lens' NormalizeState Word
-- | 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
-- | Description of a Term in terms of the type "components" the
-- Term has.
--
-- Is used as a performance/size metric.
data TermClassification
TermClassification :: !Int -> !Int -> !Int -> TermClassification
-- | Number of functions
[_function] :: TermClassification -> !Int
-- | Number of primitives
[_primitive] :: TermClassification -> !Int
-- | Number of selections/multiplexers
[_selection] :: TermClassification -> !Int
selection :: Lens' TermClassification Int
primitive :: Lens' TermClassification Int
function :: Lens' TermClassification Int
instance GHC.Show.Show Clash.Normalize.Types.TermClassification
-- | 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 :: TmOccName -> TmOccName -> NormalizeMonad (Maybe Int)
addNewInline :: TmOccName -> TmOccName -> NormalizeMonad ()
-- | Specialize under the Normalization Monad
specializeNorm :: NormRewrite
-- | Determine if a term is closed
isClosed :: Fresh m => HashMap TyConOccName TyCon -> Term -> m Bool
-- | Determine if a term represents a constant
isConstant :: Term -> Bool
isConstantNotClockReset :: Term -> NormalizeSession Bool
-- | Assert whether a name is a reference to a recursive binder.
isRecursiveBndr :: TmOccName -> NormalizeSession Bool
-- | A call graph counts the number of occurrences that a functions
-- g is used in f.
type CallGraph = HashMap TmOccName (HashMap TmOccName Word)
-- | Create a call graph for a set of global binders, given a root
callGraph :: BindingMap -> TmOccName -> CallGraph
-- | Give a "performance/size" classification of a function in normal form.
classifyFunction :: Term -> TermClassification
-- | Determine whether a function adds a lot of hardware or not.
--
-- It is considered expensive when it has 2 or more of the following
-- components:
--
--
-- - functions
-- - primitives
-- - selections (multiplexers)
--
isCheapFunction :: Term -> Bool
-- | 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, [Declaration])
mkArgument :: Identifier -> Term -> NetlistMonad ((Expr, 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 (Identifier, [Declaration]), WireOrReg, [BlackBoxTemplate], [BlackBoxTemplate], Maybe ((Text, Text), BlackBoxTemplate), BlackBoxContext), [Declaration])
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 :: BindingMap -> [(TmName, Type, Maybe TopEntity, Maybe TmName)] -> PrimMap BlackBoxTemplate -> HashMap TyConOccName TyCon -> (HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)) -> [(String, FilePath)] -> Int -> (IdType -> Identifier -> Identifier) -> (IdType -> Identifier -> Identifier -> Identifier) -> [Identifier] -> FilePath -> TmOccName -> IO ([(SrcSpan, Component)], [(String, FilePath)], [Identifier])
-- | Run a NetlistMonad action in a given environment
runNetlistMonad :: BindingMap -> HashMap TmOccName (Type, Maybe TopEntity) -> PrimMap BlackBoxTemplate -> HashMap TyConOccName TyCon -> (HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)) -> [(String, FilePath)] -> Int -> (IdType -> Identifier -> Identifier) -> (IdType -> Identifier -> Identifier -> Identifier) -> [Identifier] -> FilePath -> NetlistMonad a -> IO (a, NetlistState)
genNames :: (IdType -> Identifier -> Identifier) -> [Identifier] -> HashMap TmOccName Identifier -> [TmName] -> ([Identifier], HashMap TmOccName Identifier)
-- | Generate a component for a given function (caching)
genComponent :: TmOccName -> NetlistMonad (SrcSpan, Component)
-- | Generate a component for a given function
genComponentT :: TmOccName -> Term -> NetlistMonad (SrcSpan, Component)
mkNetDecl :: (Id, Embed Term) -> NetlistMonad (Maybe Declaration)
-- | Generate a list of Declarations for a let-binder, return an empty list
-- if the bound expression is represented by 0 bits
mkDeclarations :: Id -> Term -> NetlistMonad [Declaration]
-- | Generate a list of Declarations for a let-binder
mkDeclarations' :: Id -> Term -> NetlistMonad [Declaration]
-- | Generate a declaration that selects an alternative based on the value
-- of the scrutinee
mkSelection :: Id -> Term -> Type -> [Alt] -> 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 that projects a field out of a
-- data-constructor.
--
-- Works for both product types, as sum-of-product types.
mkProjection :: Bool -> Either Identifier Id -> Term -> Type -> Alt -> 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])
-- | Reductions of primitives
--
-- Currently, it contains reductions for:
--
--
-- - Clash.Sized.Vector.map
-- - Clash.Sized.Vector.zipWith
-- - Clash.Sized.Vector.traverse#
-- - Clash.Sized.Vector.foldr
-- - Clash.Sized.Vector.fold
-- - Clash.Sized.Vector.dfold
-- - Clash.Sized.Vector.(++)
-- - Clash.Sized.Vector.head
-- - Clash.Sized.Vector.tail
-- - Clash.Sized.Vector.unconcatBitVector#
-- - Clash.Sized.Vector.replicate
-- - Clash.Sized.Vector.imap
-- - Clash.Sized.Vector.dtfold
-- - Clash.Sized.RTree.tfold
--
--
-- Partially handles:
--
--
-- - Clash.Sized.Vector.unconcat
-- - Clash.Sized.Vector.transpose
--
module Clash.Normalize.PrimitiveReductions
-- | Replace an application of the Clash.Sized.Vector.zipWith
-- primitive on vectors of a known length n, by the fully
-- unrolled recursive "definition" of Clash.Sized.Vector.zipWith
reduceZipWith :: Integer -> Type -> Type -> Type -> Term -> Term -> Term -> NormalizeSession Term
-- | Replace an application of the Clash.Sized.Vector.map
-- primitive on vectors of a known length n, by the fully
-- unrolled recursive "definition" of Clash.Sized.Vector.map
reduceMap :: Integer -> Type -> Type -> Term -> Term -> NormalizeSession Term
-- | Replace an application of the Clash.Sized.Vector.imap
-- primitive on vectors of a known length n, by the fully
-- unrolled recursive "definition" of Clash.Sized.Vector.imap
reduceImap :: Integer -> Type -> Type -> Term -> Term -> NormalizeSession Term
-- | Replace an application of the Clash.Sized.Vector.traverse#
-- primitive on vectors of a known length n, by the fully
-- unrolled recursive "definition" of
-- Clash.Sized.Vector.traverse#
reduceTraverse :: Integer -> Type -> Type -> Type -> Term -> Term -> Term -> NormalizeSession Term
-- | Create the traversable vector
--
-- e.g. for a length '2' input vector, we get
--
--
-- (:>) <$> 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
buildSNat :: DataCon -> Integer -> 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 TmOccName -> [(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 TmOccName -> (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)
-- | 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 (except clock or reset generators)
bindConstantVar :: NormRewrite
-- | Specialise functions on arguments which are constant, except when they
-- are clock or reset generators
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 work-free functions, i.e. fully applied functions that evaluate
-- to a constant
inlineWorkFree :: 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#
-- - Clash.Sized.Vector.foldr
-- - Clash.Sized.Vector.fold
-- - Clash.Sized.Vector.dfold
-- - Clash.Sized.Vector.(++)
-- - Clash.Sized.Vector.head
-- - Clash.Sized.Vector.tail
-- - Clash.Sized.Vector.unconcat
-- - Clash.Sized.Vector.transpose
-- - Clash.Sized.Vector.replicate
-- - Clash.Sized.Vector.dtfold
--
reduceNonRepPrim :: NormRewrite
-- | Flatten ridiculous case-statements generated by GHC
--
-- For case-statements in haskell of the form:
--
--
-- 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
-- | Given a function in the desired normal form, inline all the following
-- let-bindings:
--
-- Let-bindings with an internal name that is only used once, where it
-- binds: * a primitive that will be translated to an HDL expression (as
-- opposed to a HDL declaration) * a projection case-expression (1
-- alternative) * a data constructor
inlineCleanup :: NormRewrite
-- | Flatten's letrecs after inlineCleanup
--
-- inlineCleanup sometimes exposes additional possibilities for
-- caseCon, which then introduces let-bindings in what should be
-- ANF. This transformation flattens those nested let-bindings again.
--
-- NB: must only be called in the cleaning up phase.
flattenLet :: NormRewrite
-- | Make a cast work-free by splitting the work of to a separate binding
--
--
-- let x = cast (f a b)
-- ==>
-- let x = cast x'
-- x' = f a b
--
splitCastWork :: NormRewrite
-- | Only inline casts that just contain a Var, because these are
-- guaranteed work-free. These are the result of the splitCastWork
-- transformation.
inlineCast :: NormRewrite
-- | Push a cast over a case into it's alternatives.
caseCast :: NormRewrite
-- | Push a cast over a Letrec into it's body
letCast :: NormRewrite
-- | Eliminate two back to back casts where the type going in and coming
-- out are the same
--
--
-- (cast :: b -> a) $ (cast :: a -> b) x ==> x
--
eliminateCastCast :: NormRewrite
-- | Push cast over an argument to a funtion into that function
--
-- This is done by specializing on the casted argument. Example: y =
-- f (cast a) where f x = g x transforms to: y = f' a where f'
-- x' = (x -> g x) (cast x')
argCastSpec :: 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 -> BindingMap -> (HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)) -> HashMap TyConOccName TyCon -> IntMap TyConName -> PrimEvaluator -> PrimMap BlackBoxTemplate -> HashMap TmOccName Bool -> [TmOccName] -> NormalizeSession a -> a
normalize :: [TmOccName] -> NormalizeSession BindingMap
normalize' :: TmOccName -> NormalizeSession ([TmOccName], (TmOccName, (TmName, Type, SrcSpan, InlineSpec, Term)))
-- | Rewrite a term according to the provided transformation
rewriteExpr :: (String, NormRewrite) -> (String, Term) -> NormalizeSession Term
-- | Check whether the normalized bindings are non-recursive. Errors when
-- one of the components is recursive.
checkNonRecursive :: BindingMap -> BindingMap
-- | Perform general "clean up" of the normalized (non-recursive) function
-- hierarchy. This includes:
--
--
-- - Inlining functions that simply "wrap" another function
--
cleanupGraph :: TmOccName -> BindingMap -> NormalizeSession BindingMap
data CallTree
CLeaf :: (TmOccName, (TmName, Type, SrcSpan, InlineSpec, Term)) -> CallTree
CBranch :: (TmOccName, (TmName, Type, SrcSpan, InlineSpec, Term)) -> [CallTree] -> CallTree
mkCallTree :: [TmOccName] -> BindingMap -> TmOccName -> Maybe CallTree
stripArgs :: [TmOccName] -> [Id] -> [Either Term Type] -> Maybe [Either Term Type]
flattenNode :: CallTree -> NormalizeSession (Either CallTree ((TmOccName, Term), [CallTree]))
flattenCallTree :: CallTree -> NormalizeSession CallTree
callTreeToList :: [TmOccName] -> CallTree -> ([TmOccName], [(TmOccName, (TmName, Type, SrcSpan, InlineSpec, Term))])
-- | Clash's clock and reset domain annotations prevent most accidental
-- meta-stability situations. That is, unless the developer uses the
-- functions marked "unsafe", the type system will prevent things like
-- illegal clock domain crossing, or improper use of asynchronous resets.
--
-- However, this all depends on clock and resets being unique. With
-- explicit clocks and resets, it is possible to have multiple clock and
-- reset arguments that are annotated with the same domain. If these
-- arguments aren't connected to the same source, we can still get
-- metastability due to either illegal clock domain crossing, or improper
-- use of asynchronous resets.
--
-- The following situations are reported: * There are 2 or more clock
-- arguments in scope that have the same clock domain annotation. * There
-- are 2 or more reset arguments in scope that have the same reset domain
-- annotation, and at least one of them is an asynchronous reset.
clockResetErrors :: SrcSpan -> (HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)) -> HashMap TyConOccName TyCon -> Type -> [String]
-- | 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 :: forall backend. Backend backend => BindingMap -> Maybe backend -> PrimMap (Text) -> HashMap TyConOccName TyCon -> IntMap TyConName -> (HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)) -> PrimEvaluator -> [(TmName, Type, Maybe TopEntity, Maybe TmName)] -> ClashOpts -> (UTCTime, UTCTime) -> IO ()
parsePrimitive :: Primitive Text -> Primitive BlackBoxTemplate
-- | Pretty print Components to HDL Documents
createHDL :: Backend backend => backend -> String -> [(SrcSpan, Component)] -> Component -> (String, Either Manifest Manifest) -> ([(String, Doc)], Manifest)
-- | 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 :: Bool -> String -> String -> IO ()
-- | Writes a HDL file to the given directory
writeHDL :: FilePath -> (String, Doc) -> IO ()
copyDataFiles :: [FilePath] -> FilePath -> [(String, FilePath)] -> IO ()
-- | Get all the terms corresponding to a call graph
callGraphBindings :: BindingMap -> TmOccName -> [Term]
-- | Normalize a complete hierarchy
normalizeEntity :: BindingMap -> PrimMap BlackBoxTemplate -> HashMap TyConOccName TyCon -> IntMap TyConName -> (HashMap TyConOccName TyCon -> Bool -> Type -> Maybe (Either String HWType)) -> PrimEvaluator -> [TmOccName] -> ClashOpts -> Supply -> TmOccName -> BindingMap