Skip to content

Commit 5319ae2

Browse files
authored
Fix assertion rendering (#3068)
1 parent a032c85 commit 5319ae2

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FIXED: The `Clash.Explicit.Verification.check` blackbox now correctly uses the given clock line, not assuming any longer that it is already bound to an identifier in the first place.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FIXED: The type of string literals passed to the `Clash.Explicit.Verification.check` blackbox now matches with the input provided via `Clash.Explicit.Verification.name`.

clash-lib/src/Clash/Primitives/Verification.hs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
{-|
2+
Copyright : (C) 2019 , Myrtle Software Ltd
3+
2021 , Ellie Hermaszewska
4+
2020-2025, QBayLogic B.V.
5+
License : BSD2 (see the file LICENSE)
6+
Maintainer : QBayLogic B.V. <devops@qbaylogic.com>
7+
-}
8+
19
{-# LANGUAGE OverloadedStrings #-}
210

311
module Clash.Primitives.Verification (checkBBF) where
@@ -11,14 +19,14 @@ import Data.List.Infinite (Infinite(..), (...))
1119
import Data.Maybe (listToMaybe)
1220
import Data.Monoid (Ap(getAp))
1321
import Data.Text.Prettyprint.Doc.Extra (Doc)
14-
import qualified Data.Text as Text
22+
import Data.Text (Text)
1523
import GHC.Stack (HasCallStack)
1624

1725
import Clash.Annotations.Primitive (HDL(..))
1826
import Clash.Backend
1927
(Backend, blockDecl, hdlKind)
2028
import Clash.Core.HasType
21-
import Clash.Core.Term (Term(Var), varToId)
29+
import Clash.Core.Term (Term(Var))
2230
import Clash.Core.TermLiteral (termToDataError)
2331
import Clash.Util (indexNote)
2432
import Clash.Netlist (mkExpr)
@@ -41,10 +49,11 @@ checkBBF _isD _primName args _ty =
4149
case litArgs of
4250
Left err -> pure (Left err)
4351
Right (propName, renderAs, cvProperty0) -> do
52+
clkBind <- bindMaybe (Just "clk") (indexNote "clk" (lefts args) clkArg)
4453
cvProperty1 <- mapM (uncurry bindMaybe) cvProperty0
4554
let decls = concatMap snd cvProperty1
4655
cvProperty2 = fmap fst cvProperty1
47-
pure (Right (meta, bb (checkTF decls (clkExpr, clkId) propName renderAs cvProperty2)))
56+
pure (Right (meta, bb (checkTF decls clkBind propName renderAs cvProperty2)))
4857
where
4958
-- TODO: Improve error handling; currently errors don't indicate what
5059
-- TODO: blackbox generated them.
@@ -55,8 +64,6 @@ checkBBF _isD _primName args _ty =
5564
:< renderAsArg
5665
:< propArg
5766
:< _ = ((0 :: Int)...)
58-
(Id.unsafeFromCoreId -> clkId) = varToId (indexNote "clk" (lefts args) clkArg)
59-
clkExpr = Identifier clkId Nothing
6067

6168
litArgs = do
6269
propName <- termToDataError (indexNote "propName" (lefts args) propNameArg)
@@ -68,7 +75,7 @@ checkBBF _isD _primName args _ty =
6875
meta = emptyBlackBoxMeta {bbKind=TDecl, bbRenderVoid=RenderVoid}
6976

7077
bindMaybe
71-
:: Maybe String
78+
:: Maybe Text
7279
-- ^ Hint for new identifier
7380
-> Term
7481
-- ^ Term to bind. Does not bind if it's already a reference to a signal
@@ -78,7 +85,7 @@ checkBBF _isD _primName args _ty =
7885
bindMaybe Nothing t = bindMaybe (Just "s") t
7986
bindMaybe (Just nm) t = do
8087
tcm <- Lens.view tcCache
81-
newId <- Id.make (Text.pack nm)
88+
newId <- Id.make nm
8289
(expr0, decls) <- mkExpr False Concurrent (NetlistId newId (inferCoreTypeOf tcm t)) t
8390
assn <- contAssign newId expr0
8491
pure
@@ -91,8 +98,8 @@ checkBBF _isD _primName args _ty =
9198

9299
checkTF
93100
:: [Declaration]
94-
-> (Expr, Identifier)
95-
-> Text.Text
101+
-> (Identifier, [Declaration])
102+
-> Text
96103
-> RenderAs
97104
-> Property' Identifier
98105
-> TemplateFunction
@@ -104,20 +111,21 @@ checkTF'
104111
. (HasCallStack, Backend s)
105112
=> [Declaration]
106113
-- ^ Extra decls needed
107-
-> (Expr, Identifier)
114+
-> (Identifier, [Declaration])
108115
-- ^ Clock
109-
-> Text.Text
116+
-> Text
110117
-- ^ Prop name
111118
-> RenderAs
112119
-> Property' Identifier
113120
-> BlackBoxContext
114121
-> State s Doc
115-
checkTF' decls (clk, clkId) propName renderAs prop bbCtx = do
122+
checkTF' decls (clkId, clkDecls) propName renderAs prop bbCtx = do
116123
blockName <- Id.makeBasic (propName <> "_block")
117-
getAp (blockDecl blockName (renderedPslProperty : decls))
124+
getAp (blockDecl blockName (clkDecls <> (renderedPslProperty : decls)))
118125

119126
where
120127
hdl = hdlKind (undefined :: s)
128+
clk = Identifier clkId Nothing
121129

122130
edge =
123131
case bbInputs bbCtx of

0 commit comments

Comments
 (0)