clash-lib-1.3.0: CAES Language for Synchronous Hardware - As a Library
Copyright(C) 2012-2016 University of Twente
2017 Google Inc.
LicenseBSD2 (see the file LICENSE)
MaintainerChristiaan Baaij <christiaan.baaij@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Clash.Core.Term

Description

Term representation in the CoreHW language: System F + LetRec + Case

Synopsis

Documentation

data Term Source #

Term representation in the CoreHW language: System F + LetRec + Case

Constructors

Var !Id

Variable reference

Data !DataCon

Datatype constructor

Literal !Literal

Literal

Prim !PrimInfo

Primitive

Lam !Id Term

Term-abstraction

TyLam !TyVar Term

Type-abstraction

App !Term !Term

Application

TyApp !Term !Type

Type-application

Letrec [LetBinding] Term

Recursive let-binding

Case !Term !Type [Alt]

Case-expression: subject, type of alternatives, list of alternatives

Cast !Term !Type !Type

Cast a term from one type to another

Tick !TickInfo !Term

Annotated term

Instances

Instances details
Eq Term Source # 
Instance details

Defined in Clash.Core.Subst

Methods

(==) :: Term -> Term -> Bool #

(/=) :: Term -> Term -> Bool #

Ord Term Source # 
Instance details

Defined in Clash.Core.Subst

Methods

compare :: Term -> Term -> Ordering #

(<) :: Term -> Term -> Bool #

(<=) :: Term -> Term -> Bool #

(>) :: Term -> Term -> Bool #

(>=) :: Term -> Term -> Bool #

max :: Term -> Term -> Term #

min :: Term -> Term -> Term #

Show Term Source # 
Instance details

Defined in Clash.Core.Term

Methods

showsPrec :: Int -> Term -> ShowS #

show :: Term -> String #

showList :: [Term] -> ShowS #

Generic Term Source # 
Instance details

Defined in Clash.Core.Term

Associated Types

type Rep Term :: Type -> Type #

Methods

from :: Term -> Rep Term x #

to :: Rep Term x -> Term #

Hashable Term Source # 
Instance details

Defined in Clash.Core.Term

Methods

hashWithSalt :: Int -> Term -> Int #

hash :: Term -> Int #

Binary Term Source # 
Instance details

Defined in Clash.Core.Term

Methods

put :: Term -> Put #

get :: Get Term #

putList :: [Term] -> Put #

NFData Term Source # 
Instance details

Defined in Clash.Core.Term

Methods

rnf :: Term -> () #

ClashPretty Term Source # 
Instance details

Defined in Clash.Core.Pretty

Methods

clashPretty :: Term -> Doc () Source #

PrettyPrec Term Source # 
Instance details

Defined in Clash.Core.Pretty

TermLiteral Term Source # 
Instance details

Defined in Clash.Core.TermLiteral

PrettyPrec (Id, Term) Source # 
Instance details

Defined in Clash.Core.Pretty

type Rep Term Source # 
Instance details

Defined in Clash.Core.Term

type Rep Term = D1 ('MetaData "Term" "Clash.Core.Term" "clash-lib-1.3.0-inplace" 'False) (((C1 ('MetaCons "Var" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Id)) :+: (C1 ('MetaCons "Data" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 DataCon)) :+: C1 ('MetaCons "Literal" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Literal)))) :+: (C1 ('MetaCons "Prim" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 PrimInfo)) :+: (C1 ('MetaCons "Lam" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Id) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Term)) :+: C1 ('MetaCons "TyLam" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TyVar) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Term))))) :+: ((C1 ('MetaCons "App" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Term) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Term)) :+: (C1 ('MetaCons "TyApp" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Term) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Type)) :+: C1 ('MetaCons "Letrec" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [LetBinding]) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Term)))) :+: (C1 ('MetaCons "Case" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Term) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Type) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Alt]))) :+: (C1 ('MetaCons "Cast" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Term) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Type) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Type))) :+: C1 ('MetaCons "Tick" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 TickInfo) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Term))))))

mkAbstraction :: Term -> [Either Id TyVar] -> Term Source #

Abstract a term over a list of term and type variables

mkTyLams :: Term -> [TyVar] -> Term Source #

Abstract a term over a list of type variables

mkLams :: Term -> [Id] -> Term Source #

Abstract a term over a list of variables

mkApps :: Term -> [Either Term Type] -> Term Source #

Apply a list of types and terms to a term

mkTyApps :: Term -> [Type] -> Term Source #

Apply a list of types to a term

mkTmApps :: Term -> [Term] -> Term Source #

Apply a list of terms to a term

type TmName = Name Term Source #

Term reference

idToVar :: Id -> Term Source #

Make variable reference out of term variable

varToId :: Term -> Id Source #

Make a term variable out of a variable reference

type LetBinding = (Id, Term) Source #

Binding in a LetRec construct

data Pat Source #

Patterns in the LHS of a case-decomposition

Constructors

DataPat !DataCon [TyVar] [Id]

Datatype pattern, '[TyVar]' bind existentially-quantified type-variables of a DataCon

LitPat !Literal

Literal pattern

DefaultPat

Default pattern

Instances

Instances details
Eq Pat Source # 
Instance details

Defined in Clash.Core.Term

Methods

(==) :: Pat -> Pat -> Bool #

(/=) :: Pat -> Pat -> Bool #

Ord Pat Source # 
Instance details

Defined in Clash.Core.Term

Methods

compare :: Pat -> Pat -> Ordering #

(<) :: Pat -> Pat -> Bool #

(<=) :: Pat -> Pat -> Bool #

(>) :: Pat -> Pat -> Bool #

(>=) :: Pat -> Pat -> Bool #

max :: Pat -> Pat -> Pat #

min :: Pat -> Pat -> Pat #

Show Pat Source # 
Instance details

Defined in Clash.Core.Term

Methods

showsPrec :: Int -> Pat -> ShowS #

show :: Pat -> String #

showList :: [Pat] -> ShowS #

Generic Pat Source # 
Instance details

Defined in Clash.Core.Term

Associated Types

type Rep Pat :: Type -> Type #

Methods

from :: Pat -> Rep Pat x #

to :: Rep Pat x -> Pat #

Hashable Pat Source # 
Instance details

Defined in Clash.Core.Term

Methods

hashWithSalt :: Int -> Pat -> Int #

hash :: Pat -> Int #

Binary Pat Source # 
Instance details

Defined in Clash.Core.Term

Methods

put :: Pat -> Put #

get :: Get Pat #

putList :: [Pat] -> Put #

NFData Pat Source # 
Instance details

Defined in Clash.Core.Term

Methods

rnf :: Pat -> () #

PrettyPrec Pat Source # 
Instance details

Defined in Clash.Core.Pretty

type Rep Pat Source # 
Instance details

Defined in Clash.Core.Term

patIds :: Pat -> ([TyVar], [Id]) Source #

Get the list of term-binders out of a DataType pattern

patVars :: Pat -> [Var a] Source #

type Alt = (Pat, Term) Source #

data TickInfo Source #

Constructors

SrcSpan !SrcSpan

Source tick, will get added by GHC by running clash with `-g`

NameMod !NameMod !Type

Modifier for naming module instantiations and registers, are added by the user by using the functions Clash.Magic.[prefixName,suffixName,setName]

DeDup

Deduplicate, i.e. try to share expressions between multiple branches.

NoDeDup

Do not deduplicate, i.e. keep, an expression inside a case-alternative; do not try to share expressions between multiple branches.

Instances

Instances details
Eq TickInfo Source # 
Instance details

Defined in Clash.Core.Term

Show TickInfo Source # 
Instance details

Defined in Clash.Core.Term

Generic TickInfo Source # 
Instance details

Defined in Clash.Core.Term

Associated Types

type Rep TickInfo :: Type -> Type #

Methods

from :: TickInfo -> Rep TickInfo x #

to :: Rep TickInfo x -> TickInfo #

Hashable TickInfo Source # 
Instance details

Defined in Clash.Core.Term

Methods

hashWithSalt :: Int -> TickInfo -> Int #

hash :: TickInfo -> Int #

Binary TickInfo Source # 
Instance details

Defined in Clash.Core.Term

Methods

put :: TickInfo -> Put #

get :: Get TickInfo #

putList :: [TickInfo] -> Put #

NFData TickInfo Source # 
Instance details

Defined in Clash.Core.Term

Methods

rnf :: TickInfo -> () #

PrettyPrec TickInfo Source # 
Instance details

Defined in Clash.Core.Pretty

type Rep TickInfo Source # 
Instance details

Defined in Clash.Core.Term

partitionTicks Source #

Arguments

:: [TickInfo] 
-> ([TickInfo], [TickInfo])

(source ticks, nameMod ticks)

Partition ticks in source ticks and nameMod ticks

data NameMod Source #

Tag to indicate which instance/register name modifier was used

Constructors

PrefixName
Clash.Magic.prefixName
SuffixName
Clash.Magic.suffixName
SuffixNameP
Clash.Magic.suffixNameP
SetName
Clash.Magic.setName

Instances

Instances details
Eq NameMod Source # 
Instance details

Defined in Clash.Core.Term

Methods

(==) :: NameMod -> NameMod -> Bool #

(/=) :: NameMod -> NameMod -> Bool #

Show NameMod Source # 
Instance details

Defined in Clash.Core.Term

Generic NameMod Source # 
Instance details

Defined in Clash.Core.Term

Associated Types

type Rep NameMod :: Type -> Type #

Methods

from :: NameMod -> Rep NameMod x #

to :: Rep NameMod x -> NameMod #

Hashable NameMod Source # 
Instance details

Defined in Clash.Core.Term

Methods

hashWithSalt :: Int -> NameMod -> Int #

hash :: NameMod -> Int #

Binary NameMod Source # 
Instance details

Defined in Clash.Core.Term

Methods

put :: NameMod -> Put #

get :: Get NameMod #

putList :: [NameMod] -> Put #

NFData NameMod Source # 
Instance details

Defined in Clash.Core.Term

Methods

rnf :: NameMod -> () #

type Rep NameMod Source # 
Instance details

Defined in Clash.Core.Term

type Rep NameMod = D1 ('MetaData "NameMod" "Clash.Core.Term" "clash-lib-1.3.0-inplace" 'False) ((C1 ('MetaCons "PrefixName" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "SuffixName" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "SuffixNameP" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "SetName" 'PrefixI 'False) (U1 :: Type -> Type)))

data PrimInfo Source #

Constructors

PrimInfo 

Fields

Instances

Instances details
Show PrimInfo Source # 
Instance details

Defined in Clash.Core.Term

Generic PrimInfo Source # 
Instance details

Defined in Clash.Core.Term

Associated Types

type Rep PrimInfo :: Type -> Type #

Methods

from :: PrimInfo -> Rep PrimInfo x #

to :: Rep PrimInfo x -> PrimInfo #

Hashable PrimInfo Source # 
Instance details

Defined in Clash.Core.Term

Methods

hashWithSalt :: Int -> PrimInfo -> Int #

hash :: PrimInfo -> Int #

Binary PrimInfo Source # 
Instance details

Defined in Clash.Core.Term

Methods

put :: PrimInfo -> Put #

get :: Get PrimInfo #

putList :: [PrimInfo] -> Put #

NFData PrimInfo Source # 
Instance details

Defined in Clash.Core.Term

Methods

rnf :: PrimInfo -> () #

type Rep PrimInfo Source # 
Instance details

Defined in Clash.Core.Term

type Rep PrimInfo = D1 ('MetaData "PrimInfo" "Clash.Core.Term" "clash-lib-1.3.0-inplace" 'False) (C1 ('MetaCons "PrimInfo" 'PrefixI 'True) ((S1 ('MetaSel ('Just "primName") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Just "primType") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Type)) :*: (S1 ('MetaSel ('Just "primWorkInfo") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 WorkInfo) :*: S1 ('MetaSel ('Just "primMultiResult") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 IsMultiPrim))))

data IsMultiPrim Source #

Constructors

SingleResult 
MultiResult 

Instances

Instances details
Show IsMultiPrim Source # 
Instance details

Defined in Clash.Core.Term

Generic IsMultiPrim Source # 
Instance details

Defined in Clash.Core.Term

Associated Types

type Rep IsMultiPrim :: Type -> Type #

Hashable IsMultiPrim Source # 
Instance details

Defined in Clash.Core.Term

Binary IsMultiPrim Source # 
Instance details

Defined in Clash.Core.Term

NFData IsMultiPrim Source # 
Instance details

Defined in Clash.Core.Term

Methods

rnf :: IsMultiPrim -> () #

type Rep IsMultiPrim Source # 
Instance details

Defined in Clash.Core.Term

type Rep IsMultiPrim = D1 ('MetaData "IsMultiPrim" "Clash.Core.Term" "clash-lib-1.3.0-inplace" 'False) (C1 ('MetaCons "SingleResult" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "MultiResult" 'PrefixI 'False) (U1 :: Type -> Type))

data WorkInfo Source #

Constructors

WorkConstant

Ignores its arguments, and outputs a constant

WorkNever

Never adds any work

WorkVariable

Does work when the arguments are variable

WorkAlways

Performs work regardless of whether the variables are constant or variable; these are things like clock or reset generators

Instances

Instances details
Eq WorkInfo Source # 
Instance details

Defined in Clash.Core.Term

Show WorkInfo Source # 
Instance details

Defined in Clash.Core.Term

Generic WorkInfo Source # 
Instance details

Defined in Clash.Core.Term

Associated Types

type Rep WorkInfo :: Type -> Type #

Methods

from :: WorkInfo -> Rep WorkInfo x #

to :: Rep WorkInfo x -> WorkInfo #

Hashable WorkInfo Source # 
Instance details

Defined in Clash.Core.Term

Methods

hashWithSalt :: Int -> WorkInfo -> Int #

hash :: WorkInfo -> Int #

Binary WorkInfo Source # 
Instance details

Defined in Clash.Core.Term

Methods

put :: WorkInfo -> Put #

get :: Get WorkInfo #

putList :: [WorkInfo] -> Put #

NFData WorkInfo Source # 
Instance details

Defined in Clash.Core.Term

Methods

rnf :: WorkInfo -> () #

type Rep WorkInfo Source # 
Instance details

Defined in Clash.Core.Term

type Rep WorkInfo = D1 ('MetaData "WorkInfo" "Clash.Core.Term" "clash-lib-1.3.0-inplace" 'False) ((C1 ('MetaCons "WorkConstant" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "WorkNever" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "WorkVariable" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "WorkAlways" 'PrefixI 'False) (U1 :: Type -> Type)))

data CoreContext Source #

Context in which a term appears

Constructors

AppFun

Function position of an application

AppArg (Maybe (Text, Int, Int))

Argument position of an application. If this is an argument applied to a primitive, a tuple is defined containing (name of the primitive, #type args, #term args)

TyAppC

Function position of a type application

LetBinding Id [Id]

RHS of a Let-binder with the sibling LHS'

LetBody [Id]

Body of a Let-binding with the bound LHS'

LamBody Id

Body of a lambda-term with the abstracted variable

TyLamBody TyVar

Body of a TyLambda-term with the abstracted type-variable

CaseAlt Pat

RHS of a case-alternative with the bound pattern on the LHS

CaseScrut

Subject of a case-decomposition

CastBody

Body of a Cast

TickC TickInfo

Body of a Tick

Instances

Instances details
Eq CoreContext Source # 
Instance details

Defined in Clash.Core.Term

Show CoreContext Source # 
Instance details

Defined in Clash.Core.Term

Generic CoreContext Source # 
Instance details

Defined in Clash.Core.Term

Associated Types

type Rep CoreContext :: Type -> Type #

Hashable CoreContext Source # 
Instance details

Defined in Clash.Core.Term

Binary CoreContext Source # 
Instance details

Defined in Clash.Core.Term

NFData CoreContext Source # 
Instance details

Defined in Clash.Core.Term

Methods

rnf :: CoreContext -> () #

type Rep CoreContext Source # 
Instance details

Defined in Clash.Core.Term

type Rep CoreContext = D1 ('MetaData "CoreContext" "Clash.Core.Term" "clash-lib-1.3.0-inplace" 'False) (((C1 ('MetaCons "AppFun" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "AppArg" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (Text, Int, Int))))) :+: (C1 ('MetaCons "TyAppC" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "LetBinding" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Id) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Id])) :+: C1 ('MetaCons "LetBody" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Id]))))) :+: ((C1 ('MetaCons "LamBody" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Id)) :+: (C1 ('MetaCons "TyLamBody" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TyVar)) :+: C1 ('MetaCons "CaseAlt" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pat)))) :+: (C1 ('MetaCons "CaseScrut" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "CastBody" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "TickC" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TickInfo))))))

type Context = [CoreContext] Source #

A list of CoreContext describes the complete navigation path from the top-level to a specific sub-expression.

isLambdaBodyCtx :: CoreContext -> Bool Source #

Is the Context a Lambda/Term-abstraction context?

isTickCtx :: CoreContext -> Bool Source #

Is the Context a Tick context?

walkTerm :: forall a. (Term -> Maybe a) -> Term -> [a] Source #

Visit all terms in a term, testing it with a predicate, and returning a list of predicate yields.

collectArgs :: Term -> (Term, [Either Term Type]) Source #

Split a (Type)Application in the applied term and it arguments

collectBndrs :: Term -> ([Either Id TyVar], Term) Source #

Split a (Type)Abstraction in the bound variables and the abstracted term

primArg Source #

Arguments

:: Term

Function application

-> Maybe (Text, Int, Int)

If Term was a primitive: (name of primitive, term args)

Given a function application, find the primitive it's applied. Yields Nothing if given term is not an application or if it is not a primitive.