@@ -349,8 +349,6 @@ dumpVCD## (offset, cycles) traceMap now
349349 error $ " dumpVCD: cycles was " ++ show cycles ++ " , but cannot be negative."
350350 | null traceMap =
351351 error $ " dumpVCD: no traces found. Extend the given trace names."
352- | Map. size traceMap > 126 - 33 =
353- Left $ " Tracemap contains more than 93 traces, which is not supported by VCD."
354352 | (nm: _) <- offensiveNames =
355353 Left $ unwords [ " Trace '" ++ nm ++ " ' contains"
356354 , " non-printable ASCII characters, which is not"
@@ -373,7 +371,12 @@ dumpVCD## (offset, cycles) traceMap now
373371 where
374372 offensiveNames = filter (any (not . printable)) traceNames
375373
376- labels = map chr [33 .. 126 ]
374+ -- Generate labels like reversed digits: 0:[1,2,01,11,21,02,12,22,001,...]
375+ labels = " !" : map go [1 .. ]
376+ where
377+ go 0 = " "
378+ go n = chr ( 33 + n `mod` k) : go (n `div` k)
379+ k = 126 - 33 + 1
377380
378381 timescale = foldl1' gcd (Map. keys periodMap)
379382 periodMap = toPeriodMap traceMap
@@ -413,22 +416,22 @@ dumpVCD## (offset, cycles) traceMap now
413416 headerTimescale = [" $timescale" , (show timescale) ++ " ps" , " $end" ]
414417 headerWires = [ Text. unwords $ headerWire w l n
415418 | (w, l, n) <- (zip3 widths labels traceNames)]
416- headerWire w l n = map Text. pack [" $var wire" , show w, [l] , n, " $end" ]
419+ headerWire w l n = map Text. pack [" $var wire" , show w, l , n, " $end" ]
417420 initValues = map Text. pack $ zipWith ($) formatters inits
418421
419422 formatters = zipWith format widths labels
420423 inits = map (maybe (error " dumpVCD##: empty value" ) fst . uncons) valuess'
421424 tails = map changed valuess'
422425
423426 -- | Format single value according to VCD spec
424- format :: Width -> Char -> Value -> String
425- format 1 label (0 ,0 ) = [ ' 0' , label, ' \n ' ]
426- format 1 label (0 ,1 ) = [ ' 1' , label, ' \n ' ]
427- format 1 label (1 ,_) = [ ' x' , label, ' \n ' ]
427+ format :: Width -> String -> Value -> String
428+ format 1 label (0 ,0 ) = ' 0' : label <> " \n "
429+ format 1 label (0 ,1 ) = ' 1' : label <> " \n "
430+ format 1 label (1 ,_) = ' x' : label <> " \n "
428431 format 1 label (mask,val) =
429432 error $ " Can't format 1 bit wide value for " ++ show label ++ " : value " ++ show val ++ " and mask " ++ show mask
430433 format n label (mask,val) =
431- " b" ++ map digit (reverse [0 .. n- 1 ]) ++ " " ++ [ label]
434+ " b" ++ map digit (reverse [0 .. n- 1 ]) ++ " " ++ label
432435 where
433436 digit d = case (testBit mask d, testBit val d) of
434437 (False ,False ) -> ' 0'
0 commit comments