Skip to content

Commit 613c6af

Browse files
martijnbastiaanchristiaanb
authored andcommitted
Add 'Clash.XException.hwSeqX'
1 parent 20a11a7 commit 613c6af

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* Add `Clash.Class.BitPack.bitCoerceMap` [#798](https://github.com/clash-lang/clash-compiler/pull/798)
3434
* Add `Clash.Magic.deDup`: instruct Clash to force sharing an operator between multiple branches of a case-expression
3535
* `InlinePrimitive` can now support multiple backends simultaneously [#425](https://github.com/clash-lang/clash-compiler/issues/425)
36+
* Add `Clash.XException.hwSeqX`: render declarations of an argument, but don't assign it to a result signal
3637

3738
* New features (Compiler):
3839
* [#961](https://github.com/clash-lang/clash-compiler/pull/961): Show `-fclash-*` Options in `clash --show-options`

clash-lib/prims/common/Clash_XException.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@
2222
, "template" : "~ARG[2]"
2323
}
2424
}
25+
, { "BlackBox" :
26+
{ "name" : "Clash.XException.hwSeqX"
27+
, "workInfo" : "Never"
28+
, "kind" : "Expression"
29+
, "type" : "hwSeqX :: a -> b -> b"
30+
, "template" : "~DEVNULL[~VAR[x][0]]~ARG[1]"
31+
}
32+
}
2533
]

clash-prelude/src/Clash/XException.hs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ module Clash.XException
3434
-- * Printing 'X' exceptions as \"X\"
3535
, ShowX (..), showsX, printX, showsPrecXWith
3636
-- * Strict evaluation
37-
, seqX, forceX, deepseqX, rwhnfX, defaultSeqX
37+
, seqX, forceX, deepseqX, rwhnfX, defaultSeqX, hwSeqX
3838
-- * Structured undefined / deep evaluation with undefined values
3939
, NFDataX (rnfX, deepErrorX, hasUndefined, ensureSpine)
4040
)
4141
where
4242

43+
import Clash.Annotations.Primitive (hasBlackBox)
4344
import Clash.CPP (maxTupleSize)
4445
import Clash.XException.TH
4546
import Control.Exception (Exception, catch, evaluate, throw)
@@ -111,6 +112,25 @@ seqX a b = unsafeDupablePerformIO
111112
{-# NOINLINE seqX #-}
112113
infixr 0 `seqX`
113114

115+
-- | Like 'seqX' in simulation, but will force its first argument to be rendered
116+
-- in HDL. This is useful for components that need to be rendered in hardware,
117+
-- but otherwise have no meaning in simulation. An example of such a component
118+
-- would be an ILA: a component monitoring an internal signal of a design. The
119+
-- output of such a component (typically a unit) can be passed as the first
120+
-- argument to 'hwSeqX' to ensure the ILA ends up in the generated HDL.
121+
--
122+
-- __NB__: the result of 'hwSeqX' must (indirectly) be used at the very top of
123+
-- a design. If it's not, Clash will remove it like it does for any other unused
124+
-- circuit parts.
125+
--
126+
-- __NB__: Make sure the blackbox for the component with zero-width results
127+
-- uses 'Clash.Netlist.BlackBox.Types.RenderVoid'
128+
hwSeqX :: a -> b -> b
129+
hwSeqX = seqX
130+
{-# NOINLINE hwSeqX #-}
131+
{-# ANN hwSeqX hasBlackBox #-}
132+
infixr 0 `hwSeqX`
133+
114134
-- | Evaluate a value with given function, returning 'Nothing' if it throws
115135
-- 'XException'.
116136
--

0 commit comments

Comments
 (0)