clash-lib-1.8.1: Clash: a functional hardware description language - As a library

Copyright | (C) 2012-2016 University of Twente 2016 Myrtle Software Ltd 2017 Google Inc. 2021-2022 QBayLogic B.V.
License | BSD2 (see the file LICENSE)
Maintainer | QBayLogic B.V. <devops@qbaylogic.com>
Safe Haskell | Safe-Inferred
Language | Haskell2010

Clash.Rewrite.Types

Description

Type and instance definitions for Rewrite modules

Synopsis

- data RewriteStep = RewriteStep {
  - t_ctx :: Context
  - t_name :: String
  - t_bndrS :: String
  - t_before :: Term
  - t_after :: Term
  }
- data RewriteState extra = RewriteState {
  - _transformCounter :: !Word
  - _transformCounters :: HashMap Text Word
  - _bindings :: !BindingMap
  - _uniqSupply :: !Supply
  - _curFun :: (Id, SrcSpan)
  - _nameCounter :: !Int
  - _globalHeap :: PrimHeap
  - _workFreeBinders :: VarEnv Bool
  - _extra :: !extra
  }
- workFreeBinders :: forall extra. Lens' (RewriteState extra) (VarEnv Bool)
- uniqSupply :: forall extra. Lens' (RewriteState extra) Supply
- transformCounters :: forall extra. Lens' (RewriteState extra) (HashMap Text Word)
- transformCounter :: forall extra. Lens' (RewriteState extra) Word
- nameCounter :: forall extra. Lens' (RewriteState extra) Int
- globalHeap :: forall extra. Lens' (RewriteState extra) PrimHeap
- extra :: forall extra extra. Lens (RewriteState extra) (RewriteState extra) extra extra
- curFun :: forall extra. Lens' (RewriteState extra) (Id, SrcSpan)
- bindings :: forall extra. Lens' (RewriteState extra) BindingMap
- data RewriteEnv = RewriteEnv {
  - _clashEnv :: ClashEnv
  - _typeTranslator :: CustomReprs -> TyConMap -> Type -> State HWMap (Maybe (Either String FilteredHWType))
  - _peEvaluator :: Evaluator
  - _evaluator :: Evaluator
  - _topEntities :: VarSet
  }
- typeTranslator :: Lens' RewriteEnv (CustomReprs -> TyConMap -> Type -> State HWMap (Maybe (Either String FilteredHWType)))
- topEntities :: Lens' RewriteEnv VarSet
- peEvaluator :: Lens' RewriteEnv Evaluator
- evaluator :: Lens' RewriteEnv Evaluator
- clashEnv :: Lens' RewriteEnv ClashEnv
- debugOpts :: Getter RewriteEnv DebugOpts
- aggressiveXOpt :: Getter RewriteEnv Bool
- tcCache :: Getter RewriteEnv TyConMap
- tupleTcCache :: Getter RewriteEnv (IntMap TyConName)
- customReprs :: Getter RewriteEnv CustomReprs
- fuelLimit :: Getter RewriteEnv Word
- primitives :: Getter RewriteEnv CompiledPrimMap
- inlineLimit :: Getter RewriteEnv Int
- inlineFunctionLimit :: Getter RewriteEnv Word
- inlineConstantLimit :: Getter RewriteEnv Word
- inlineWFCacheLimit :: Getter RewriteEnv Word
- newInlineStrategy :: Getter RewriteEnv Bool
- specializationLimit :: Getter RewriteEnv Int
- normalizeUltra :: Getter RewriteEnv Bool
- newtype RewriteMonad extra a = R {
  - unR :: RWST RewriteEnv Any (RewriteState extra) IO a
  }
- runR :: RewriteMonad extra a -> RewriteEnv -> RewriteState extra -> IO (a, RewriteState extra, Any)
- censor :: (Any -> Any) -> RewriteMonad extra a -> RewriteMonad extra a
- data TransformContext = TransformContext {
  - tfInScope :: !InScopeSet
  - tfContext :: Context
  }
- type Transform m = TransformContext -> Term -> m Term
- type Rewrite extra = Transform (RewriteMonad extra)

# Documentation

data RewriteStep Source #

State used by the inspection mechanism for recording rewrite steps.

Constructors

RewriteStep |

Fields

- t_ctx :: Context

  current context

- t_name :: String

  Name of the transformation

- t_bndrS :: String

  Name of the current binder

- t_before :: Term

  Term before `apply`

- t_after :: Term

  Term after `apply`

#### Instances

Instances details

Generic RewriteStep Source # |
Instance details Defined in Clash.Rewrite.Types Associated Types type Rep RewriteStep :: Type -> Type Source # Methods from :: RewriteStep -> Rep RewriteStep x Source # to :: Rep RewriteStep x -> RewriteStep Source #
Show RewriteStep Source # |
Instance details Defined in Clash.Rewrite.Types Methods showsPrec :: Int -> RewriteStep -> ShowS Source # show :: RewriteStep -> String Source # showList :: [RewriteStep] -> ShowS Source #
Binary RewriteStep Source # |
Instance details Defined in Clash.Rewrite.Types Methods put :: RewriteStep -> Put Source # get :: Get RewriteStep Source # putList :: [RewriteStep] -> Put Source #
NFData RewriteStep Source # |
Instance details Defined in Clash.Rewrite.Types Methods rnf :: RewriteStep -> () Source #
type Rep RewriteStep Source # |

Instance details

Defined in Clash.Rewrite.Types

type Rep RewriteStep = D1 ('MetaData "RewriteStep" "Clash.Rewrite.Types" "clash-lib-1.8.1-2YrsOtauO5B4MB9KvGiYOL" 'False) (C1 ('MetaCons "RewriteStep" 'PrefixI 'True) ((S1 ('MetaSel ('Just "t_ctx") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Context) :*: S1 ('MetaSel ('Just "t_name") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)) :*: (S1 ('MetaSel ('Just "t_bndrS") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: (S1 ('MetaSel ('Just "t_before") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Term) :*: S1 ('MetaSel ('Just "t_after") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Term)))))

data RewriteState extra Source #

State of a rewriting session

Constructors

RewriteState |

Fields

- _transformCounter :: !Word

  Total number of applied transformations

- _transformCounters :: HashMap Text Word

  Map that tracks how many times each transformation is applied

- _bindings :: !BindingMap

  Global binders

- _uniqSupply :: !Supply

  Supply of unique numbers

- _curFun :: (Id, SrcSpan)

  Function which is currently normalized

- _nameCounter :: !Int

  Used for `Fresh`

- _globalHeap :: PrimHeap

  Used as a heap for compile-time evaluation of primitives that live in I/O

- _workFreeBinders :: VarEnv Bool

  Map telling whether a binder's definition is work-free

- _extra :: !extra

  Additional state

#### Instances

Instances details

MonadState (RewriteState extra) (RewriteMonad extra) Source # |
Instance details Defined in Clash.Rewrite.Types Methods get :: RewriteMonad extra (RewriteState extra) Source # put :: RewriteState extra -> RewriteMonad extra () Source # state :: (RewriteState extra -> (a, RewriteState extra)) -> RewriteMonad extra a Source #

workFreeBinders :: forall extra. Lens' (RewriteState extra) (VarEnv Bool) Source #

uniqSupply :: forall extra. Lens' (RewriteState extra) Supply Source #

transformCounters :: forall extra. Lens' (RewriteState extra) (HashMap Text Word) Source #

transformCounter :: forall extra. Lens' (RewriteState extra) Word Source #

nameCounter :: forall extra. Lens' (RewriteState extra) Int Source #

globalHeap :: forall extra. Lens' (RewriteState extra) PrimHeap Source #

extra :: forall extra extra. Lens (RewriteState extra) (RewriteState extra) extra extra Source #

curFun :: forall extra. Lens' (RewriteState extra) (Id, SrcSpan) Source #

bindings :: forall extra. Lens' (RewriteState extra) BindingMap Source #

data RewriteEnv Source #

Read-only environment of a rewriting session

Constructors

RewriteEnv |

Fields

- _clashEnv :: ClashEnv

  The global environment of the compiler

- _typeTranslator :: CustomReprs -> TyConMap -> Type -> State HWMap (Maybe (Either String FilteredHWType))

  Hardcode Type -> FilteredHWType translator

- _peEvaluator :: Evaluator

  Hardcoded evaluator for partial evaluation

- _evaluator :: Evaluator

  Hardcoded evaluator for WHNF (old evaluator)

- _topEntities :: VarSet

  Functions that are considered TopEntities

#### Instances

Instances details

MonadReader RewriteEnv (RewriteMonad extra) Source # |
Instance details Defined in Clash.Rewrite.Types Methods ask :: RewriteMonad extra RewriteEnv Source # local :: (RewriteEnv -> RewriteEnv) -> RewriteMonad extra a -> RewriteMonad extra a Source # reader :: (RewriteEnv -> a) -> RewriteMonad extra a Source #

typeTranslator :: Lens' RewriteEnv (CustomReprs -> TyConMap -> Type -> State HWMap (Maybe (Either String FilteredHWType))) Source #

topEntities :: Lens' RewriteEnv VarSet Source #

peEvaluator :: Lens' RewriteEnv Evaluator Source #

evaluator :: Lens' RewriteEnv Evaluator Source #

clashEnv :: Lens' RewriteEnv ClashEnv Source #

debugOpts :: Getter RewriteEnv DebugOpts Source #

aggressiveXOpt :: Getter RewriteEnv Bool Source #

tcCache :: Getter RewriteEnv TyConMap Source #

tupleTcCache :: Getter RewriteEnv (IntMap TyConName) Source #

customReprs :: Getter RewriteEnv CustomReprs Source #

fuelLimit :: Getter RewriteEnv Word Source #

primitives :: Getter RewriteEnv CompiledPrimMap Source #

inlineLimit :: Getter RewriteEnv Int Source #

inlineFunctionLimit :: Getter RewriteEnv Word Source #

inlineConstantLimit :: Getter RewriteEnv Word Source #

inlineWFCacheLimit :: Getter RewriteEnv Word Source #

newInlineStrategy :: Getter RewriteEnv Bool Source #

specializationLimit :: Getter RewriteEnv Int Source #

normalizeUltra :: Getter RewriteEnv Bool Source #

newtype RewriteMonad extra a Source #

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.

Constructors

R |

Fields

- unR :: RWST RewriteEnv Any (RewriteState extra) IO a

#### Instances

Instances details

MonadReader RewriteEnv (RewriteMonad extra) Source # |
Instance details Defined in Clash.Rewrite.Types Methods ask :: RewriteMonad extra RewriteEnv Source # local :: (RewriteEnv -> RewriteEnv) -> RewriteMonad extra a -> RewriteMonad extra a Source # reader :: (RewriteEnv -> a) -> RewriteMonad extra a Source #
MonadWriter Any (RewriteMonad extra) Source # |
Instance details Defined in Clash.Rewrite.Types Methods writer :: (a, Any) -> RewriteMonad extra a Source # tell :: Any -> RewriteMonad extra () Source # listen :: RewriteMonad extra a -> RewriteMonad extra (a, Any) Source # pass :: RewriteMonad extra (a, Any -> Any) -> RewriteMonad extra a Source #
MonadFix (RewriteMonad extra) Source # |
Instance details Defined in Clash.Rewrite.Types Methods mfix :: (a -> RewriteMonad extra a) -> RewriteMonad extra a Source #
Applicative (RewriteMonad extra) Source # |

Instance details

Defined in Clash.Rewrite.Types

Methods

pure :: a -> RewriteMonad extra a Source #

(<*>) :: RewriteMonad extra (a -> b) -> RewriteMonad extra a -> RewriteMonad extra b Source #

liftA2 :: (a -> b -> c) -> RewriteMonad extra a -> RewriteMonad extra b -> RewriteMonad extra c Source #

(*>) :: RewriteMonad extra a -> RewriteMonad extra b -> RewriteMonad extra b Source #

(<*) :: RewriteMonad extra a -> RewriteMonad extra b -> RewriteMonad extra a Source #

Functor (RewriteMonad extra) Source # |
Instance details Defined in Clash.Rewrite.Types Methods fmap :: (a -> b) -> RewriteMonad extra a -> RewriteMonad extra b Source # (<$) :: a -> RewriteMonad extra b -> RewriteMonad extra a Source #
Monad (RewriteMonad extra) Source # |
Instance details Defined in Clash.Rewrite.Types Methods (>>=) :: RewriteMonad extra a -> (a -> RewriteMonad extra b) -> RewriteMonad extra b Source # (>>) :: RewriteMonad extra a -> RewriteMonad extra b -> RewriteMonad extra b Source # return :: a -> RewriteMonad extra a Source #
MonadUnique (RewriteMonad extra) Source # |
Instance details Defined in Clash.Rewrite.Types Methods getUniqueM :: RewriteMonad extra Int Source #
MonadState (RewriteState extra) (RewriteMonad extra) Source # |
Instance details Defined in Clash.Rewrite.Types Methods get :: RewriteMonad extra (RewriteState extra) Source # put :: RewriteState extra -> RewriteMonad extra () Source # state :: (RewriteState extra -> (a, RewriteState extra)) -> RewriteMonad extra a Source #

runR :: RewriteMonad extra a -> RewriteEnv -> RewriteState extra -> IO (a, RewriteState extra, Any) Source #

Run the computation in the RewriteMonad

censor :: (Any -> Any) -> RewriteMonad extra a -> RewriteMonad extra a Source #

data TransformContext Source #

Constructors

TransformContext |

Fields

- tfInScope :: !InScopeSet
- tfContext :: Context

type Transform m = TransformContext -> Term -> m Term Source #

Monadic action that transforms a term given a certain context

type Rewrite extra = Transform (RewriteMonad extra) Source #

A `Transform` action in the context of the `RewriteMonad`