{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
module Clash.Netlist.Types
( Declaration (..,NetDecl)
, module Clash.Netlist.Types
)
where
import Control.DeepSeq
import qualified Control.Lens as Lens
import Control.Lens (Lens', (.=))
#if !MIN_VERSION_base(4,13,0)
import Control.Monad.Fail (MonadFail)
#endif
import Control.Monad.Reader (ReaderT, MonadReader)
import qualified Control.Monad.State as Lazy (State)
import qualified Control.Monad.State.Strict as Strict
(State, MonadIO, MonadState, StateT)
import Data.Bits (testBit)
import Data.Binary (Binary(..))
import Data.Function (on)
import Data.Hashable (Hashable(hash,hashWithSalt))
import Data.HashMap.Strict (HashMap)
import Data.HashSet (HashSet)
import qualified Data.List as List
import Data.IntMap (IntMap, empty)
import Data.Map.Ordered (OMap)
import Data.Map (Map)
import Data.Maybe (mapMaybe)
import Data.Monoid (Ap(..))
import qualified Data.Set as Set
import Data.Text (Text)
import Data.Typeable (Typeable)
import Data.Text.Prettyprint.Doc.Extra (Doc)
import GHC.Generics (Generic)
import GHC.Stack
import Language.Haskell.TH.Syntax (Lift)
#if MIN_VERSION_ghc(9,0,0)
import GHC.Types.SrcLoc (SrcSpan)
#else
import SrcLoc (SrcSpan)
#endif
import Clash.Annotations.BitRepresentation (FieldAnn)
import Clash.Annotations.Primitive (HDL(..))
import Clash.Annotations.TopEntity (TopEntity)
import Clash.Backend (Backend)
import Clash.Core.HasType
import Clash.Core.Type (Type)
import Clash.Core.Var (Attr', Id)
import Clash.Core.TyCon (TyConMap)
import Clash.Core.VarEnv (VarEnv)
import Clash.Driver.Types (BindingMap, ClashEnv(..), ClashOpts(..))
import Clash.Netlist.BlackBox.Types (BlackBoxTemplate)
import Clash.Primitives.Types (CompiledPrimMap)
import Clash.Signal.Internal
(ResetPolarity, ActiveEdge, ResetKind, InitBehavior)
import Clash.Unique (Unique)
import Clash.Annotations.BitRepresentation.Internal
(CustomReprs, DataRepr', ConstrRepr')
import {-# SOURCE #-} qualified Clash.Netlist.Id as Id
data TopEntityT = TopEntityT
{ TopEntityT -> Id
topId :: Id
, TopEntityT -> Maybe TopEntity
topAnnotation :: Maybe TopEntity
, TopEntityT -> Bool
topIsTestBench :: Bool
} deriving ((forall x. TopEntityT -> Rep TopEntityT x)
-> (forall x. Rep TopEntityT x -> TopEntityT) -> Generic TopEntityT
forall x. Rep TopEntityT x -> TopEntityT
forall x. TopEntityT -> Rep TopEntityT x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TopEntityT x -> TopEntityT
$cfrom :: forall x. TopEntityT -> Rep TopEntityT x
Generic, BBHash -> TopEntityT -> ShowS
[TopEntityT] -> ShowS
TopEntityT -> BBName
(BBHash -> TopEntityT -> ShowS)
-> (TopEntityT -> BBName)
-> ([TopEntityT] -> ShowS)
-> Show TopEntityT
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [TopEntityT] -> ShowS
$cshowList :: [TopEntityT] -> ShowS
show :: TopEntityT -> BBName
$cshow :: TopEntityT -> BBName
showsPrec :: BBHash -> TopEntityT -> ShowS
$cshowsPrec :: BBHash -> TopEntityT -> ShowS
Show, TopEntityT -> TopEntityT -> Bool
(TopEntityT -> TopEntityT -> Bool)
-> (TopEntityT -> TopEntityT -> Bool) -> Eq TopEntityT
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TopEntityT -> TopEntityT -> Bool
$c/= :: TopEntityT -> TopEntityT -> Bool
== :: TopEntityT -> TopEntityT -> Bool
$c== :: TopEntityT -> TopEntityT -> Bool
Eq)
data ExpandedTopEntity a = ExpandedTopEntity
{ forall a. ExpandedTopEntity a -> [Maybe (ExpandedPortName a)]
et_inputs :: [Maybe (ExpandedPortName a)]
, forall a. ExpandedTopEntity a -> Maybe (ExpandedPortName a)
et_output :: Maybe (ExpandedPortName a)
} deriving (BBHash -> ExpandedTopEntity a -> ShowS
[ExpandedTopEntity a] -> ShowS
ExpandedTopEntity a -> BBName
(BBHash -> ExpandedTopEntity a -> ShowS)
-> (ExpandedTopEntity a -> BBName)
-> ([ExpandedTopEntity a] -> ShowS)
-> Show (ExpandedTopEntity a)
forall a. Show a => BBHash -> ExpandedTopEntity a -> ShowS
forall a. Show a => [ExpandedTopEntity a] -> ShowS
forall a. Show a => ExpandedTopEntity a -> BBName
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [ExpandedTopEntity a] -> ShowS
$cshowList :: forall a. Show a => [ExpandedTopEntity a] -> ShowS
show :: ExpandedTopEntity a -> BBName
$cshow :: forall a. Show a => ExpandedTopEntity a -> BBName
showsPrec :: BBHash -> ExpandedTopEntity a -> ShowS
$cshowsPrec :: forall a. Show a => BBHash -> ExpandedTopEntity a -> ShowS
Show, (forall a b.
(a -> b) -> ExpandedTopEntity a -> ExpandedTopEntity b)
-> (forall a b. a -> ExpandedTopEntity b -> ExpandedTopEntity a)
-> Functor ExpandedTopEntity
forall a b. a -> ExpandedTopEntity b -> ExpandedTopEntity a
forall a b. (a -> b) -> ExpandedTopEntity a -> ExpandedTopEntity b
forall (f :: Type -> Type).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> ExpandedTopEntity b -> ExpandedTopEntity a
$c<$ :: forall a b. a -> ExpandedTopEntity b -> ExpandedTopEntity a
fmap :: forall a b. (a -> b) -> ExpandedTopEntity a -> ExpandedTopEntity b
$cfmap :: forall a b. (a -> b) -> ExpandedTopEntity a -> ExpandedTopEntity b
Functor, (forall m. Monoid m => ExpandedTopEntity m -> m)
-> (forall m a. Monoid m => (a -> m) -> ExpandedTopEntity a -> m)
-> (forall m a. Monoid m => (a -> m) -> ExpandedTopEntity a -> m)
-> (forall a b. (a -> b -> b) -> b -> ExpandedTopEntity a -> b)
-> (forall a b. (a -> b -> b) -> b -> ExpandedTopEntity a -> b)
-> (forall b a. (b -> a -> b) -> b -> ExpandedTopEntity a -> b)
-> (forall b a. (b -> a -> b) -> b -> ExpandedTopEntity a -> b)
-> (forall a. (a -> a -> a) -> ExpandedTopEntity a -> a)
-> (forall a. (a -> a -> a) -> ExpandedTopEntity a -> a)
-> (forall a. ExpandedTopEntity a -> [a])
-> (forall a. ExpandedTopEntity a -> Bool)
-> (forall a. ExpandedTopEntity a -> BBHash)
-> (forall a. Eq a => a -> ExpandedTopEntity a -> Bool)
-> (forall a. Ord a => ExpandedTopEntity a -> a)
-> (forall a. Ord a => ExpandedTopEntity a -> a)
-> (forall a. Num a => ExpandedTopEntity a -> a)
-> (forall a. Num a => ExpandedTopEntity a -> a)
-> Foldable ExpandedTopEntity
forall a. Eq a => a -> ExpandedTopEntity a -> Bool
forall a. Num a => ExpandedTopEntity a -> a
forall a. Ord a => ExpandedTopEntity a -> a
forall m. Monoid m => ExpandedTopEntity m -> m
forall a. ExpandedTopEntity a -> Bool
forall a. ExpandedTopEntity a -> BBHash
forall a. ExpandedTopEntity a -> [a]
forall a. (a -> a -> a) -> ExpandedTopEntity a -> a
forall m a. Monoid m => (a -> m) -> ExpandedTopEntity a -> m
forall b a. (b -> a -> b) -> b -> ExpandedTopEntity a -> b
forall a b. (a -> b -> b) -> b -> ExpandedTopEntity a -> b
forall (t :: Type -> Type).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> BBHash)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => ExpandedTopEntity a -> a
$cproduct :: forall a. Num a => ExpandedTopEntity a -> a
sum :: forall a. Num a => ExpandedTopEntity a -> a
$csum :: forall a. Num a => ExpandedTopEntity a -> a
minimum :: forall a. Ord a => ExpandedTopEntity a -> a
$cminimum :: forall a. Ord a => ExpandedTopEntity a -> a
maximum :: forall a. Ord a => ExpandedTopEntity a -> a
$cmaximum :: forall a. Ord a => ExpandedTopEntity a -> a
elem :: forall a. Eq a => a -> ExpandedTopEntity a -> Bool
$celem :: forall a. Eq a => a -> ExpandedTopEntity a -> Bool
length :: forall a. ExpandedTopEntity a -> BBHash
$clength :: forall a. ExpandedTopEntity a -> BBHash
null :: forall a. ExpandedTopEntity a -> Bool
$cnull :: forall a. ExpandedTopEntity a -> Bool
toList :: forall a. ExpandedTopEntity a -> [a]
$ctoList :: forall a. ExpandedTopEntity a -> [a]
foldl1 :: forall a. (a -> a -> a) -> ExpandedTopEntity a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> ExpandedTopEntity a -> a
foldr1 :: forall a. (a -> a -> a) -> ExpandedTopEntity a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> ExpandedTopEntity a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> ExpandedTopEntity a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> ExpandedTopEntity a -> b
foldl :: forall b a. (b -> a -> b) -> b -> ExpandedTopEntity a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> ExpandedTopEntity a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> ExpandedTopEntity a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> ExpandedTopEntity a -> b
foldr :: forall a b. (a -> b -> b) -> b -> ExpandedTopEntity a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> ExpandedTopEntity a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> ExpandedTopEntity a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> ExpandedTopEntity a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> ExpandedTopEntity a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> ExpandedTopEntity a -> m
fold :: forall m. Monoid m => ExpandedTopEntity m -> m
$cfold :: forall m. Monoid m => ExpandedTopEntity m -> m
Foldable, Functor ExpandedTopEntity
Foldable ExpandedTopEntity
Functor ExpandedTopEntity
-> Foldable ExpandedTopEntity
-> (forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> ExpandedTopEntity a -> f (ExpandedTopEntity b))
-> (forall (f :: Type -> Type) a.
Applicative f =>
ExpandedTopEntity (f a) -> f (ExpandedTopEntity a))
-> (forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> ExpandedTopEntity a -> m (ExpandedTopEntity b))
-> (forall (m :: Type -> Type) a.
Monad m =>
ExpandedTopEntity (m a) -> m (ExpandedTopEntity a))
-> Traversable ExpandedTopEntity
forall (t :: Type -> Type).
Functor t
-> Foldable t
-> (forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: Type -> Type) a.
Applicative f =>
t (f a) -> f (t a))
-> (forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: Type -> Type) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: Type -> Type) a.
Monad m =>
ExpandedTopEntity (m a) -> m (ExpandedTopEntity a)
forall (f :: Type -> Type) a.
Applicative f =>
ExpandedTopEntity (f a) -> f (ExpandedTopEntity a)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> ExpandedTopEntity a -> m (ExpandedTopEntity b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> ExpandedTopEntity a -> f (ExpandedTopEntity b)
sequence :: forall (m :: Type -> Type) a.
Monad m =>
ExpandedTopEntity (m a) -> m (ExpandedTopEntity a)
$csequence :: forall (m :: Type -> Type) a.
Monad m =>
ExpandedTopEntity (m a) -> m (ExpandedTopEntity a)
mapM :: forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> ExpandedTopEntity a -> m (ExpandedTopEntity b)
$cmapM :: forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> ExpandedTopEntity a -> m (ExpandedTopEntity b)
sequenceA :: forall (f :: Type -> Type) a.
Applicative f =>
ExpandedTopEntity (f a) -> f (ExpandedTopEntity a)
$csequenceA :: forall (f :: Type -> Type) a.
Applicative f =>
ExpandedTopEntity (f a) -> f (ExpandedTopEntity a)
traverse :: forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> ExpandedTopEntity a -> f (ExpandedTopEntity b)
$ctraverse :: forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> ExpandedTopEntity a -> f (ExpandedTopEntity b)
Traversable)
data ExpandedPortName a
= ExpandedPortName HWType a
| ExpandedPortProduct
Text
HWType
[ExpandedPortName a]
deriving (BBHash -> ExpandedPortName a -> ShowS
[ExpandedPortName a] -> ShowS
ExpandedPortName a -> BBName
(BBHash -> ExpandedPortName a -> ShowS)
-> (ExpandedPortName a -> BBName)
-> ([ExpandedPortName a] -> ShowS)
-> Show (ExpandedPortName a)
forall a. Show a => BBHash -> ExpandedPortName a -> ShowS
forall a. Show a => [ExpandedPortName a] -> ShowS
forall a. Show a => ExpandedPortName a -> BBName
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [ExpandedPortName a] -> ShowS
$cshowList :: forall a. Show a => [ExpandedPortName a] -> ShowS
show :: ExpandedPortName a -> BBName
$cshow :: forall a. Show a => ExpandedPortName a -> BBName
showsPrec :: BBHash -> ExpandedPortName a -> ShowS
$cshowsPrec :: forall a. Show a => BBHash -> ExpandedPortName a -> ShowS
Show, (forall a b. (a -> b) -> ExpandedPortName a -> ExpandedPortName b)
-> (forall a b. a -> ExpandedPortName b -> ExpandedPortName a)
-> Functor ExpandedPortName
forall a b. a -> ExpandedPortName b -> ExpandedPortName a
forall a b. (a -> b) -> ExpandedPortName a -> ExpandedPortName b
forall (f :: Type -> Type).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> ExpandedPortName b -> ExpandedPortName a
$c<$ :: forall a b. a -> ExpandedPortName b -> ExpandedPortName a
fmap :: forall a b. (a -> b) -> ExpandedPortName a -> ExpandedPortName b
$cfmap :: forall a b. (a -> b) -> ExpandedPortName a -> ExpandedPortName b
Functor, (forall m. Monoid m => ExpandedPortName m -> m)
-> (forall m a. Monoid m => (a -> m) -> ExpandedPortName a -> m)
-> (forall m a. Monoid m => (a -> m) -> ExpandedPortName a -> m)
-> (forall a b. (a -> b -> b) -> b -> ExpandedPortName a -> b)
-> (forall a b. (a -> b -> b) -> b -> ExpandedPortName a -> b)
-> (forall b a. (b -> a -> b) -> b -> ExpandedPortName a -> b)
-> (forall b a. (b -> a -> b) -> b -> ExpandedPortName a -> b)
-> (forall a. (a -> a -> a) -> ExpandedPortName a -> a)
-> (forall a. (a -> a -> a) -> ExpandedPortName a -> a)
-> (forall a. ExpandedPortName a -> [a])
-> (forall a. ExpandedPortName a -> Bool)
-> (forall a. ExpandedPortName a -> BBHash)
-> (forall a. Eq a => a -> ExpandedPortName a -> Bool)
-> (forall a. Ord a => ExpandedPortName a -> a)
-> (forall a. Ord a => ExpandedPortName a -> a)
-> (forall a. Num a => ExpandedPortName a -> a)
-> (forall a. Num a => ExpandedPortName a -> a)
-> Foldable ExpandedPortName
forall a. Eq a => a -> ExpandedPortName a -> Bool
forall a. Num a => ExpandedPortName a -> a
forall a. Ord a => ExpandedPortName a -> a
forall m. Monoid m => ExpandedPortName m -> m
forall a. ExpandedPortName a -> Bool
forall a. ExpandedPortName a -> BBHash
forall a. ExpandedPortName a -> [a]
forall a. (a -> a -> a) -> ExpandedPortName a -> a
forall m a. Monoid m => (a -> m) -> ExpandedPortName a -> m
forall b a. (b -> a -> b) -> b -> ExpandedPortName a -> b
forall a b. (a -> b -> b) -> b -> ExpandedPortName a -> b
forall (t :: Type -> Type).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> BBHash)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => ExpandedPortName a -> a
$cproduct :: forall a. Num a => ExpandedPortName a -> a
sum :: forall a. Num a => ExpandedPortName a -> a
$csum :: forall a. Num a => ExpandedPortName a -> a
minimum :: forall a. Ord a => ExpandedPortName a -> a
$cminimum :: forall a. Ord a => ExpandedPortName a -> a
maximum :: forall a. Ord a => ExpandedPortName a -> a
$cmaximum :: forall a. Ord a => ExpandedPortName a -> a
elem :: forall a. Eq a => a -> ExpandedPortName a -> Bool
$celem :: forall a. Eq a => a -> ExpandedPortName a -> Bool
length :: forall a. ExpandedPortName a -> BBHash
$clength :: forall a. ExpandedPortName a -> BBHash
null :: forall a. ExpandedPortName a -> Bool
$cnull :: forall a. ExpandedPortName a -> Bool
toList :: forall a. ExpandedPortName a -> [a]
$ctoList :: forall a. ExpandedPortName a -> [a]
foldl1 :: forall a. (a -> a -> a) -> ExpandedPortName a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> ExpandedPortName a -> a
foldr1 :: forall a. (a -> a -> a) -> ExpandedPortName a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> ExpandedPortName a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> ExpandedPortName a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> ExpandedPortName a -> b
foldl :: forall b a. (b -> a -> b) -> b -> ExpandedPortName a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> ExpandedPortName a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> ExpandedPortName a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> ExpandedPortName a -> b
foldr :: forall a b. (a -> b -> b) -> b -> ExpandedPortName a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> ExpandedPortName a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> ExpandedPortName a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> ExpandedPortName a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> ExpandedPortName a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> ExpandedPortName a -> m
fold :: forall m. Monoid m => ExpandedPortName m -> m
$cfold :: forall m. Monoid m => ExpandedPortName m -> m
Foldable, Functor ExpandedPortName
Foldable ExpandedPortName
Functor ExpandedPortName
-> Foldable ExpandedPortName
-> (forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> ExpandedPortName a -> f (ExpandedPortName b))
-> (forall (f :: Type -> Type) a.
Applicative f =>
ExpandedPortName (f a) -> f (ExpandedPortName a))
-> (forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> ExpandedPortName a -> m (ExpandedPortName b))
-> (forall (m :: Type -> Type) a.
Monad m =>
ExpandedPortName (m a) -> m (ExpandedPortName a))
-> Traversable ExpandedPortName
forall (t :: Type -> Type).
Functor t
-> Foldable t
-> (forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: Type -> Type) a.
Applicative f =>
t (f a) -> f (t a))
-> (forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: Type -> Type) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: Type -> Type) a.
Monad m =>
ExpandedPortName (m a) -> m (ExpandedPortName a)
forall (f :: Type -> Type) a.
Applicative f =>
ExpandedPortName (f a) -> f (ExpandedPortName a)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> ExpandedPortName a -> m (ExpandedPortName b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> ExpandedPortName a -> f (ExpandedPortName b)
sequence :: forall (m :: Type -> Type) a.
Monad m =>
ExpandedPortName (m a) -> m (ExpandedPortName a)
$csequence :: forall (m :: Type -> Type) a.
Monad m =>
ExpandedPortName (m a) -> m (ExpandedPortName a)
mapM :: forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> ExpandedPortName a -> m (ExpandedPortName b)
$cmapM :: forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> ExpandedPortName a -> m (ExpandedPortName b)
sequenceA :: forall (f :: Type -> Type) a.
Applicative f =>
ExpandedPortName (f a) -> f (ExpandedPortName a)
$csequenceA :: forall (f :: Type -> Type) a.
Applicative f =>
ExpandedPortName (f a) -> f (ExpandedPortName a)
traverse :: forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> ExpandedPortName a -> f (ExpandedPortName b)
$ctraverse :: forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> ExpandedPortName a -> f (ExpandedPortName b)
Traversable)
newtype NetlistMonad a =
NetlistMonad { forall a.
NetlistMonad a -> StateT NetlistState (ReaderT NetlistEnv IO) a
runNetlist :: Strict.StateT NetlistState (ReaderT NetlistEnv IO) a }
deriving newtype ((forall a b. (a -> b) -> NetlistMonad a -> NetlistMonad b)
-> (forall a b. a -> NetlistMonad b -> NetlistMonad a)
-> Functor NetlistMonad
forall a b. a -> NetlistMonad b -> NetlistMonad a
forall a b. (a -> b) -> NetlistMonad a -> NetlistMonad b
forall (f :: Type -> Type).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> NetlistMonad b -> NetlistMonad a
$c<$ :: forall a b. a -> NetlistMonad b -> NetlistMonad a
fmap :: forall a b. (a -> b) -> NetlistMonad a -> NetlistMonad b
$cfmap :: forall a b. (a -> b) -> NetlistMonad a -> NetlistMonad b
Functor, Applicative NetlistMonad
Applicative NetlistMonad
-> (forall a b.
NetlistMonad a -> (a -> NetlistMonad b) -> NetlistMonad b)
-> (forall a b. NetlistMonad a -> NetlistMonad b -> NetlistMonad b)
-> (forall a. a -> NetlistMonad a)
-> Monad NetlistMonad
forall a. a -> NetlistMonad a
forall a b. NetlistMonad a -> NetlistMonad b -> NetlistMonad b
forall a b.
NetlistMonad a -> (a -> NetlistMonad b) -> NetlistMonad b
forall (m :: Type -> Type).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> NetlistMonad a
$creturn :: forall a. a -> NetlistMonad a
>> :: forall a b. NetlistMonad a -> NetlistMonad b -> NetlistMonad b
$c>> :: forall a b. NetlistMonad a -> NetlistMonad b -> NetlistMonad b
>>= :: forall a b.
NetlistMonad a -> (a -> NetlistMonad b) -> NetlistMonad b
$c>>= :: forall a b.
NetlistMonad a -> (a -> NetlistMonad b) -> NetlistMonad b
Monad, Functor NetlistMonad
Functor NetlistMonad
-> (forall a. a -> NetlistMonad a)
-> (forall a b.
NetlistMonad (a -> b) -> NetlistMonad a -> NetlistMonad b)
-> (forall a b c.
(a -> b -> c)
-> NetlistMonad a -> NetlistMonad b -> NetlistMonad c)
-> (forall a b. NetlistMonad a -> NetlistMonad b -> NetlistMonad b)
-> (forall a b. NetlistMonad a -> NetlistMonad b -> NetlistMonad a)
-> Applicative NetlistMonad
forall a. a -> NetlistMonad a
forall a b. NetlistMonad a -> NetlistMonad b -> NetlistMonad a
forall a b. NetlistMonad a -> NetlistMonad b -> NetlistMonad b
forall a b.
NetlistMonad (a -> b) -> NetlistMonad a -> NetlistMonad b
forall a b c.
(a -> b -> c) -> NetlistMonad a -> NetlistMonad b -> NetlistMonad c
forall (f :: Type -> Type).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: forall a b. NetlistMonad a -> NetlistMonad b -> NetlistMonad a
$c<* :: forall a b. NetlistMonad a -> NetlistMonad b -> NetlistMonad a
*> :: forall a b. NetlistMonad a -> NetlistMonad b -> NetlistMonad b
$c*> :: forall a b. NetlistMonad a -> NetlistMonad b -> NetlistMonad b
liftA2 :: forall a b c.
(a -> b -> c) -> NetlistMonad a -> NetlistMonad b -> NetlistMonad c
$cliftA2 :: forall a b c.
(a -> b -> c) -> NetlistMonad a -> NetlistMonad b -> NetlistMonad c
<*> :: forall a b.
NetlistMonad (a -> b) -> NetlistMonad a -> NetlistMonad b
$c<*> :: forall a b.
NetlistMonad (a -> b) -> NetlistMonad a -> NetlistMonad b
pure :: forall a. a -> NetlistMonad a
$cpure :: forall a. a -> NetlistMonad a
Applicative, MonadReader NetlistEnv,
Strict.MonadState NetlistState, Monad NetlistMonad
Monad NetlistMonad
-> (forall a. IO a -> NetlistMonad a) -> MonadIO NetlistMonad
forall a. IO a -> NetlistMonad a
forall (m :: Type -> Type).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: forall a. IO a -> NetlistMonad a
$cliftIO :: forall a. IO a -> NetlistMonad a
Strict.MonadIO, Monad NetlistMonad
Monad NetlistMonad
-> (forall a. BBName -> NetlistMonad a) -> MonadFail NetlistMonad
forall a. BBName -> NetlistMonad a
forall (m :: Type -> Type).
Monad m -> (forall a. BBName -> m a) -> MonadFail m
fail :: forall a. BBName -> NetlistMonad a
$cfail :: forall a. BBName -> NetlistMonad a
MonadFail)
type HWMap = Map Type (Either String FilteredHWType)
type FreshCache = HashMap Text (IntMap Word)
type IdentifierText = Text
data PreserveCase
= PreserveCase
| ToLower
deriving (BBHash -> PreserveCase -> ShowS
[PreserveCase] -> ShowS
PreserveCase -> BBName
(BBHash -> PreserveCase -> ShowS)
-> (PreserveCase -> BBName)
-> ([PreserveCase] -> ShowS)
-> Show PreserveCase
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [PreserveCase] -> ShowS
$cshowList :: [PreserveCase] -> ShowS
show :: PreserveCase -> BBName
$cshow :: PreserveCase -> BBName
showsPrec :: BBHash -> PreserveCase -> ShowS
$cshowsPrec :: BBHash -> PreserveCase -> ShowS
Show, (forall x. PreserveCase -> Rep PreserveCase x)
-> (forall x. Rep PreserveCase x -> PreserveCase)
-> Generic PreserveCase
forall x. Rep PreserveCase x -> PreserveCase
forall x. PreserveCase -> Rep PreserveCase x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PreserveCase x -> PreserveCase
$cfrom :: forall x. PreserveCase -> Rep PreserveCase x
Generic, PreserveCase -> ()
(PreserveCase -> ()) -> NFData PreserveCase
forall a. (a -> ()) -> NFData a
rnf :: PreserveCase -> ()
$crnf :: PreserveCase -> ()
NFData, PreserveCase -> PreserveCase -> Bool
(PreserveCase -> PreserveCase -> Bool)
-> (PreserveCase -> PreserveCase -> Bool) -> Eq PreserveCase
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PreserveCase -> PreserveCase -> Bool
$c/= :: PreserveCase -> PreserveCase -> Bool
== :: PreserveCase -> PreserveCase -> Bool
$c== :: PreserveCase -> PreserveCase -> Bool
Eq, Get PreserveCase
[PreserveCase] -> Put
PreserveCase -> Put
(PreserveCase -> Put)
-> Get PreserveCase
-> ([PreserveCase] -> Put)
-> Binary PreserveCase
forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
putList :: [PreserveCase] -> Put
$cputList :: [PreserveCase] -> Put
get :: Get PreserveCase
$cget :: Get PreserveCase
put :: PreserveCase -> Put
$cput :: PreserveCase -> Put
Binary, BBHash -> PreserveCase -> BBHash
PreserveCase -> BBHash
(BBHash -> PreserveCase -> BBHash)
-> (PreserveCase -> BBHash) -> Hashable PreserveCase
forall a. (BBHash -> a -> BBHash) -> (a -> BBHash) -> Hashable a
hash :: PreserveCase -> BBHash
$chash :: PreserveCase -> BBHash
hashWithSalt :: BBHash -> PreserveCase -> BBHash
$chashWithSalt :: BBHash -> PreserveCase -> BBHash
Hashable)
data IdentifierType
= Basic
| Extended
deriving (BBHash -> IdentifierType -> ShowS
[IdentifierType] -> ShowS
IdentifierType -> BBName
(BBHash -> IdentifierType -> ShowS)
-> (IdentifierType -> BBName)
-> ([IdentifierType] -> ShowS)
-> Show IdentifierType
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [IdentifierType] -> ShowS
$cshowList :: [IdentifierType] -> ShowS
show :: IdentifierType -> BBName
$cshow :: IdentifierType -> BBName
showsPrec :: BBHash -> IdentifierType -> ShowS
$cshowsPrec :: BBHash -> IdentifierType -> ShowS
Show, (forall x. IdentifierType -> Rep IdentifierType x)
-> (forall x. Rep IdentifierType x -> IdentifierType)
-> Generic IdentifierType
forall x. Rep IdentifierType x -> IdentifierType
forall x. IdentifierType -> Rep IdentifierType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IdentifierType x -> IdentifierType
$cfrom :: forall x. IdentifierType -> Rep IdentifierType x
Generic, IdentifierType -> ()
(IdentifierType -> ()) -> NFData IdentifierType
forall a. (a -> ()) -> NFData a
rnf :: IdentifierType -> ()
$crnf :: IdentifierType -> ()
NFData, IdentifierType -> IdentifierType -> Bool
(IdentifierType -> IdentifierType -> Bool)
-> (IdentifierType -> IdentifierType -> Bool) -> Eq IdentifierType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IdentifierType -> IdentifierType -> Bool
$c/= :: IdentifierType -> IdentifierType -> Bool
== :: IdentifierType -> IdentifierType -> Bool
$c== :: IdentifierType -> IdentifierType -> Bool
Eq)
data IdentifierSet
= IdentifierSet {
IdentifierSet -> Bool
is_allowEscaped :: !Bool
, IdentifierSet -> PreserveCase
is_lowerCaseBasicIds :: !PreserveCase
, IdentifierSet -> HDL
is_hdl :: !HDL
, IdentifierSet -> FreshCache
is_freshCache :: !FreshCache
, IdentifierSet -> HashSet Identifier
is_store :: !(HashSet Identifier)
} deriving ((forall x. IdentifierSet -> Rep IdentifierSet x)
-> (forall x. Rep IdentifierSet x -> IdentifierSet)
-> Generic IdentifierSet
forall x. Rep IdentifierSet x -> IdentifierSet
forall x. IdentifierSet -> Rep IdentifierSet x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IdentifierSet x -> IdentifierSet
$cfrom :: forall x. IdentifierSet -> Rep IdentifierSet x
Generic, IdentifierSet -> ()
(IdentifierSet -> ()) -> NFData IdentifierSet
forall a. (a -> ()) -> NFData a
rnf :: IdentifierSet -> ()
$crnf :: IdentifierSet -> ()
NFData, BBHash -> IdentifierSet -> ShowS
[IdentifierSet] -> ShowS
IdentifierSet -> BBName
(BBHash -> IdentifierSet -> ShowS)
-> (IdentifierSet -> BBName)
-> ([IdentifierSet] -> ShowS)
-> Show IdentifierSet
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [IdentifierSet] -> ShowS
$cshowList :: [IdentifierSet] -> ShowS
show :: IdentifierSet -> BBName
$cshow :: IdentifierSet -> BBName
showsPrec :: BBHash -> IdentifierSet -> ShowS
$cshowsPrec :: BBHash -> IdentifierSet -> ShowS
Show)
data Identifier
= RawIdentifier
!Text
(Maybe Identifier)
!CallStack
| UniqueIdentifier {
Identifier -> Text
i_baseName :: !Text
, Identifier -> Text
i_baseNameCaseFold :: !Text
, Identifier -> [Word]
i_extensionsRev :: [Word]
, Identifier -> IdentifierType
i_idType :: !IdentifierType
, Identifier -> HDL
i_hdl :: !HDL
, Identifier -> CallStack
i_provenance :: !CallStack
} deriving (BBHash -> Identifier -> ShowS
[Identifier] -> ShowS
Identifier -> BBName
(BBHash -> Identifier -> ShowS)
-> (Identifier -> BBName)
-> ([Identifier] -> ShowS)
-> Show Identifier
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [Identifier] -> ShowS
$cshowList :: [Identifier] -> ShowS
show :: Identifier -> BBName
$cshow :: Identifier -> BBName
showsPrec :: BBHash -> Identifier -> ShowS
$cshowsPrec :: BBHash -> Identifier -> ShowS
Show, (forall x. Identifier -> Rep Identifier x)
-> (forall x. Rep Identifier x -> Identifier) -> Generic Identifier
forall x. Rep Identifier x -> Identifier
forall x. Identifier -> Rep Identifier x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Identifier x -> Identifier
$cfrom :: forall x. Identifier -> Rep Identifier x
Generic, Identifier -> ()
(Identifier -> ()) -> NFData Identifier
forall a. (a -> ()) -> NFData a
rnf :: Identifier -> ()
$crnf :: Identifier -> ()
NFData)
identifierKey# :: Identifier -> ((Text, Bool), [Word])
identifierKey# :: Identifier -> ((Text, Bool), [Word])
identifierKey# (RawIdentifier Text
t Maybe Identifier
_id CallStack
_) = ((Text
t, Bool
True), [])
identifierKey# Identifier
id_ = ((Identifier -> Text
i_baseNameCaseFold Identifier
id_, Bool
False), Identifier -> [Word]
i_extensionsRev Identifier
id_)
instance Hashable Identifier where
hashWithSalt :: BBHash -> Identifier -> BBHash
hashWithSalt BBHash
salt = BBHash -> BBHash -> BBHash
forall a. Hashable a => BBHash -> a -> BBHash
hashWithSalt BBHash
salt (BBHash -> BBHash)
-> (Identifier -> BBHash) -> Identifier -> BBHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identifier -> BBHash
forall a. Hashable a => a -> BBHash
hash
hash :: Identifier -> BBHash
hash = ((Text, Bool) -> [Word] -> BBHash)
-> ((Text, Bool), [Word]) -> BBHash
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (Text, Bool) -> [Word] -> BBHash
forall {a} {b} {t :: Type -> Type}.
(Hashable a, Hashable b, Foldable t, Num b) =>
a -> t b -> BBHash
hash# (((Text, Bool), [Word]) -> BBHash)
-> (Identifier -> ((Text, Bool), [Word])) -> Identifier -> BBHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identifier -> ((Text, Bool), [Word])
identifierKey#
where
hash# :: a -> t b -> BBHash
hash# a
a t b
extensions =
let fuzz :: a -> a -> a
fuzz a
fuzzFactor a
ext = a
fuzzFactor a -> a -> a
forall a. Num a => a -> a -> a
* a
fuzzFactor a -> a -> a
forall a. Num a => a -> a -> a
* a
ext in
(a, b) -> BBHash
forall a. Hashable a => a -> BBHash
hash (a
a, (b -> b -> b) -> b -> t b -> b
forall (t :: Type -> Type) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' b -> b -> b
forall a. Num a => a -> a -> a
fuzz b
2 t b
extensions)
instance Eq Identifier where
Identifier
i1 == :: Identifier -> Identifier -> Bool
== Identifier
i2 = Identifier -> ((Text, Bool), [Word])
identifierKey# Identifier
i1 ((Text, Bool), [Word]) -> ((Text, Bool), [Word]) -> Bool
forall a. Eq a => a -> a -> Bool
== Identifier -> ((Text, Bool), [Word])
identifierKey# Identifier
i2
Identifier
i1 /= :: Identifier -> Identifier -> Bool
/= Identifier
i2 = Identifier -> ((Text, Bool), [Word])
identifierKey# Identifier
i1 ((Text, Bool), [Word]) -> ((Text, Bool), [Word]) -> Bool
forall a. Eq a => a -> a -> Bool
/= Identifier -> ((Text, Bool), [Word])
identifierKey# Identifier
i2
instance Ord Identifier where
compare :: Identifier -> Identifier -> Ordering
compare = ((Text, Bool), [Word]) -> ((Text, Bool), [Word]) -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (((Text, Bool), [Word]) -> ((Text, Bool), [Word]) -> Ordering)
-> (Identifier -> ((Text, Bool), [Word]))
-> Identifier
-> Identifier
-> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Identifier -> ((Text, Bool), [Word])
identifierKey#
data NetlistEnv
= NetlistEnv
{ NetlistEnv -> ClashEnv
_clashEnv :: ClashEnv
, NetlistEnv -> Text
_prefixName :: Text
, NetlistEnv -> Text
_suffixName :: Text
, NetlistEnv -> Maybe Text
_setName :: Maybe Text
}
data ComponentMeta = ComponentMeta
{ ComponentMeta -> [Bool]
cmWereVoids :: [Bool]
, ComponentMeta -> SrcSpan
cmLoc :: SrcSpan
, ComponentMeta -> IdentifierSet
cmScope :: IdentifierSet
} deriving ((forall x. ComponentMeta -> Rep ComponentMeta x)
-> (forall x. Rep ComponentMeta x -> ComponentMeta)
-> Generic ComponentMeta
forall x. Rep ComponentMeta x -> ComponentMeta
forall x. ComponentMeta -> Rep ComponentMeta x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ComponentMeta x -> ComponentMeta
$cfrom :: forall x. ComponentMeta -> Rep ComponentMeta x
Generic, BBHash -> ComponentMeta -> ShowS
[ComponentMeta] -> ShowS
ComponentMeta -> BBName
(BBHash -> ComponentMeta -> ShowS)
-> (ComponentMeta -> BBName)
-> ([ComponentMeta] -> ShowS)
-> Show ComponentMeta
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [ComponentMeta] -> ShowS
$cshowList :: [ComponentMeta] -> ShowS
show :: ComponentMeta -> BBName
$cshow :: ComponentMeta -> BBName
showsPrec :: BBHash -> ComponentMeta -> ShowS
$cshowsPrec :: BBHash -> ComponentMeta -> ShowS
Show, ComponentMeta -> ()
(ComponentMeta -> ()) -> NFData ComponentMeta
forall a. (a -> ()) -> NFData a
rnf :: ComponentMeta -> ()
$crnf :: ComponentMeta -> ()
NFData)
type ComponentMap = OMap Unique (ComponentMeta, Component)
data NetlistState
= NetlistState
{ NetlistState -> BindingMap
_bindings :: BindingMap
, NetlistState -> ComponentMap
_components :: ComponentMap
, NetlistState
-> CustomReprs
-> TyConMap
-> Type
-> State HWMap (Maybe (Either BBName FilteredHWType))
_typeTranslator :: CustomReprs -> TyConMap -> Type
-> Strict.State HWMap (Maybe (Either String FilteredHWType))
, NetlistState -> (Identifier, SrcSpan)
_curCompNm :: !(Identifier,SrcSpan)
, NetlistState -> IdentifierSet
_seenIds :: IdentifierSet
, NetlistState -> IdentifierSet
_seenComps :: IdentifierSet
, NetlistState -> Set Text
_seenPrimitives :: Set.Set Text
, NetlistState -> VarEnv Identifier
_componentNames :: VarEnv Identifier
, NetlistState -> VarEnv TopEntityT
_topEntityAnns :: VarEnv TopEntityT
, NetlistState -> BBName
_hdlDir :: FilePath
, NetlistState -> BBHash
_curBBlvl :: Int
, NetlistState -> Bool
_isTestBench :: Bool
, NetlistState -> Bool
_backEndITE :: Bool
, NetlistState -> SomeBackend
_backend :: SomeBackend
, NetlistState -> HWMap
_htyCache :: HWMap
}
data ComponentPrefix
= ComponentPrefix
{ ComponentPrefix -> Maybe Text
componentPrefixTop :: Maybe Text
, ComponentPrefix -> Maybe Text
componentPrefixOther :: Maybe Text
} deriving BBHash -> ComponentPrefix -> ShowS
[ComponentPrefix] -> ShowS
ComponentPrefix -> BBName
(BBHash -> ComponentPrefix -> ShowS)
-> (ComponentPrefix -> BBName)
-> ([ComponentPrefix] -> ShowS)
-> Show ComponentPrefix
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [ComponentPrefix] -> ShowS
$cshowList :: [ComponentPrefix] -> ShowS
show :: ComponentPrefix -> BBName
$cshow :: ComponentPrefix -> BBName
showsPrec :: BBHash -> ComponentPrefix -> ShowS
$cshowsPrec :: BBHash -> ComponentPrefix -> ShowS
Show
data SomeBackend where
SomeBackend :: Backend backend => backend -> SomeBackend
type = Text
type Directive = Text
data
= Comment
| Directive Directive
deriving BBHash -> CommentOrDirective -> ShowS
[CommentOrDirective] -> ShowS
CommentOrDirective -> BBName
(BBHash -> CommentOrDirective -> ShowS)
-> (CommentOrDirective -> BBName)
-> ([CommentOrDirective] -> ShowS)
-> Show CommentOrDirective
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [CommentOrDirective] -> ShowS
$cshowList :: [CommentOrDirective] -> ShowS
show :: CommentOrDirective -> BBName
$cshow :: CommentOrDirective -> BBName
showsPrec :: BBHash -> CommentOrDirective -> ShowS
$cshowsPrec :: BBHash -> CommentOrDirective -> ShowS
Show
data Component
= Component
{ Component -> Identifier
componentName :: !Identifier
, Component -> [(Identifier, HWType)]
inputs :: [(Identifier,HWType)]
, Component -> [(WireOrReg, (Identifier, HWType), Maybe Expr)]
outputs :: [(WireOrReg,(Identifier,HWType),Maybe Expr)]
, Component -> [Declaration]
declarations :: [Declaration]
}
deriving (BBHash -> Component -> ShowS
[Component] -> ShowS
Component -> BBName
(BBHash -> Component -> ShowS)
-> (Component -> BBName)
-> ([Component] -> ShowS)
-> Show Component
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [Component] -> ShowS
$cshowList :: [Component] -> ShowS
show :: Component -> BBName
$cshow :: Component -> BBName
showsPrec :: BBHash -> Component -> ShowS
$cshowsPrec :: BBHash -> Component -> ShowS
Show, (forall x. Component -> Rep Component x)
-> (forall x. Rep Component x -> Component) -> Generic Component
forall x. Rep Component x -> Component
forall x. Component -> Rep Component x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Component x -> Component
$cfrom :: forall x. Component -> Rep Component x
Generic, Component -> ()
(Component -> ()) -> NFData Component
forall a. (a -> ()) -> NFData a
rnf :: Component -> ()
$crnf :: Component -> ()
NFData)
isBiDirectional :: (Identifier, HWType) -> Bool
isBiDirectional :: (Identifier, HWType) -> Bool
isBiDirectional (Identifier
_, BiDirectional PortDirection
_ HWType
_) = Bool
True
isBiDirectional (Identifier, HWType)
_ = Bool
False
findClocks :: Component -> [(Text, Text)]
findClocks :: Component -> [(Text, Text)]
findClocks (Component Identifier
_ [(Identifier, HWType)]
is [(WireOrReg, (Identifier, HWType), Maybe Expr)]
_ [Declaration]
_) =
((Identifier, HWType) -> Maybe (Text, Text))
-> [(Identifier, HWType)] -> [(Text, Text)]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Identifier, HWType) -> Maybe (Text, Text)
isClock [(Identifier, HWType)]
is
where
isClock :: (Identifier, HWType) -> Maybe (Text, Text)
isClock (Identifier
i, Clock Text
d) = (Text, Text) -> Maybe (Text, Text)
forall a. a -> Maybe a
Just (Identifier -> Text
Id.toText Identifier
i, Text
d)
isClock (Identifier
i, Annotated [Attr']
_ HWType
t) = (Identifier, HWType) -> Maybe (Text, Text)
isClock (Identifier
i,HWType
t)
isClock (Identifier, HWType)
_ = Maybe (Text, Text)
forall a. Maybe a
Nothing
type Size = Int
type IsVoid = Bool
data FilteredHWType =
FilteredHWType HWType [[(IsVoid, FilteredHWType)]]
deriving (FilteredHWType -> FilteredHWType -> Bool
(FilteredHWType -> FilteredHWType -> Bool)
-> (FilteredHWType -> FilteredHWType -> Bool) -> Eq FilteredHWType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FilteredHWType -> FilteredHWType -> Bool
$c/= :: FilteredHWType -> FilteredHWType -> Bool
== :: FilteredHWType -> FilteredHWType -> Bool
$c== :: FilteredHWType -> FilteredHWType -> Bool
Eq, BBHash -> FilteredHWType -> ShowS
[FilteredHWType] -> ShowS
FilteredHWType -> BBName
(BBHash -> FilteredHWType -> ShowS)
-> (FilteredHWType -> BBName)
-> ([FilteredHWType] -> ShowS)
-> Show FilteredHWType
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [FilteredHWType] -> ShowS
$cshowList :: [FilteredHWType] -> ShowS
show :: FilteredHWType -> BBName
$cshow :: FilteredHWType -> BBName
showsPrec :: BBHash -> FilteredHWType -> ShowS
$cshowsPrec :: BBHash -> FilteredHWType -> ShowS
Show)
type DomainName = Text
data HWType
= Void (Maybe HWType)
| String
| Integer
| Bool
| Bit
| BitVector !Size
| Index !Integer
| Signed !Size
| Unsigned !Size
| Vector !Size !HWType
| MemBlob !Size !Size
| RTree !Size !HWType
| Sum !Text [Text]
| Product !Text (Maybe [Text]) [HWType]
| SP !Text [(Text, [HWType])]
| Clock !DomainName
| Reset !DomainName
| Enable !DomainName
| BiDirectional !PortDirection !HWType
| CustomSP !Text !DataRepr' !Size [(ConstrRepr', Text, [HWType])]
| CustomSum !Text !DataRepr' !Size [(ConstrRepr', Text)]
| CustomProduct !Text !DataRepr' !Size (Maybe [Text]) [(FieldAnn, HWType)]
| Annotated [Attr'] !HWType
| KnownDomain !DomainName !Integer !ActiveEdge !ResetKind !InitBehavior !ResetPolarity
| FileType
deriving (HWType -> HWType -> Bool
(HWType -> HWType -> Bool)
-> (HWType -> HWType -> Bool) -> Eq HWType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HWType -> HWType -> Bool
$c/= :: HWType -> HWType -> Bool
== :: HWType -> HWType -> Bool
$c== :: HWType -> HWType -> Bool
Eq, Eq HWType
Eq HWType
-> (HWType -> HWType -> Ordering)
-> (HWType -> HWType -> Bool)
-> (HWType -> HWType -> Bool)
-> (HWType -> HWType -> Bool)
-> (HWType -> HWType -> Bool)
-> (HWType -> HWType -> HWType)
-> (HWType -> HWType -> HWType)
-> Ord HWType
HWType -> HWType -> Bool
HWType -> HWType -> Ordering
HWType -> HWType -> HWType
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: HWType -> HWType -> HWType
$cmin :: HWType -> HWType -> HWType
max :: HWType -> HWType -> HWType
$cmax :: HWType -> HWType -> HWType
>= :: HWType -> HWType -> Bool
$c>= :: HWType -> HWType -> Bool
> :: HWType -> HWType -> Bool
$c> :: HWType -> HWType -> Bool
<= :: HWType -> HWType -> Bool
$c<= :: HWType -> HWType -> Bool
< :: HWType -> HWType -> Bool
$c< :: HWType -> HWType -> Bool
compare :: HWType -> HWType -> Ordering
$ccompare :: HWType -> HWType -> Ordering
Ord, BBHash -> HWType -> ShowS
[HWType] -> ShowS
HWType -> BBName
(BBHash -> HWType -> ShowS)
-> (HWType -> BBName) -> ([HWType] -> ShowS) -> Show HWType
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [HWType] -> ShowS
$cshowList :: [HWType] -> ShowS
show :: HWType -> BBName
$cshow :: HWType -> BBName
showsPrec :: BBHash -> HWType -> ShowS
$cshowsPrec :: BBHash -> HWType -> ShowS
Show, (forall x. HWType -> Rep HWType x)
-> (forall x. Rep HWType x -> HWType) -> Generic HWType
forall x. Rep HWType x -> HWType
forall x. HWType -> Rep HWType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HWType x -> HWType
$cfrom :: forall x. HWType -> Rep HWType x
Generic, HWType -> ()
(HWType -> ()) -> NFData HWType
forall a. (a -> ()) -> NFData a
rnf :: HWType -> ()
$crnf :: HWType -> ()
NFData, BBHash -> HWType -> BBHash
HWType -> BBHash
(BBHash -> HWType -> BBHash)
-> (HWType -> BBHash) -> Hashable HWType
forall a. (BBHash -> a -> BBHash) -> (a -> BBHash) -> Hashable a
hash :: HWType -> BBHash
$chash :: HWType -> BBHash
hashWithSalt :: BBHash -> HWType -> BBHash
$chashWithSalt :: BBHash -> HWType -> BBHash
Hashable)
hwTypeDomain :: HWType -> Maybe DomainName
hwTypeDomain :: HWType -> Maybe Text
hwTypeDomain = \case
Clock Text
dom -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
dom
Reset Text
dom -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
dom
Enable Text
dom -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
dom
KnownDomain Text
dom Integer
_ ActiveEdge
_ ResetKind
_ InitBehavior
_ ResetPolarity
_ -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
dom
HWType
_ -> Maybe Text
forall a. Maybe a
Nothing
hwTypeAttrs :: HWType -> [Attr']
hwTypeAttrs :: HWType -> [Attr']
hwTypeAttrs (Annotated [Attr']
attrs HWType
_type) = [Attr']
attrs
hwTypeAttrs HWType
_ = []
data PortMap
= IndexedPortMap [(PortDirection, HWType, Expr)]
| NamedPortMap [(Expr, PortDirection, HWType, Expr)]
deriving (BBHash -> PortMap -> ShowS
[PortMap] -> ShowS
PortMap -> BBName
(BBHash -> PortMap -> ShowS)
-> (PortMap -> BBName) -> ([PortMap] -> ShowS) -> Show PortMap
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [PortMap] -> ShowS
$cshowList :: [PortMap] -> ShowS
show :: PortMap -> BBName
$cshow :: PortMap -> BBName
showsPrec :: BBHash -> PortMap -> ShowS
$cshowsPrec :: BBHash -> PortMap -> ShowS
Show)
data Declaration
= Assignment
!Identifier
!Expr
| CondAssignment
!Identifier
!HWType
!Expr
!HWType
[(Maybe Literal,Expr)]
| InstDecl
EntityOrComponent
(Maybe Text)
[Attr']
!Identifier
!Identifier
[(Expr,HWType,Expr)]
PortMap
| BlackBoxD
!Text
[BlackBoxTemplate]
[BlackBoxTemplate]
[((Text,Text),BlackBox)]
!BlackBox
BlackBoxContext
| NetDecl'
(Maybe Comment)
WireOrReg
!Identifier
(Either IdentifierText HWType)
(Maybe Expr)
| TickDecl CommentOrDirective
| Seq [Seq]
| ConditionalDecl
!Text
[Declaration]
deriving BBHash -> Declaration -> ShowS
[Declaration] -> ShowS
Declaration -> BBName
(BBHash -> Declaration -> ShowS)
-> (Declaration -> BBName)
-> ([Declaration] -> ShowS)
-> Show Declaration
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [Declaration] -> ShowS
$cshowList :: [Declaration] -> ShowS
show :: Declaration -> BBName
$cshow :: Declaration -> BBName
showsPrec :: BBHash -> Declaration -> ShowS
$cshowsPrec :: BBHash -> Declaration -> ShowS
Show
data Seq
= AlwaysClocked
ActiveEdge
Expr
[Seq]
| Initial
[Seq]
| AlwaysComb
[Seq]
| SeqDecl
Declaration
| Branch
!Expr
!HWType
[(Maybe Literal,[Seq])]
deriving BBHash -> Seq -> ShowS
[Seq] -> ShowS
Seq -> BBName
(BBHash -> Seq -> ShowS)
-> (Seq -> BBName) -> ([Seq] -> ShowS) -> Show Seq
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [Seq] -> ShowS
$cshowList :: [Seq] -> ShowS
show :: Seq -> BBName
$cshow :: Seq -> BBName
showsPrec :: BBHash -> Seq -> ShowS
$cshowsPrec :: BBHash -> Seq -> ShowS
Show
data EntityOrComponent = Entity | Comp | Empty
deriving BBHash -> EntityOrComponent -> ShowS
[EntityOrComponent] -> ShowS
EntityOrComponent -> BBName
(BBHash -> EntityOrComponent -> ShowS)
-> (EntityOrComponent -> BBName)
-> ([EntityOrComponent] -> ShowS)
-> Show EntityOrComponent
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [EntityOrComponent] -> ShowS
$cshowList :: [EntityOrComponent] -> ShowS
show :: EntityOrComponent -> BBName
$cshow :: EntityOrComponent -> BBName
showsPrec :: BBHash -> EntityOrComponent -> ShowS
$cshowsPrec :: BBHash -> EntityOrComponent -> ShowS
Show
data WireOrReg = Wire | Reg
deriving (BBHash -> WireOrReg -> ShowS
[WireOrReg] -> ShowS
WireOrReg -> BBName
(BBHash -> WireOrReg -> ShowS)
-> (WireOrReg -> BBName)
-> ([WireOrReg] -> ShowS)
-> Show WireOrReg
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [WireOrReg] -> ShowS
$cshowList :: [WireOrReg] -> ShowS
show :: WireOrReg -> BBName
$cshow :: WireOrReg -> BBName
showsPrec :: BBHash -> WireOrReg -> ShowS
$cshowsPrec :: BBHash -> WireOrReg -> ShowS
Show,(forall x. WireOrReg -> Rep WireOrReg x)
-> (forall x. Rep WireOrReg x -> WireOrReg) -> Generic WireOrReg
forall x. Rep WireOrReg x -> WireOrReg
forall x. WireOrReg -> Rep WireOrReg x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep WireOrReg x -> WireOrReg
$cfrom :: forall x. WireOrReg -> Rep WireOrReg x
Generic)
instance NFData WireOrReg
pattern NetDecl
:: Maybe Comment
-> Identifier
-> HWType
-> Declaration
pattern $bNetDecl :: Maybe Text -> Identifier -> HWType -> Declaration
$mNetDecl :: forall {r}.
Declaration
-> (Maybe Text -> Identifier -> HWType -> r) -> (Void# -> r) -> r
NetDecl note d ty <- NetDecl' note Wire d (Right ty) _
where
NetDecl Maybe Text
note Identifier
d HWType
ty = Maybe Text
-> WireOrReg
-> Identifier
-> Either Text HWType
-> Maybe Expr
-> Declaration
NetDecl' Maybe Text
note WireOrReg
Wire Identifier
d (HWType -> Either Text HWType
forall a b. b -> Either a b
Right HWType
ty) Maybe Expr
forall a. Maybe a
Nothing
data PortDirection = In | Out
deriving (PortDirection -> PortDirection -> Bool
(PortDirection -> PortDirection -> Bool)
-> (PortDirection -> PortDirection -> Bool) -> Eq PortDirection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortDirection -> PortDirection -> Bool
$c/= :: PortDirection -> PortDirection -> Bool
== :: PortDirection -> PortDirection -> Bool
$c== :: PortDirection -> PortDirection -> Bool
Eq,Eq PortDirection
Eq PortDirection
-> (PortDirection -> PortDirection -> Ordering)
-> (PortDirection -> PortDirection -> Bool)
-> (PortDirection -> PortDirection -> Bool)
-> (PortDirection -> PortDirection -> Bool)
-> (PortDirection -> PortDirection -> Bool)
-> (PortDirection -> PortDirection -> PortDirection)
-> (PortDirection -> PortDirection -> PortDirection)
-> Ord PortDirection
PortDirection -> PortDirection -> Bool
PortDirection -> PortDirection -> Ordering
PortDirection -> PortDirection -> PortDirection
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: PortDirection -> PortDirection -> PortDirection
$cmin :: PortDirection -> PortDirection -> PortDirection
max :: PortDirection -> PortDirection -> PortDirection
$cmax :: PortDirection -> PortDirection -> PortDirection
>= :: PortDirection -> PortDirection -> Bool
$c>= :: PortDirection -> PortDirection -> Bool
> :: PortDirection -> PortDirection -> Bool
$c> :: PortDirection -> PortDirection -> Bool
<= :: PortDirection -> PortDirection -> Bool
$c<= :: PortDirection -> PortDirection -> Bool
< :: PortDirection -> PortDirection -> Bool
$c< :: PortDirection -> PortDirection -> Bool
compare :: PortDirection -> PortDirection -> Ordering
$ccompare :: PortDirection -> PortDirection -> Ordering
Ord,BBHash -> PortDirection -> ShowS
[PortDirection] -> ShowS
PortDirection -> BBName
(BBHash -> PortDirection -> ShowS)
-> (PortDirection -> BBName)
-> ([PortDirection] -> ShowS)
-> Show PortDirection
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [PortDirection] -> ShowS
$cshowList :: [PortDirection] -> ShowS
show :: PortDirection -> BBName
$cshow :: PortDirection -> BBName
showsPrec :: BBHash -> PortDirection -> ShowS
$cshowsPrec :: BBHash -> PortDirection -> ShowS
Show,(forall x. PortDirection -> Rep PortDirection x)
-> (forall x. Rep PortDirection x -> PortDirection)
-> Generic PortDirection
forall x. Rep PortDirection x -> PortDirection
forall x. PortDirection -> Rep PortDirection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PortDirection x -> PortDirection
$cfrom :: forall x. PortDirection -> Rep PortDirection x
Generic,PortDirection -> ()
(PortDirection -> ()) -> NFData PortDirection
forall a. (a -> ()) -> NFData a
rnf :: PortDirection -> ()
$crnf :: PortDirection -> ()
NFData,BBHash -> PortDirection -> BBHash
PortDirection -> BBHash
(BBHash -> PortDirection -> BBHash)
-> (PortDirection -> BBHash) -> Hashable PortDirection
forall a. (BBHash -> a -> BBHash) -> (a -> BBHash) -> Hashable a
hash :: PortDirection -> BBHash
$chash :: PortDirection -> BBHash
hashWithSalt :: BBHash -> PortDirection -> BBHash
$chashWithSalt :: BBHash -> PortDirection -> BBHash
Hashable)
instance NFData Declaration where
rnf :: Declaration -> ()
rnf Declaration
a = Declaration
a Declaration -> () -> ()
`seq` ()
data Modifier
= Indexed (HWType,Int,Int)
| DC (HWType,Int)
| VecAppend
| RTreeAppend
| Sliced (HWType,Int,Int)
| Nested Modifier Modifier
deriving BBHash -> Modifier -> ShowS
[Modifier] -> ShowS
Modifier -> BBName
(BBHash -> Modifier -> ShowS)
-> (Modifier -> BBName) -> ([Modifier] -> ShowS) -> Show Modifier
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [Modifier] -> ShowS
$cshowList :: [Modifier] -> ShowS
show :: Modifier -> BBName
$cshow :: Modifier -> BBName
showsPrec :: BBHash -> Modifier -> ShowS
$cshowsPrec :: BBHash -> Modifier -> ShowS
Show
data Expr
= Literal !(Maybe (HWType,Size)) !Literal
| DataCon !HWType !Modifier [Expr]
| Identifier !Identifier !(Maybe Modifier)
| DataTag !HWType !(Either Identifier Identifier)
| BlackBoxE
!Text
[BlackBoxTemplate]
[BlackBoxTemplate]
[((Text,Text),BlackBox)]
!BlackBox
!BlackBoxContext
!Bool
| ToBv
(Maybe Identifier)
HWType
Expr
| FromBv
(Maybe Identifier)
HWType
Expr
| IfThenElse Expr Expr Expr
| Noop
deriving BBHash -> Expr -> ShowS
[Expr] -> ShowS
Expr -> BBName
(BBHash -> Expr -> ShowS)
-> (Expr -> BBName) -> ([Expr] -> ShowS) -> Show Expr
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [Expr] -> ShowS
$cshowList :: [Expr] -> ShowS
show :: Expr -> BBName
$cshow :: Expr -> BBName
showsPrec :: BBHash -> Expr -> ShowS
$cshowsPrec :: BBHash -> Expr -> ShowS
Show
instance NFData Expr where
rnf :: Expr -> ()
rnf Expr
x = Expr
x Expr -> () -> ()
`seq` ()
data Literal
= NumLit !Integer
| BitLit !Bit
| BitVecLit !Integer !Integer
| BoolLit !Bool
| VecLit [Literal]
| StringLit !String
deriving (Literal -> Literal -> Bool
(Literal -> Literal -> Bool)
-> (Literal -> Literal -> Bool) -> Eq Literal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Literal -> Literal -> Bool
$c/= :: Literal -> Literal -> Bool
== :: Literal -> Literal -> Bool
$c== :: Literal -> Literal -> Bool
Eq,BBHash -> Literal -> ShowS
[Literal] -> ShowS
Literal -> BBName
(BBHash -> Literal -> ShowS)
-> (Literal -> BBName) -> ([Literal] -> ShowS) -> Show Literal
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [Literal] -> ShowS
$cshowList :: [Literal] -> ShowS
show :: Literal -> BBName
$cshow :: Literal -> BBName
showsPrec :: BBHash -> Literal -> ShowS
$cshowsPrec :: BBHash -> Literal -> ShowS
Show)
data Bit
= H
| L
| U
| Z
deriving (Bit -> Bit -> Bool
(Bit -> Bit -> Bool) -> (Bit -> Bit -> Bool) -> Eq Bit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Bit -> Bit -> Bool
$c/= :: Bit -> Bit -> Bool
== :: Bit -> Bit -> Bool
$c== :: Bit -> Bit -> Bool
Eq,BBHash -> Bit -> ShowS
[Bit] -> ShowS
Bit -> BBName
(BBHash -> Bit -> ShowS)
-> (Bit -> BBName) -> ([Bit] -> ShowS) -> Show Bit
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [Bit] -> ShowS
$cshowList :: [Bit] -> ShowS
show :: Bit -> BBName
$cshow :: Bit -> BBName
showsPrec :: BBHash -> Bit -> ShowS
$cshowsPrec :: BBHash -> Bit -> ShowS
Show,Typeable,(forall (m :: Type -> Type). Quote m => Bit -> m Exp)
-> (forall (m :: Type -> Type). Quote m => Bit -> Code m Bit)
-> Lift Bit
forall t.
(forall (m :: Type -> Type). Quote m => t -> m Exp)
-> (forall (m :: Type -> Type). Quote m => t -> Code m t) -> Lift t
forall (m :: Type -> Type). Quote m => Bit -> m Exp
forall (m :: Type -> Type). Quote m => Bit -> Code m Bit
liftTyped :: forall (m :: Type -> Type). Quote m => Bit -> Code m Bit
$cliftTyped :: forall (m :: Type -> Type). Quote m => Bit -> Code m Bit
lift :: forall (m :: Type -> Type). Quote m => Bit -> m Exp
$clift :: forall (m :: Type -> Type). Quote m => Bit -> m Exp
Lift)
toBit :: Integer
-> Integer
-> Bit
toBit :: Integer -> Integer -> Bit
toBit Integer
m Integer
i = if Integer -> BBHash -> Bool
forall a. Bits a => a -> BBHash -> Bool
testBit Integer
m BBHash
0
then Bit
U
else if Integer -> BBHash -> Bool
forall a. Bits a => a -> BBHash -> Bool
testBit Integer
i BBHash
0 then Bit
H else Bit
L
data BlackBoxContext
= Context
{ BlackBoxContext -> Text
bbName :: Text
, BlackBoxContext -> [(Expr, HWType)]
bbResults :: [(Expr,HWType)]
, BlackBoxContext -> [(Expr, HWType, Bool)]
bbInputs :: [(Expr,HWType,Bool)]
, BlackBoxContext
-> IntMap
[(Either BlackBox (Identifier, [Declaration]), WireOrReg,
[BlackBoxTemplate], [BlackBoxTemplate], [((Text, Text), BlackBox)],
BlackBoxContext)]
bbFunctions :: IntMap [(Either BlackBox (Identifier,[Declaration])
,WireOrReg
,[BlackBoxTemplate]
,[BlackBoxTemplate]
,[((Text,Text),BlackBox)]
,BlackBoxContext)]
, BlackBoxContext -> [Text]
bbQsysIncName :: [IdentifierText]
, BlackBoxContext -> BBHash
bbLevel :: Int
, BlackBoxContext -> Identifier
bbCompName :: Identifier
, BlackBoxContext -> Maybe Text
bbCtxName :: Maybe IdentifierText
}
deriving BBHash -> BlackBoxContext -> ShowS
[BlackBoxContext] -> ShowS
BlackBoxContext -> BBName
(BBHash -> BlackBoxContext -> ShowS)
-> (BlackBoxContext -> BBName)
-> ([BlackBoxContext] -> ShowS)
-> Show BlackBoxContext
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [BlackBoxContext] -> ShowS
$cshowList :: [BlackBoxContext] -> ShowS
show :: BlackBoxContext -> BBName
$cshow :: BlackBoxContext -> BBName
showsPrec :: BBHash -> BlackBoxContext -> ShowS
$cshowsPrec :: BBHash -> BlackBoxContext -> ShowS
Show
type BBName = String
type BBHash = Int
data BlackBox
= BBTemplate BlackBoxTemplate
| BBFunction BBName BBHash TemplateFunction
deriving ((forall x. BlackBox -> Rep BlackBox x)
-> (forall x. Rep BlackBox x -> BlackBox) -> Generic BlackBox
forall x. Rep BlackBox x -> BlackBox
forall x. BlackBox -> Rep BlackBox x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BlackBox x -> BlackBox
$cfrom :: forall x. BlackBox -> Rep BlackBox x
Generic, BlackBox -> ()
(BlackBox -> ()) -> NFData BlackBox
forall a. (a -> ()) -> NFData a
rnf :: BlackBox -> ()
$crnf :: BlackBox -> ()
NFData, Get BlackBox
[BlackBox] -> Put
BlackBox -> Put
(BlackBox -> Put)
-> Get BlackBox -> ([BlackBox] -> Put) -> Binary BlackBox
forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
putList :: [BlackBox] -> Put
$cputList :: [BlackBox] -> Put
get :: Get BlackBox
$cget :: Get BlackBox
put :: BlackBox -> Put
$cput :: BlackBox -> Put
Binary)
data TemplateFunction where
TemplateFunction
:: [Int]
-> (BlackBoxContext -> Bool)
-> (forall s . Backend s => BlackBoxContext -> Lazy.State s Doc)
-> TemplateFunction
instance Show BlackBox where
showsPrec :: BBHash -> BlackBox -> ShowS
showsPrec BBHash
d (BBTemplate BlackBoxTemplate
t) =
Bool -> ShowS -> ShowS
showParen (BBHash
d BBHash -> BBHash -> Bool
forall a. Ord a => a -> a -> Bool
> BBHash
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ (BBName
"BBTemplate " BBName -> ShowS
forall a. [a] -> [a] -> [a]
++) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BBHash -> BlackBoxTemplate -> ShowS
forall a. Show a => BBHash -> a -> ShowS
showsPrec BBHash
11 BlackBoxTemplate
t
showsPrec BBHash
_ (BBFunction BBName
nm BBHash
hsh TemplateFunction
_) =
(BBName
"<TemplateFunction(nm=" BBName -> ShowS
forall a. [a] -> [a] -> [a]
++) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BBName -> ShowS
forall a. Show a => a -> ShowS
shows BBName
nm ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BBName
", hash=" BBName -> ShowS
forall a. [a] -> [a] -> [a]
++) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BBHash -> ShowS
forall a. Show a => a -> ShowS
shows BBHash
hsh ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(BBName
")>" BBName -> ShowS
forall a. [a] -> [a] -> [a]
++)
instance NFData TemplateFunction where
rnf :: TemplateFunction -> ()
rnf (TemplateFunction [BBHash]
is BlackBoxContext -> Bool
f forall s. Backend s => BlackBoxContext -> State s Doc
_) = [BBHash] -> ()
forall a. NFData a => a -> ()
rnf [BBHash]
is () -> () -> ()
`seq` BlackBoxContext -> Bool
f (BlackBoxContext -> Bool) -> () -> ()
`seq` ()
instance Binary TemplateFunction where
put :: TemplateFunction -> Put
put (TemplateFunction [BBHash]
is BlackBoxContext -> Bool
_ forall s. Backend s => BlackBoxContext -> State s Doc
_ ) = [BBHash] -> Put
forall t. Binary t => t -> Put
put [BBHash]
is
get :: Get TemplateFunction
get = (\[BBHash]
is -> [BBHash]
-> (BlackBoxContext -> Bool)
-> (forall s. Backend s => BlackBoxContext -> State s Doc)
-> TemplateFunction
TemplateFunction [BBHash]
is BlackBoxContext -> Bool
forall {b} {a}. b -> a
err forall s. Backend s => BlackBoxContext -> State s Doc
forall {b} {a}. b -> a
err) ([BBHash] -> TemplateFunction)
-> Get [BBHash] -> Get TemplateFunction
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Get [BBHash]
forall t. Binary t => Get t
get
where err :: b -> a
err = a -> b -> a
forall a b. a -> b -> a
const (a -> b -> a) -> a -> b -> a
forall a b. (a -> b) -> a -> b
$ BBName -> a
forall a. HasCallStack => BBName -> a
error BBName
"TemplateFunction functions can't be preserved by serialisation"
data NetlistId
= NetlistId Identifier Type
| CoreId Id
| MultiId [Id]
deriving BBHash -> NetlistId -> ShowS
[NetlistId] -> ShowS
NetlistId -> BBName
(BBHash -> NetlistId -> ShowS)
-> (NetlistId -> BBName)
-> ([NetlistId] -> ShowS)
-> Show NetlistId
forall a.
(BBHash -> a -> ShowS) -> (a -> BBName) -> ([a] -> ShowS) -> Show a
showList :: [NetlistId] -> ShowS
$cshowList :: [NetlistId] -> ShowS
show :: NetlistId -> BBName
$cshow :: NetlistId -> BBName
showsPrec :: BBHash -> NetlistId -> ShowS
$cshowsPrec :: BBHash -> NetlistId -> ShowS
Show
netlistId1
:: HasCallStack
=> (Identifier -> r)
-> (Id -> r)
-> NetlistId
-> r
netlistId1 :: forall r.
HasCallStack =>
(Identifier -> r) -> (Id -> r) -> NetlistId -> r
netlistId1 Identifier -> r
f Id -> r
g = \case
NetlistId Identifier
i Type
_ -> Identifier -> r
f Identifier
i
CoreId Id
i -> Id -> r
g Id
i
NetlistId
m -> BBName -> r
forall a. HasCallStack => BBName -> a
error (BBName
"netlistId1 MultiId: " BBName -> ShowS
forall a. [a] -> [a] -> [a]
++ NetlistId -> BBName
forall a. Show a => a -> BBName
show NetlistId
m)
netlistTypes
:: NetlistId
-> [Type]
netlistTypes :: NetlistId -> [Type]
netlistTypes = \case
NetlistId Identifier
_ Type
t -> [Type
t]
CoreId Id
i -> [Id -> Type
forall a. HasType a => a -> Type
coreTypeOf Id
i]
MultiId [Id]
is -> (Id -> Type) -> [Id] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map Id -> Type
forall a. HasType a => a -> Type
coreTypeOf [Id]
is
netlistTypes1
:: HasCallStack
=> NetlistId
-> Type
netlistTypes1 :: HasCallStack => NetlistId -> Type
netlistTypes1 = \case
NetlistId Identifier
_ Type
t -> Type
t
CoreId Id
i -> Id -> Type
forall a. HasType a => a -> Type
coreTypeOf Id
i
NetlistId
m -> BBName -> Type
forall a. HasCallStack => BBName -> a
error (BBName
"netlistTypes1 MultiId: " BBName -> ShowS
forall a. [a] -> [a] -> [a]
++ NetlistId -> BBName
forall a. Show a => a -> BBName
show NetlistId
m)
data DeclarationType
= Concurrent
| Sequential
emptyBBContext :: Text -> BlackBoxContext
emptyBBContext :: Text -> BlackBoxContext
emptyBBContext Text
name
= Context :: Text
-> [(Expr, HWType)]
-> [(Expr, HWType, Bool)]
-> IntMap
[(Either BlackBox (Identifier, [Declaration]), WireOrReg,
[BlackBoxTemplate], [BlackBoxTemplate], [((Text, Text), BlackBox)],
BlackBoxContext)]
-> [Text]
-> BBHash
-> Identifier
-> Maybe Text
-> BlackBoxContext
Context
{ bbName :: Text
bbName = Text
name
, bbResults :: [(Expr, HWType)]
bbResults = []
, bbInputs :: [(Expr, HWType, Bool)]
bbInputs = []
, bbFunctions :: IntMap
[(Either BlackBox (Identifier, [Declaration]), WireOrReg,
[BlackBoxTemplate], [BlackBoxTemplate], [((Text, Text), BlackBox)],
BlackBoxContext)]
bbFunctions = IntMap
[(Either BlackBox (Identifier, [Declaration]), WireOrReg,
[BlackBoxTemplate], [BlackBoxTemplate], [((Text, Text), BlackBox)],
BlackBoxContext)]
forall a. IntMap a
empty
, bbQsysIncName :: [Text]
bbQsysIncName = []
, bbLevel :: BBHash
bbLevel = (-BBHash
1)
, bbCompName :: Identifier
bbCompName = Text
-> Text
-> [Word]
-> IdentifierType
-> HDL
-> CallStack
-> Identifier
UniqueIdentifier
Text
"__NOCOMPNAME__" Text
"__NOCOMPNAME__" []
IdentifierType
Basic HDL
VHDL CallStack
emptyCallStack
, bbCtxName :: Maybe Text
bbCtxName = Maybe Text
forall a. Maybe a
Nothing
}
Lens.makeLenses ''NetlistEnv
Lens.makeLenses ''NetlistState
intWidth :: Lens.Getter NetlistEnv Int
intWidth :: Getter NetlistEnv BBHash
intWidth = (ClashEnv -> f ClashEnv) -> NetlistEnv -> f NetlistEnv
Lens' NetlistEnv ClashEnv
clashEnv ((ClashEnv -> f ClashEnv) -> NetlistEnv -> f NetlistEnv)
-> ((BBHash -> f BBHash) -> ClashEnv -> f ClashEnv)
-> (BBHash -> f BBHash)
-> NetlistEnv
-> f NetlistEnv
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ClashEnv -> BBHash)
-> (BBHash -> f BBHash) -> ClashEnv -> f ClashEnv
forall (p :: Type -> Type -> Type) (f :: Type -> Type) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
Lens.to (ClashOpts -> BBHash
opt_intWidth (ClashOpts -> BBHash)
-> (ClashEnv -> ClashOpts) -> ClashEnv -> BBHash
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClashEnv -> ClashOpts
envOpts)
customReprs :: Lens.Getter NetlistEnv CustomReprs
customReprs :: Getter NetlistEnv CustomReprs
customReprs = (ClashEnv -> f ClashEnv) -> NetlistEnv -> f NetlistEnv
Lens' NetlistEnv ClashEnv
clashEnv ((ClashEnv -> f ClashEnv) -> NetlistEnv -> f NetlistEnv)
-> ((CustomReprs -> f CustomReprs) -> ClashEnv -> f ClashEnv)
-> (CustomReprs -> f CustomReprs)
-> NetlistEnv
-> f NetlistEnv
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ClashEnv -> CustomReprs)
-> (CustomReprs -> f CustomReprs) -> ClashEnv -> f ClashEnv
forall (p :: Type -> Type -> Type) (f :: Type -> Type) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
Lens.to ClashEnv -> CustomReprs
envCustomReprs
tcCache :: Lens.Getter NetlistEnv TyConMap
tcCache :: Getter NetlistEnv TyConMap
tcCache = (ClashEnv -> f ClashEnv) -> NetlistEnv -> f NetlistEnv
Lens' NetlistEnv ClashEnv
clashEnv ((ClashEnv -> f ClashEnv) -> NetlistEnv -> f NetlistEnv)
-> ((TyConMap -> f TyConMap) -> ClashEnv -> f ClashEnv)
-> (TyConMap -> f TyConMap)
-> NetlistEnv
-> f NetlistEnv
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ClashEnv -> TyConMap)
-> (TyConMap -> f TyConMap) -> ClashEnv -> f ClashEnv
forall (p :: Type -> Type -> Type) (f :: Type -> Type) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
Lens.to ClashEnv -> TyConMap
envTyConMap
primitives :: Lens.Getter NetlistEnv CompiledPrimMap
primitives :: Getter NetlistEnv CompiledPrimMap
primitives = (ClashEnv -> f ClashEnv) -> NetlistEnv -> f NetlistEnv
Lens' NetlistEnv ClashEnv
clashEnv ((ClashEnv -> f ClashEnv) -> NetlistEnv -> f NetlistEnv)
-> ((CompiledPrimMap -> f CompiledPrimMap)
-> ClashEnv -> f ClashEnv)
-> (CompiledPrimMap -> f CompiledPrimMap)
-> NetlistEnv
-> f NetlistEnv
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ClashEnv -> CompiledPrimMap)
-> (CompiledPrimMap -> f CompiledPrimMap) -> ClashEnv -> f ClashEnv
forall (p :: Type -> Type -> Type) (f :: Type -> Type) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
Lens.to ClashEnv -> CompiledPrimMap
envPrimitives
clashOpts :: Lens.Getter NetlistEnv ClashOpts
clashOpts :: Getter NetlistEnv ClashOpts
clashOpts = (ClashEnv -> f ClashEnv) -> NetlistEnv -> f NetlistEnv
Lens' NetlistEnv ClashEnv
clashEnv ((ClashEnv -> f ClashEnv) -> NetlistEnv -> f NetlistEnv)
-> ((ClashOpts -> f ClashOpts) -> ClashEnv -> f ClashEnv)
-> (ClashOpts -> f ClashOpts)
-> NetlistEnv
-> f NetlistEnv
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ClashEnv -> ClashOpts)
-> (ClashOpts -> f ClashOpts) -> ClashEnv -> f ClashEnv
forall (p :: Type -> Type -> Type) (f :: Type -> Type) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
Lens.to ClashEnv -> ClashOpts
envOpts
class HasIdentifierSet s where
identifierSet :: Lens' s IdentifierSet
instance HasIdentifierSet IdentifierSet where
identifierSet :: Lens' IdentifierSet IdentifierSet
identifierSet = (IdentifierSet -> f IdentifierSet)
-> IdentifierSet -> f IdentifierSet
forall a b. (a -> b) -> a -> b
($)
class Monad m => IdentifierSetMonad m where
identifierSetM :: (IdentifierSet -> IdentifierSet) -> m IdentifierSet
instance IdentifierSetMonad NetlistMonad where
identifierSetM :: (IdentifierSet -> IdentifierSet) -> NetlistMonad IdentifierSet
identifierSetM IdentifierSet -> IdentifierSet
f = do
IdentifierSet
is0 <- Getting IdentifierSet NetlistState IdentifierSet
-> NetlistMonad IdentifierSet
forall s (m :: Type -> Type) a.
MonadState s m =>
Getting a s a -> m a
Lens.use Getting IdentifierSet NetlistState IdentifierSet
Lens' NetlistState IdentifierSet
seenIds
let is1 :: IdentifierSet
is1 = IdentifierSet -> IdentifierSet
f IdentifierSet
is0
(IdentifierSet -> Identity IdentifierSet)
-> NetlistState -> Identity NetlistState
Lens' NetlistState IdentifierSet
seenIds ((IdentifierSet -> Identity IdentifierSet)
-> NetlistState -> Identity NetlistState)
-> IdentifierSet -> NetlistMonad ()
forall s (m :: Type -> Type) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= IdentifierSet
is1
IdentifierSet -> NetlistMonad IdentifierSet
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure IdentifierSet
is1
{-# INLINE identifierSetM #-}
instance HasIdentifierSet s => IdentifierSetMonad (Strict.State s) where
identifierSetM :: (IdentifierSet -> IdentifierSet) -> State s IdentifierSet
identifierSetM IdentifierSet -> IdentifierSet
f = do
IdentifierSet
is0 <- Getting IdentifierSet s IdentifierSet -> State s IdentifierSet
forall s (m :: Type -> Type) a.
MonadState s m =>
Getting a s a -> m a
Lens.use Getting IdentifierSet s IdentifierSet
forall s. HasIdentifierSet s => Lens' s IdentifierSet
identifierSet
(IdentifierSet -> Identity IdentifierSet) -> s -> Identity s
forall s. HasIdentifierSet s => Lens' s IdentifierSet
identifierSet ((IdentifierSet -> Identity IdentifierSet) -> s -> Identity s)
-> IdentifierSet -> StateT s Identity ()
forall s (m :: Type -> Type) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= IdentifierSet -> IdentifierSet
f IdentifierSet
is0
Getting IdentifierSet s IdentifierSet -> State s IdentifierSet
forall s (m :: Type -> Type) a.
MonadState s m =>
Getting a s a -> m a
Lens.use Getting IdentifierSet s IdentifierSet
forall s. HasIdentifierSet s => Lens' s IdentifierSet
identifierSet
{-# INLINE identifierSetM #-}
instance HasIdentifierSet s => IdentifierSetMonad (Lazy.State s) where
identifierSetM :: (IdentifierSet -> IdentifierSet) -> State s IdentifierSet
identifierSetM IdentifierSet -> IdentifierSet
f = do
IdentifierSet
is0 <- Getting IdentifierSet s IdentifierSet -> State s IdentifierSet
forall s (m :: Type -> Type) a.
MonadState s m =>
Getting a s a -> m a
Lens.use Getting IdentifierSet s IdentifierSet
forall s. HasIdentifierSet s => Lens' s IdentifierSet
identifierSet
(IdentifierSet -> Identity IdentifierSet) -> s -> Identity s
forall s. HasIdentifierSet s => Lens' s IdentifierSet
identifierSet ((IdentifierSet -> Identity IdentifierSet) -> s -> Identity s)
-> IdentifierSet -> StateT s Identity ()
forall s (m :: Type -> Type) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= IdentifierSet -> IdentifierSet
f IdentifierSet
is0
Getting IdentifierSet s IdentifierSet -> State s IdentifierSet
forall s (m :: Type -> Type) a.
MonadState s m =>
Getting a s a -> m a
Lens.use Getting IdentifierSet s IdentifierSet
forall s. HasIdentifierSet s => Lens' s IdentifierSet
identifierSet
{-# INLINE identifierSetM #-}
instance IdentifierSetMonad m => IdentifierSetMonad (Ap m) where
identifierSetM :: (IdentifierSet -> IdentifierSet) -> Ap m IdentifierSet
identifierSetM = m IdentifierSet -> Ap m IdentifierSet
forall {k} (f :: k -> Type) (a :: k). f a -> Ap f a
Ap (m IdentifierSet -> Ap m IdentifierSet)
-> ((IdentifierSet -> IdentifierSet) -> m IdentifierSet)
-> (IdentifierSet -> IdentifierSet)
-> Ap m IdentifierSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (IdentifierSet -> IdentifierSet) -> m IdentifierSet
forall (m :: Type -> Type).
IdentifierSetMonad m =>
(IdentifierSet -> IdentifierSet) -> m IdentifierSet
identifierSetM