Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow newer Clash #56

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
os: [ubuntu-latest]
clash:
- "1.6.1"
- "1.8.1"
cabal:
- "3.6"
ghc:
Expand Down
3 changes: 2 additions & 1 deletion clash-protocols.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ common common-options
BangPatterns
BinaryLiterals
ConstraintKinds
CPP
DataKinds
DefaultSignatures
DeriveAnyClass
Expand Down Expand Up @@ -87,7 +88,7 @@ common common-options
Cabal,

-- clash-prelude will set suitable version bounds for the plugins
clash-prelude >= 1.4.0 && < 1.8,
clash-prelude >= 1.4.0 && < 1.10,
ghc-typelits-natnormalise,
ghc-typelits-extra,
ghc-typelits-knownnat
Expand Down
43 changes: 38 additions & 5 deletions src/Protocols/Df.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ forceResetSanity
where
f (True, _, _ ) = (Ack False, NoData)
f (False, fwd, bwd) = (bwd, fwd)
#if MIN_VERSION_clash_prelude(1,8,0)
rstLow = C.unsafeToActiveHigh C.hasReset
#else
rstLow = C.unsafeToHighPolarity C.hasReset
#endif

-- | Like 'P.map', but over payload (/a/) of a Df stream.
map :: (a -> b) -> Circuit (Df dom a) (Df dom b)
Expand Down Expand Up @@ -208,15 +212,31 @@ second f = map (B.second f)

-- | Acknowledge but ignore data from LHS protocol. Send a static value /b/.
const :: C.HiddenReset dom => b -> Circuit (Df dom a) (Df dom b)
const b = Circuit (P.const (Ack <$> C.unsafeToLowPolarity C.hasReset, P.pure (Data b)))
const b = Circuit (P.const (Ack <$>
#if MIN_VERSION_clash_prelude(1,8,0)
C.unsafeToActiveLow C.hasReset
#else
C.unsafeToLowPolarity C.hasReset
#endif
, P.pure (Data b)
)
)

-- | Drive a constant value composed of /a/.
pure :: a -> Circuit () (Df dom a)
pure a = Circuit (P.const ((), P.pure (Data a)))

-- | Drive a constant value composed of /a/.
void :: C.HiddenReset dom => Circuit (Df dom a) ()
void = Circuit (P.const (Ack <$> C.unsafeToLowPolarity C.hasReset, ()))
void = Circuit (P.const (Ack <$>
#if MIN_VERSION_clash_prelude(1,8,0)
C.unsafeToActiveLow C.hasReset
#else
C.unsafeToLowPolarity C.hasReset
#endif
, ()
)
)

-- | Like 'Data.Maybe.catMaybes', but over a Df stream.
--
Expand Down Expand Up @@ -659,7 +679,15 @@ fifo fifoDepth = Circuit $ C.hideReset circuitFunction where
(brReadAddr, brWrite, otpA, otpB)
= C.unbundle
$ C.mealy machineAsFunction s0
$ C.bundle (brRead, C.unsafeToHighPolarity reset, inpA, inpB)
$ C.bundle ( brRead
#if MIN_VERSION_clash_prelude(1,8,0)
, C.unsafeToActiveHigh reset
#else
, C.unsafeToHighPolarity reset
#endif
, inpA
, inpB
)

-- when reset is on, set state to initial state and output blank outputs
machineAsFunction _ (_, True, _, _) = (s0, (0, Nothing, Ack False, NoData))
Expand Down Expand Up @@ -835,5 +863,10 @@ simulate conf@SimulationConfig{..} circ inputs =
-- | Like 'C.resetGenN', but works on 'Int' instead of 'C.SNat'. Not
-- synthesizable.
resetGen :: C.KnownDomain dom => Int -> C.Reset dom
resetGen n = C.unsafeFromHighPolarity
(C.fromList (replicate n True <> repeat False))
resetGen n =
#if MIN_VERSION_clash_prelude(1,8,0)
C.unsafeFromActiveHigh
#else
C.unsafeFromHighPolarity
#endif
(C.fromList (replicate n True <> repeat False))
10 changes: 9 additions & 1 deletion src/Protocols/DfConv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,15 @@ toDfCircuitHelper _ s0 blankOtp stateFn
. bundle
. (bundle *** bundle)
where
cktFn reset inp = mealy transFn s0 ((,) <$> unsafeToHighPolarity reset <*> inp)
cktFn reset inp =
let rstLow =
#if MIN_VERSION_clash_prelude(1,8,0)
unsafeToActiveHigh reset
#else
unsafeToHighPolarity reset
#endif
in mealy transFn s0 ((,) <$> rstLow <*> inp)

transFn _ (True, _) = (s0, ((Ack False, NoData), blankOtp))
transFn s (False, ((toOtp, Ack inpAck), inp)) = let
((otp, inputted, otpAck), s') = runState
Expand Down
7 changes: 6 additions & 1 deletion src/Protocols/Hedgehog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ data StallMode = NoStall | Stall
-- | Like 'C.resetGenN', but works on 'Int' instead of 'C.SNat'. Not
-- synthesizable.
resetGen :: C.KnownDomain dom => Int -> C.Reset dom
resetGen n = C.unsafeFromHighPolarity
resetGen n =
#if MIN_VERSION_clash_prelude(1,8,0)
C.unsafeFromActiveHigh
#else
C.unsafeFromHighPolarity
#endif
(C.fromList (replicate n True <> repeat False))

-- | Test a protocol against a pure model implementation. Circuit under test will
Expand Down
8 changes: 7 additions & 1 deletion src/Protocols/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,13 @@ simulateCSE c = simulateCS (c clk rst ena)
rst = resetGen (resetCycles def)
ena = C.enableGen

resetGen n = C.unsafeFromHighPolarity (C.fromList (replicate n True <> repeat False))
resetGen n =
#if MIN_VERSION_clash_prelude(1,8,0)
C.unsafeFromActiveHigh
#else
C.unsafeFromHighPolarity
#endif
$ C.fromList (replicate n True <> repeat False)

-- | Applies conversion functions defined in the 'Simulate' instance of @a@ and @b@ to
-- the given simulation types, and applies the results to the internal function of the
Expand Down
Loading