@@ -118,8 +118,8 @@ import Clash.Annotations.Primitive (HDL (..), Primitive (..))
118118import Clash.Annotations.SynthesisAttributes (Attr )
119119import Clash.Backend hiding (Usage , fromBV , toBV )
120120import Clash.Backend.VHDL (VHDLState )
121- import Clash.Explicit.Signal (ResetPolarity (.. ))
122- import Clash.Netlist.BlackBox.Util (exprToString , renderElem )
121+ import Clash.Explicit.Signal (ResetPolarity (.. ), vResetPolarity )
122+ import Clash.Netlist.BlackBox.Util (exprToString , getDomainConf , renderElem )
123123import Clash.Netlist.BlackBox.Types
124124 (BlackBoxTemplate , Element (Component , Text ), Decl (.. ))
125125import qualified Clash.Netlist.Id as Id
@@ -204,6 +204,17 @@ instance Backend backend => HasIdentifierSet (BlockState backend) where
204204instance HasUsageMap backend => HasUsageMap (BlockState backend ) where
205205 usageMap = bsBackend. usageMap
206206
207+ liftToBlockState
208+ :: forall backend a . Backend backend
209+ => State backend a -> State (BlockState backend ) a
210+ liftToBlockState (StateT f) = StateT g
211+ where
212+ g :: BlockState backend -> Identity (a , BlockState backend )
213+ g sbsIn = do
214+ let sIn = _bsBackend sbsIn
215+ (res,sOut) <- f sIn
216+ pure (res, sbsIn{_bsBackend = sOut})
217+
207218-- | A typed expression.
208219data TExpr = TExpr
209220 { ety :: HWType
@@ -1012,32 +1023,26 @@ unsafeToActiveHigh
10121023 :: Backend backend
10131024 => Text
10141025 -- ^ Name hint
1015- -> HWType
1016- -- ^ 'KnownDomain'
10171026 -> TExpr
10181027 -- ^ Reset signal
10191028 -> State (BlockState backend ) TExpr
1020- unsafeToActiveHigh nm dom rExpr =
1021- case extrResetPolarity dom of
1029+ unsafeToActiveHigh nm rExpr = do
1030+ resetLevel <- vResetPolarity <$> liftToBlockState (getDomainConf (ety rExpr))
1031+ case resetLevel of
10221032 ActiveHigh -> pure rExpr
10231033 ActiveLow -> notExpr nm rExpr
10241034
1025- extrResetPolarity :: HWType -> ResetPolarity
1026- extrResetPolarity (Void (Just (KnownDomain _ _ _ _ _ p))) = p
1027- extrResetPolarity p = error (" Internal error: expected KnownDomain, got: " <> show p)
1028-
10291035-- | Massage a reset to work as active-low reset.
10301036unsafeToActiveLow
10311037 :: Backend backend
10321038 => Text
10331039 -- ^ Name hint
1034- -> HWType
1035- -- ^ 'KnownDomain'
10361040 -> TExpr
10371041 -- ^ Reset signal
10381042 -> State (BlockState backend ) TExpr
1039- unsafeToActiveLow nm dom rExpr =
1040- case extrResetPolarity dom of
1043+ unsafeToActiveLow nm rExpr = do
1044+ resetLevel <- vResetPolarity <$> liftToBlockState (getDomainConf (ety rExpr))
1045+ case resetLevel of
10411046 ActiveLow -> pure rExpr
10421047 ActiveHigh -> notExpr nm rExpr
10431048
0 commit comments