Skip to content

Commit

Permalink
Fix (System)Verilog literal rendering of Index values
Browse files Browse the repository at this point in the history
There was confusion between the size in bits and the type level argument to Index.

Fixes #2813
  • Loading branch information
leonschoorl committed Sep 30, 2024
1 parent 3b755b9 commit 6c9781e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion clash-lib/src/Clash/Backend/SystemVerilog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,9 @@ expr_ _ (BlackBoxE pNm _ _ _ _ bbCtx _)
expr_ _ (BlackBoxE pNm _ _ _ _ bbCtx _)
| pNm == "Clash.Sized.Internal.Index.fromInteger#"
, [Literal _ (NumLit n), Literal _ i] <- extractLiterals bbCtx
= exprLitSV (Just (Index (fromInteger n),fromInteger n)) i
, Just k <- clogBase 2 n
, let k' = max 1 k
= exprLitSV (Just (Index (fromInteger n),k')) i

expr_ b (BlackBoxE _ libs imps inc bs bbCtx b') =
parenIf (b || b') (Ap (renderBlackBox libs imps inc bs bbCtx <*> pure 0))
Expand Down
4 changes: 3 additions & 1 deletion clash-lib/src/Clash/Backend/Verilog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,9 @@ expr_ _ (BlackBoxE pNm _ _ _ _ bbCtx _)
expr_ _ (BlackBoxE pNm _ _ _ _ bbCtx _)
| pNm == "Clash.Sized.Internal.Index.fromInteger#"
, [Literal _ (NumLit n), Literal _ i] <- extractLiterals bbCtx
= exprLit undefValue (Just (Index (fromInteger n),fromInteger n)) i
, Just k <- clogBase 2 n
, let k' = max 1 k
= exprLit undefValue (Just (Index (fromInteger n),k')) i

expr_ b (BlackBoxE _ libs imps inc bs bbCtx b') = do
parenIf (b || b') (Ap (renderBlackBox libs imps inc bs bbCtx <*> pure 0))
Expand Down

0 comments on commit 6c9781e

Please sign in to comment.