Skip to content

Commit fb8f164

Browse files
Removed the limit on the number of traces in dumpVCD (#3083)
`dumpVCD` was limited to 93 traces, because it could only generate single character trace identifier codes. The codes are now generated ad infinitum, and the restriction has been removed. Additionally, single bit traces were logged with an extra newline, causing empty lines in the VCD. This has been removed as well. Fixes: #3082
1 parent 4326c2f commit fb8f164

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FIXED: Removed the limit on the number of traces in `dumpVCD`. Also removed unnecessary double newlines after 1-bit signals. [#3082](https://github.com/clash-lang/clash-compiler/issues/3082)

clash-prelude/src/Clash/Signal/Trace.hs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import Data.IORef
115115
import Data.List (foldl')
116116
#endif
117117
import Data.List (foldl1', unzip4, transpose, uncons)
118+
import Data.List.Extra (snoc)
118119
import qualified Data.Map.Strict as Map
119120
import Data.Maybe (fromMaybe, catMaybes)
120121
import qualified Data.Text as Text
@@ -342,8 +343,6 @@ dumpVCD## (offset, cycles) traceMap now
342343
error $ "dumpVCD: cycles was " ++ show cycles ++ ", but cannot be negative."
343344
| null traceMap =
344345
error $ "dumpVCD: no traces found. Extend the given trace names."
345-
| Map.size traceMap > 126 - 33 =
346-
Left $ "Tracemap contains more than 93 traces, which is not supported by VCD."
347346
| (nm:_) <- offensiveNames =
348347
Left $ unwords [ "Trace '" ++ nm ++ "' contains"
349348
, "non-printable ASCII characters, which is not"
@@ -366,7 +365,10 @@ dumpVCD## (offset, cycles) traceMap now
366365
where
367366
offensiveNames = filter (any (not . printable)) traceNames
368367

369-
labels = map chr [33..126]
368+
-- Generate labels in the pattern a,b,c,aa,ab,ac,ba,bb,bc,ca,cb,cc,aaa,...
369+
labels = concatMap (\s -> map (snoc s) alphabet) ([]: labels)
370+
where
371+
alphabet = map chr [33..126]
370372

371373
timescale = foldl1' gcd (Map.keys periodMap)
372374
periodMap = toPeriodMap traceMap
@@ -407,22 +409,22 @@ dumpVCD## (offset, cycles) traceMap now
407409
headerTimescale = ["$timescale", (show timescale) ++ "ps", "$end"]
408410
headerWires = [ Text.unwords $ headerWire w l n
409411
| (w, l, n) <- (zip3 widths labels traceNames)]
410-
headerWire w l n = map Text.pack ["$var wire", show w, [l], n, "$end"]
412+
headerWire w l n = map Text.pack ["$var wire", show w, l, n, "$end"]
411413
initValues = map Text.pack $ zipWith ($) formatters inits
412414

413415
formatters = zipWith format widths labels
414416
inits = map (maybe (error "dumpVCD##: empty value") fst . uncons) valuess'
415417
tails = map changed valuess'
416418

417419
-- | Format single value according to VCD spec
418-
format :: Width -> Char -> Value -> String
419-
format 1 label (0,0) = ['0', label, '\n']
420-
format 1 label (0,1) = ['1', label, '\n']
421-
format 1 label (1,_) = ['x', label, '\n']
420+
format :: Width -> String -> Value -> String
421+
format 1 label (0,0) = '0': label
422+
format 1 label (0,1) = '1': label
423+
format 1 label (1,_) = 'x': label
422424
format 1 label (mask,val) =
423425
error $ "Can't format 1 bit wide value for " ++ show label ++ ": value " ++ show val ++ " and mask " ++ show mask
424426
format n label (mask,val) =
425-
"b" ++ map digit (reverse [0..n-1]) ++ " " ++ [label]
427+
"b" ++ map digit (reverse [0..n-1]) ++ " " ++ label
426428
where
427429
digit d = case (testBit mask d, testBit val d) of
428430
(False,False) -> '0'

0 commit comments

Comments
 (0)