@@ -117,8 +117,8 @@ import Clash.Annotations.Primitive (HDL (..), Primitive (..))
117117import Clash.Annotations.SynthesisAttributes (Attr )
118118import Clash.Backend hiding (Usage , fromBV , toBV )
119119import Clash.Backend.VHDL (VHDLState )
120- import Clash.Explicit.Signal (ResetPolarity (.. ))
121- import Clash.Netlist.BlackBox.Util (exprToString , renderElem )
120+ import Clash.Explicit.Signal (ResetPolarity (.. ), vResetPolarity )
121+ import Clash.Netlist.BlackBox.Util (exprToString , getDomainConf , renderElem )
122122import Clash.Netlist.BlackBox.Types
123123 (BlackBoxTemplate , Element (Component , Text ), Decl (.. ))
124124import qualified Clash.Netlist.Id as Id
@@ -203,6 +203,17 @@ instance Backend backend => HasIdentifierSet (BlockState backend) where
203203instance HasUsageMap backend => HasUsageMap (BlockState backend ) where
204204 usageMap = bsBackend. usageMap
205205
206+ liftToBlockState
207+ :: forall backend a . Backend backend
208+ => State backend a -> State (BlockState backend ) a
209+ liftToBlockState (StateT f) = StateT g
210+ where
211+ g :: BlockState backend -> Identity (a , BlockState backend )
212+ g sbsIn = do
213+ let sIn = _bsBackend sbsIn
214+ (res,sOut) <- f sIn
215+ pure (res, sbsIn{_bsBackend = sOut})
216+
206217-- | A typed expression.
207218data TExpr = TExpr
208219 { ety :: HWType
@@ -992,32 +1003,26 @@ unsafeToActiveHigh
9921003 :: Backend backend
9931004 => Text
9941005 -- ^ Name hint
995- -> HWType
996- -- ^ 'KnownDomain'
9971006 -> TExpr
9981007 -- ^ Reset signal
9991008 -> State (BlockState backend ) TExpr
1000- unsafeToActiveHigh nm dom rExpr =
1001- case extrResetPolarity dom of
1009+ unsafeToActiveHigh nm rExpr = do
1010+ resetLevel <- vResetPolarity <$> liftToBlockState (getDomainConf (ety rExpr))
1011+ case resetLevel of
10021012 ActiveHigh -> pure rExpr
10031013 ActiveLow -> notExpr nm rExpr
10041014
1005- extrResetPolarity :: HWType -> ResetPolarity
1006- extrResetPolarity (Void (Just (KnownDomain _ _ _ _ _ p))) = p
1007- extrResetPolarity p = error (" Internal error: expected KnownDomain, got: " <> show p)
1008-
10091015-- | Massage a reset to work as active-low reset.
10101016unsafeToActiveLow
10111017 :: Backend backend
10121018 => Text
10131019 -- ^ Name hint
1014- -> HWType
1015- -- ^ 'KnownDomain'
10161020 -> TExpr
10171021 -- ^ Reset signal
10181022 -> State (BlockState backend ) TExpr
1019- unsafeToActiveLow nm dom rExpr =
1020- case extrResetPolarity dom of
1023+ unsafeToActiveLow nm rExpr = do
1024+ resetLevel <- vResetPolarity <$> liftToBlockState (getDomainConf (ety rExpr))
1025+ case resetLevel of
10211026 ActiveLow -> pure rExpr
10221027 ActiveHigh -> notExpr nm rExpr
10231028
0 commit comments