@@ -118,8 +118,8 @@ import Clash.Annotations.Primitive (HDL (..), Primitive (..))
118
118
import Clash.Annotations.SynthesisAttributes (Attr )
119
119
import Clash.Backend hiding (Usage , fromBV , toBV )
120
120
import 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 )
123
123
import Clash.Netlist.BlackBox.Types
124
124
(BlackBoxTemplate , Element (Component , Text ), Decl (.. ))
125
125
import qualified Clash.Netlist.Id as Id
@@ -204,6 +204,17 @@ instance Backend backend => HasIdentifierSet (BlockState backend) where
204
204
instance HasUsageMap backend => HasUsageMap (BlockState backend ) where
205
205
usageMap = bsBackend. usageMap
206
206
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
+
207
218
-- | A typed expression.
208
219
data TExpr = TExpr
209
220
{ ety :: HWType
@@ -1012,32 +1023,26 @@ unsafeToActiveHigh
1012
1023
:: Backend backend
1013
1024
=> Text
1014
1025
-- ^ Name hint
1015
- -> HWType
1016
- -- ^ 'KnownDomain'
1017
1026
-> TExpr
1018
1027
-- ^ Reset signal
1019
1028
-> 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
1022
1032
ActiveHigh -> pure rExpr
1023
1033
ActiveLow -> notExpr nm rExpr
1024
1034
1025
- extrResetPolarity :: HWType -> ResetPolarity
1026
- extrResetPolarity (Void (Just (KnownDomain _ _ _ _ _ p))) = p
1027
- extrResetPolarity p = error (" Internal error: expected KnownDomain, got: " <> show p)
1028
-
1029
1035
-- | Massage a reset to work as active-low reset.
1030
1036
unsafeToActiveLow
1031
1037
:: Backend backend
1032
1038
=> Text
1033
1039
-- ^ Name hint
1034
- -> HWType
1035
- -- ^ 'KnownDomain'
1036
1040
-> TExpr
1037
1041
-- ^ Reset signal
1038
1042
-> 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
1041
1046
ActiveLow -> pure rExpr
1042
1047
ActiveHigh -> notExpr nm rExpr
1043
1048
0 commit comments