diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 770e61ec..d0432143 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -118,7 +118,7 @@ jobs: version: "0.14.0.0" pattern: | **/*.hs - !clash-protocols-base/src/Protocols/Cpp.hs + !clash-protocols-base/src/Protocols/Plugin/Cpp.hs linting: name: Source code linting diff --git a/clash-protocols-base/clash-protocols-base.cabal b/clash-protocols-base/clash-protocols-base.cabal index 8c2f8be3..d9a19475 100644 --- a/clash-protocols-base/clash-protocols-base.cabal +++ b/clash-protocols-base/clash-protocols-base.cabal @@ -111,15 +111,16 @@ library , template-haskell exposed-modules: - Protocols.Circuit - Protocols.Cpp - Protocols.Internal.TaggedBundle - Protocols.Internal.TaggedBundle.TH - Protocols.Internal.Types - Protocols.Internal.Units - Protocols.Internal.Units.TH Protocols.Plugin + Protocols.Plugin.Cpp Protocols.Plugin.Internal - Protocols.Protocol.TH + Protocols.Plugin.TaggedBundle + Protocols.Plugin.Units + + other-modules: + Protocols.Plugin.TH + Protocols.Plugin.Units.TH + Protocols.Plugin.TaggedBundle.TH + Protocols.Plugin.Types default-language: Haskell2010 diff --git a/clash-protocols-base/src/Protocols/Circuit.hs b/clash-protocols-base/src/Protocols/Circuit.hs deleted file mode 100644 index 71e129e8..00000000 --- a/clash-protocols-base/src/Protocols/Circuit.hs +++ /dev/null @@ -1,38 +0,0 @@ -{-# OPTIONS_GHC -Wno-dodgy-exports #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} - -module Protocols.Circuit ( - module Protocols.Internal.Types - ) where - -import Clash.Signal -import Clash.Sized.Vector -import GHC.TypeNats (KnownNat) -import Protocols.Cpp (maxTupleSize) -import Protocols.Internal.Types -import Protocols.Protocol.TH - -instance Protocol () where - type Fwd () = () - type Bwd () = () - -{- | __NB__: The documentation only shows instances up to /3/-tuples. By -default, instances up to and including /12/-tuples will exist. If the flag -@large-tuples@ is set instances up to the GHC imposed limit will exist. The -GHC imposed limit is either 62 or 64 depending on the GHC version. --} -instance Protocol (a, b) where - type Fwd (a, b) = (Fwd a, Fwd b) - type Bwd (a, b) = (Bwd a, Bwd b) - --- Generate n-tuple instances, where n > 2 -protocolTupleInstances 3 maxTupleSize - -instance (KnownNat n) => Protocol (Vec n a) where - type Fwd (Vec n a) = Vec n (Fwd a) - type Bwd (Vec n a) = Vec n (Bwd a) - --- XXX: Type families with Signals on LHS are currently broken on Clash: -instance Protocol (CSignal dom a) where - type Fwd (CSignal dom a) = Signal dom a - type Bwd (CSignal dom a) = Signal dom () diff --git a/clash-protocols-base/src/Protocols/Plugin.hs b/clash-protocols-base/src/Protocols/Plugin.hs index 6baa1547..c458217b 100644 --- a/clash-protocols-base/src/Protocols/Plugin.hs +++ b/clash-protocols-base/src/Protocols/Plugin.hs @@ -1,11 +1,15 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternSynonyms #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} {- | A GHC source plugin providing a DSL for writing Circuit components. Credits to @circuit-notation@ at . -} module Protocols.Plugin ( + Circuit (..), + Protocol (..), + CSignal, plugin, circuit, (-<), @@ -14,11 +18,16 @@ module Protocols.Plugin ( -- base import Prelude +-- clash-prelude +import qualified Clash.Explicit.Prelude as C + -- clash-protocols -import Protocols.Internal.Types -import Protocols.Internal.TaggedBundle -import Protocols.Internal.Units +import Protocols.Plugin.Cpp import Protocols.Plugin.Internal +import Protocols.Plugin.TH +import Protocols.Plugin.TaggedBundle +import Protocols.Plugin.Types +import Protocols.Plugin.Units -- circuit-notation import qualified CircuitNotation as CN @@ -29,6 +38,31 @@ import Data.Tagged -- ghc import qualified GHC.Plugins as GHC +instance Protocol () where + type Fwd () = () + type Bwd () = () + +{- | __NB__: The documentation only shows instances up to /3/-tuples. By +default, instances up to and including /12/-tuples will exist. If the flag +@large-tuples@ is set instances up to the GHC imposed limit will exist. The +GHC imposed limit is either 62 or 64 depending on the GHC version. +-} +instance Protocol (a, b) where + type Fwd (a, b) = (Fwd a, Fwd b) + type Bwd (a, b) = (Bwd a, Bwd b) + +-- Generate n-tuple instances, where n > 2 +protocolTupleInstances 3 maxTupleSize + +instance (C.KnownNat n) => Protocol (C.Vec n a) where + type Fwd (C.Vec n a) = C.Vec n (Fwd a) + type Bwd (C.Vec n a) = C.Vec n (Bwd a) + +-- XXX: Type families with Signals on LHS are currently broken on Clash: +instance Protocol (CSignal dom a) where + type Fwd (CSignal dom a) = C.Signal dom a + type Bwd (CSignal dom a) = C.Signal dom () + -- | @circuit-notation@ plugin repurposed for "Protocols". plugin :: GHC.Plugin plugin = diff --git a/clash-protocols-base/src/Protocols/Cpp.hs b/clash-protocols-base/src/Protocols/Plugin/Cpp.hs similarity index 96% rename from clash-protocols-base/src/Protocols/Cpp.hs rename to clash-protocols-base/src/Protocols/Plugin/Cpp.hs index 82646320..4877c986 100644 --- a/clash-protocols-base/src/Protocols/Cpp.hs +++ b/clash-protocols-base/src/Protocols/Plugin/Cpp.hs @@ -12,7 +12,7 @@ Compile-time dependent constants. Inspired by @clash-prelude@'s @Clash.CPP@. {-# OPTIONS_HADDOCK hide #-} -module Protocols.Cpp +module Protocols.Plugin.Cpp ( maxTupleSize , haddockOnly ) where diff --git a/clash-protocols-base/src/Protocols/Plugin/Internal.hs b/clash-protocols-base/src/Protocols/Plugin/Internal.hs index f74f08b3..9b328694 100644 --- a/clash-protocols-base/src/Protocols/Plugin/Internal.hs +++ b/clash-protocols-base/src/Protocols/Plugin/Internal.hs @@ -8,7 +8,7 @@ import Clash.Explicit.Prelude import Data.Tagged import GHC.Base (Any) -import Protocols.Internal.Types +import Protocols.Plugin.Types {- | Picked up by "Protocols.Plugin" to process protocol DSL. See "Protocols.Plugin" for more information. diff --git a/clash-protocols-base/src/Protocols/Protocol/TH.hs b/clash-protocols-base/src/Protocols/Plugin/TH.hs similarity index 96% rename from clash-protocols-base/src/Protocols/Protocol/TH.hs rename to clash-protocols-base/src/Protocols/Plugin/TH.hs index 7a77712a..dcd202e9 100644 --- a/clash-protocols-base/src/Protocols/Protocol/TH.hs +++ b/clash-protocols-base/src/Protocols/Plugin/TH.hs @@ -1,6 +1,7 @@ {-# OPTIONS_HADDOCK hide #-} -module Protocols.Protocol.TH where +module Protocols.Plugin.TH where + import Language.Haskell.TH appTs :: Q Type -> [Q Type] -> Q Type diff --git a/clash-protocols-base/src/Protocols/Internal/TaggedBundle.hs b/clash-protocols-base/src/Protocols/Plugin/TaggedBundle.hs similarity index 92% rename from clash-protocols-base/src/Protocols/Internal/TaggedBundle.hs rename to clash-protocols-base/src/Protocols/Plugin/TaggedBundle.hs index d2f6d3b4..78db9f0e 100644 --- a/clash-protocols-base/src/Protocols/Internal/TaggedBundle.hs +++ b/clash-protocols-base/src/Protocols/Plugin/TaggedBundle.hs @@ -6,12 +6,12 @@ -- For debugging TH: -- {-# OPTIONS_GHC -ddump-splices #-} -module Protocols.Internal.TaggedBundle where +module Protocols.Plugin.TaggedBundle where import Clash.Explicit.Prelude -import Protocols.Cpp (maxTupleSize) -import Protocols.Internal.TaggedBundle.TH (taggedBundleTupleInstances) +import Protocols.Plugin.Cpp (maxTupleSize) +import Protocols.Plugin.TaggedBundle.TH (taggedBundleTupleInstances) import Data.Tagged diff --git a/clash-protocols-base/src/Protocols/Internal/TaggedBundle/TH.hs b/clash-protocols-base/src/Protocols/Plugin/TaggedBundle/TH.hs similarity index 97% rename from clash-protocols-base/src/Protocols/Internal/TaggedBundle/TH.hs rename to clash-protocols-base/src/Protocols/Plugin/TaggedBundle/TH.hs index bcca01c4..67b41588 100644 --- a/clash-protocols-base/src/Protocols/Internal/TaggedBundle/TH.hs +++ b/clash-protocols-base/src/Protocols/Plugin/TaggedBundle/TH.hs @@ -1,6 +1,6 @@ {-# OPTIONS_HADDOCK hide #-} -module Protocols.Internal.TaggedBundle.TH where +module Protocols.Plugin.TaggedBundle.TH where import Data.Tagged import Language.Haskell.TH diff --git a/clash-protocols-base/src/Protocols/Internal/Types.hs b/clash-protocols-base/src/Protocols/Plugin/Types.hs similarity index 84% rename from clash-protocols-base/src/Protocols/Internal/Types.hs rename to clash-protocols-base/src/Protocols/Plugin/Types.hs index 6161c075..5463defe 100644 --- a/clash-protocols-base/src/Protocols/Internal/Types.hs +++ b/clash-protocols-base/src/Protocols/Plugin/Types.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE RoleAnnotations #-} + {- | These class definitions are needed to be able to write Template Haskell quotes for instances. They are defined separately to avoid import loops. @@ -5,12 +7,10 @@ for instances. They are defined separately to avoid import loops. This module is not exported; the classes and their (orphan) instances are exported elsewhere. -} -{-# LANGUAGE RoleAnnotations #-} -module Protocols.Internal.Types where +module Protocols.Plugin.Types where import Clash.Signal import Data.Kind (Type) -import Data.Proxy -- | A protocol describes the in- and outputs of one side of a 'Circuit'. class Protocol a where @@ -135,13 +135,6 @@ types: newtype Circuit a b = Circuit ((Fwd a, Bwd b) -> (Bwd a, Fwd b)) -{- | Idle state of a Circuit. Aims to provide no data for both the forward and -backward direction. Transactions are not acknowledged. --} -class (Protocol p) => IdleCircuit p where - idleFwd :: Proxy p -> Fwd (p :: Type) - idleBwd :: Proxy p -> Bwd (p :: Type) - {- | Circuit protocol with /Signal dom a/ in its forward direction, and /()/ in its backward direction. Convenient for exposing protocol internals, or simply for undirectional streams. @@ -151,30 +144,3 @@ Note: 'CSignal' exists to work around [issue 760](https://github.com/clash-lang/ data CSignal (dom :: Domain) (a :: Type) type role CSignal nominal representational - -{- | Force a /nack/ on the backward channel and /no data/ on the forward -channel if reset is asserted. --} -forceResetSanityGeneric :: - forall dom a fwd bwd. - ( KnownDomain dom - , HiddenReset dom - , IdleCircuit a - , Fwd a ~ Signal dom fwd - , Bwd a ~ Signal dom bwd - ) => - Circuit a a -forceResetSanityGeneric = Circuit go - where - go (fwd, bwd) = - unbundle $ - mux - rstAsserted - (bundle (idleBwd $ Proxy @a, idleFwd $ Proxy @a)) - (bundle (bwd, fwd)) - -#if MIN_VERSION_clash_prelude(1,8,0) - rstAsserted = unsafeToActiveHigh hasReset -#else - rstAsserted = unsafeToHighPolarity hasReset -#endif diff --git a/clash-protocols-base/src/Protocols/Internal/Units.hs b/clash-protocols-base/src/Protocols/Plugin/Units.hs similarity index 90% rename from clash-protocols-base/src/Protocols/Internal/Units.hs rename to clash-protocols-base/src/Protocols/Plugin/Units.hs index e5b29e03..9da0ab58 100644 --- a/clash-protocols-base/src/Protocols/Internal/Units.hs +++ b/clash-protocols-base/src/Protocols/Plugin/Units.hs @@ -5,12 +5,12 @@ -- For debugging TH: -- {-# OPTIONS_GHC -ddump-splices #-} -module Protocols.Internal.Units where +module Protocols.Plugin.Units where import Clash.Explicit.Prelude -import Protocols.Cpp (maxTupleSize) -import Protocols.Internal.Units.TH (unitsTupleInstances) +import Protocols.Plugin.Cpp (maxTupleSize) +import Protocols.Plugin.Units.TH (unitsTupleInstances) {- | Utilities for zero-width types. Is used by "Protocols.Plugin" to drive \"trivial\" backwards channels. diff --git a/clash-protocols-base/src/Protocols/Internal/Units/TH.hs b/clash-protocols-base/src/Protocols/Plugin/Units/TH.hs similarity index 91% rename from clash-protocols-base/src/Protocols/Internal/Units/TH.hs rename to clash-protocols-base/src/Protocols/Plugin/Units/TH.hs index c8c51dee..7841fb10 100644 --- a/clash-protocols-base/src/Protocols/Internal/Units/TH.hs +++ b/clash-protocols-base/src/Protocols/Plugin/Units/TH.hs @@ -1,6 +1,6 @@ {-# OPTIONS_HADDOCK hide #-} -module Protocols.Internal.Units.TH (unitsTupleInstances) where +module Protocols.Plugin.Units.TH (unitsTupleInstances) where import Language.Haskell.TH diff --git a/clash-protocols/clash-protocols.cabal b/clash-protocols/clash-protocols.cabal index 71ed3503..9c2a62b3 100644 --- a/clash-protocols/clash-protocols.cabal +++ b/clash-protocols/clash-protocols.cabal @@ -165,6 +165,7 @@ library autogen-modules: Paths_clash_protocols other-modules: + Protocols.Internal.Types Paths_clash_protocols default-language: Haskell2010 diff --git a/clash-protocols/src/Protocols.hs b/clash-protocols/src/Protocols.hs index 0d2b1aff..ddbcfd91 100644 --- a/clash-protocols/src/Protocols.hs +++ b/clash-protocols/src/Protocols.hs @@ -59,12 +59,13 @@ module Protocols ( -- * Circuit notation plugin circuit, (-<), - module Protocols.Internal.Units, - module Protocols.Internal.TaggedBundle, + module Protocols.Plugin.Units, + module Protocols.Plugin.TaggedBundle, ) where import Data.Default (def) import Protocols.Df (Df) import Protocols.Internal -import Protocols.Internal.TaggedBundle -import Protocols.Internal.Units +import Protocols.Plugin +import Protocols.Plugin.TaggedBundle +import Protocols.Plugin.Units diff --git a/clash-protocols/src/Protocols/Avalon/MemMap.hs b/clash-protocols/src/Protocols/Avalon/MemMap.hs index bf100b57..1ca23cae 100644 --- a/clash-protocols/src/Protocols/Avalon/MemMap.hs +++ b/clash-protocols/src/Protocols/Avalon/MemMap.hs @@ -106,6 +106,7 @@ import qualified Clash.Prelude as C import qualified Protocols.DfConv as DfConv import Protocols.Idle import Protocols.Internal +import Protocols.Plugin {- | Config needed for both manager and subordinate interfaces. @Bool@ values represent whether to keep a boolean field or not. diff --git a/clash-protocols/src/Protocols/Avalon/Stream.hs b/clash-protocols/src/Protocols/Avalon/Stream.hs index af5167d0..ab2932a0 100644 --- a/clash-protocols/src/Protocols/Avalon/Stream.hs +++ b/clash-protocols/src/Protocols/Avalon/Stream.hs @@ -32,6 +32,7 @@ import qualified Protocols.DfConv as DfConv import Protocols.Hedgehog.Internal import Protocols.Idle import Protocols.Internal +import Protocols.Plugin instance Hashable (C.Unsigned n) diff --git a/clash-protocols/src/Protocols/Axi4/ReadAddress.hs b/clash-protocols/src/Protocols/Axi4/ReadAddress.hs index e165fb92..3703051d 100644 --- a/clash-protocols/src/Protocols/Axi4/ReadAddress.hs +++ b/clash-protocols/src/Protocols/Axi4/ReadAddress.hs @@ -49,7 +49,9 @@ import qualified Clash.Prelude as C -- me import Protocols.Axi4.Common +import Protocols.Idle import Protocols.Internal +import Protocols.Plugin -- | Configuration options for 'Axi4ReadAddress'. data Axi4ReadAddressConfig = Axi4ReadAddressConfig diff --git a/clash-protocols/src/Protocols/Axi4/ReadData.hs b/clash-protocols/src/Protocols/Axi4/ReadData.hs index 4d9d27d7..036272b2 100644 --- a/clash-protocols/src/Protocols/Axi4/ReadData.hs +++ b/clash-protocols/src/Protocols/Axi4/ReadData.hs @@ -48,6 +48,7 @@ import qualified Clash.Prelude as C import Protocols.Axi4.Common import Protocols.Idle import Protocols.Internal +import Protocols.Plugin -- | Configuration options for 'Axi4ReadData'. data Axi4ReadDataConfig = Axi4ReadDataConfig diff --git a/clash-protocols/src/Protocols/Axi4/Stream.hs b/clash-protocols/src/Protocols/Axi4/Stream.hs index 4c093d8d..7484eb84 100644 --- a/clash-protocols/src/Protocols/Axi4/Stream.hs +++ b/clash-protocols/src/Protocols/Axi4/Stream.hs @@ -27,7 +27,9 @@ import qualified Clash.Prelude as C import qualified Protocols.Df as Df import qualified Protocols.DfConv as DfConv import Protocols.Hedgehog.Internal +import Protocols.Idle import Protocols.Internal +import Protocols.Plugin instance (KnownNat n) => Hashable (Unsigned n) instance (KnownNat n, Hashable a) => Hashable (Vec n a) where diff --git a/clash-protocols/src/Protocols/Axi4/WriteAddress.hs b/clash-protocols/src/Protocols/Axi4/WriteAddress.hs index 6ebb67d3..8abc2e02 100644 --- a/clash-protocols/src/Protocols/Axi4/WriteAddress.hs +++ b/clash-protocols/src/Protocols/Axi4/WriteAddress.hs @@ -47,7 +47,9 @@ import qualified Clash.Prelude as C -- me import Protocols.Axi4.Common +import Protocols.Idle import Protocols.Internal +import Protocols.Plugin -- | Configuration options for 'Axi4WriteAddress'. data Axi4WriteAddressConfig = Axi4WriteAddressConfig diff --git a/clash-protocols/src/Protocols/Axi4/WriteData.hs b/clash-protocols/src/Protocols/Axi4/WriteData.hs index 3bfc207d..2ff797bb 100644 --- a/clash-protocols/src/Protocols/Axi4/WriteData.hs +++ b/clash-protocols/src/Protocols/Axi4/WriteData.hs @@ -45,6 +45,7 @@ import qualified Clash.Prelude as C import Protocols.Axi4.Common import Protocols.Idle import Protocols.Internal +import Protocols.Plugin -- | Configuration options for 'Axi4WriteData'. data Axi4WriteDataConfig = Axi4WriteDataConfig diff --git a/clash-protocols/src/Protocols/Axi4/WriteResponse.hs b/clash-protocols/src/Protocols/Axi4/WriteResponse.hs index 53b46c13..a2304e9e 100644 --- a/clash-protocols/src/Protocols/Axi4/WriteResponse.hs +++ b/clash-protocols/src/Protocols/Axi4/WriteResponse.hs @@ -33,6 +33,7 @@ import qualified Clash.Prelude as C import Protocols.Axi4.Common import Protocols.Idle import Protocols.Internal +import Protocols.Plugin -- | Configuration options for 'Axi4WriteResponse'. data Axi4WriteResponseConfig = Axi4WriteResponseConfig diff --git a/clash-protocols/src/Protocols/Df.hs b/clash-protocols/src/Protocols/Df.hs index 98a31be8..2ff0a351 100644 --- a/clash-protocols/src/Protocols/Df.hs +++ b/clash-protocols/src/Protocols/Df.hs @@ -129,7 +129,9 @@ import qualified Clash.Prelude as C import Clash.Signal.Internal (Signal (..)) -- me +import Protocols.Idle import Protocols.Internal +import Protocols.Plugin {-# ANN module "HLint: ignore Use const" #-} diff --git a/clash-protocols/src/Protocols/DfConv.hs b/clash-protocols/src/Protocols/DfConv.hs index e6eccc95..40ee51c6 100644 --- a/clash-protocols/src/Protocols/DfConv.hs +++ b/clash-protocols/src/Protocols/DfConv.hs @@ -115,6 +115,7 @@ import Protocols.Axi4.WriteResponse import Protocols.Df (Data (..), Df) import qualified Protocols.Df as Df import Protocols.Internal +import Protocols.Plugin {- | Class for protocols that are "similar" to 'Df', i.e. they can be converted to and from a pair of 'Df' ports (one going 'Fwd', one going 'Bwd'), using diff --git a/clash-protocols/src/Protocols/Idle.hs b/clash-protocols/src/Protocols/Idle.hs index 6f7e6114..7e6f48f8 100644 --- a/clash-protocols/src/Protocols/Idle.hs +++ b/clash-protocols/src/Protocols/Idle.hs @@ -4,24 +4,31 @@ Functionalities to easily create idle circuits for protocols. -} module Protocols.Idle ( + -- * Type classes IdleCircuit (..), + + -- * Utility functions idleSource, idleSink, + forceResetSanityGeneric, ) where -import qualified Clash.Prelude as C +import Clash.Prelude +import Prelude () + import Data.Proxy -import Protocols.Cpp (maxTupleSize) import Protocols.Internal import Protocols.Internal.TH (idleCircuitTupleInstances) +import Protocols.Plugin +import Protocols.Plugin.Cpp (maxTupleSize) instance (IdleCircuit a, IdleCircuit b) => IdleCircuit (a, b) where idleFwd _ = (idleFwd $ Proxy @a, idleFwd $ Proxy @b) idleBwd _ = (idleBwd $ Proxy @a, idleBwd $ Proxy @b) -instance (IdleCircuit a, C.KnownNat n) => IdleCircuit (C.Vec n a) where - idleFwd _ = C.repeat $ idleFwd $ Proxy @a - idleBwd _ = C.repeat $ idleBwd $ Proxy @a +instance (IdleCircuit a, KnownNat n) => IdleCircuit (Vec n a) where + idleFwd _ = repeat $ idleFwd $ Proxy @a + idleBwd _ = repeat $ idleBwd $ Proxy @a instance IdleCircuit () where idleFwd _ = () @@ -37,3 +44,30 @@ idleSource = Circuit $ const ((), idleFwd $ Proxy @p) -- | Idle state of a sink, this circuit does not consume any data. idleSink :: forall p. (IdleCircuit p) => Circuit p () idleSink = Circuit $ const (idleBwd $ Proxy @p, ()) + +{- | Force a /nack/ on the backward channel and /no data/ on the forward +channel if reset is asserted. +-} +forceResetSanityGeneric :: + forall dom a fwd bwd. + ( KnownDomain dom + , HiddenReset dom + , IdleCircuit a + , Fwd a ~ Signal dom fwd + , Bwd a ~ Signal dom bwd + ) => + Circuit a a +forceResetSanityGeneric = Circuit go + where + go (fwd, bwd) = + unbundle + $ mux + rstAsserted + (bundle (idleBwd $ Proxy @a, idleFwd $ Proxy @a)) + (bundle (bwd, fwd)) + +#if MIN_VERSION_clash_prelude(1,8,0) + rstAsserted = unsafeToActiveHigh hasReset +#else + rstAsserted = unsafeToHighPolarity hasReset +#endif diff --git a/clash-protocols/src/Protocols/Internal.hs b/clash-protocols/src/Protocols/Internal.hs index 4e1dcc3c..bb592f5a 100644 --- a/clash-protocols/src/Protocols/Internal.hs +++ b/clash-protocols/src/Protocols/Internal.hs @@ -22,15 +22,14 @@ import Control.DeepSeq (NFData) import Data.Hashable (Hashable) import Data.Maybe (fromMaybe) import Data.Proxy -import GHC.Base (Any) import Prelude hiding (const, map) import qualified Clash.Explicit.Prelude as CE import Clash.Prelude (type (*), type (+)) import qualified Clash.Prelude as C -import Protocols.Circuit import Protocols.Internal.Types +import Protocols.Plugin import Control.Arrow ((***)) import Data.Coerce (coerce) @@ -573,20 +572,6 @@ simulateCircuit fwds bwds circ = toSignals circ $ (simToSigFwd (Proxy @a) fwds, simToSigBwd (Proxy @b) bwds) -{- | Picked up by "Protocols.Plugin" to process protocol DSL. See -"Protocols.Plugin" for more information. --} -circuit :: Any -circuit = - error "'protocol' called: did you forget to enable \"Protocols.Plugin\"?" - -{- | Picked up by "Protocols.Plugin" to tie circuits together. See -"Protocols.Plugin" for more information. --} -(-<) :: Any -(-<) = - error "(-<) called: did you forget to enable \"Protocols.Plugin\"?" - {- | Allows for optional data. Depending on the value of @keep@, the data can either be included or left out. When left out, the data is represented instead as type @()@. diff --git a/clash-protocols/src/Protocols/Internal/TH.hs b/clash-protocols/src/Protocols/Internal/TH.hs index fe42c581..4d3f43f3 100644 --- a/clash-protocols/src/Protocols/Internal/TH.hs +++ b/clash-protocols/src/Protocols/Internal/TH.hs @@ -4,7 +4,6 @@ module Protocols.Internal.TH where import Control.Monad.Extra (concatMapM) import Language.Haskell.TH - import Protocols.Internal.Types appTs :: Q Type -> [Q Type] -> Q Type diff --git a/clash-protocols/src/Protocols/Internal/Types.hs b/clash-protocols/src/Protocols/Internal/Types.hs new file mode 100644 index 00000000..8303818e --- /dev/null +++ b/clash-protocols/src/Protocols/Internal/Types.hs @@ -0,0 +1,12 @@ +module Protocols.Internal.Types where + +import Data.Proxy +import GHC.Base (Type) +import Protocols.Plugin + +{- | Idle state of a Circuit. Aims to provide no data for both the forward and +backward direction. Transactions are not acknowledged. +-} +class (Protocol p) => IdleCircuit p where + idleFwd :: Proxy p -> Fwd (p :: Type) + idleBwd :: Proxy p -> Bwd (p :: Type) diff --git a/clash-protocols/src/Protocols/Wishbone.hs b/clash-protocols/src/Protocols/Wishbone.hs index 79d6ccad..689d26d1 100644 --- a/clash-protocols/src/Protocols/Wishbone.hs +++ b/clash-protocols/src/Protocols/Wishbone.hs @@ -15,7 +15,7 @@ import Prelude hiding (head, not, (&&)) import Clash.Signal.Internal (Signal (..)) import Control.DeepSeq (NFData) import Protocols -import Protocols.Internal.Types +import Protocols.Idle import qualified Clash.Prelude as C diff --git a/format.sh b/format.sh index 3c39cb99..5f899790 100755 --- a/format.sh +++ b/format.sh @@ -24,7 +24,7 @@ if [[ "$#" -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then fi exclude_files=( - "clash-protocols-base/src/Protocols/Cpp.hs" + "clash-protocols-base/src/Protocols/Plugin/Cpp.hs" "dist-newstyle" )