pyvcd icon indicating copy to clipboard operation
pyvcd copied to clipboard

Error parsing $var declaration where identifier contains square brackets

Open noloerino opened this issue 4 years ago • 3 comments

When parsing a $var directive that both contains a square bracket as part of the identifier AND a bit index declared afterwards, pyvcd will fail to process it properly and raise vcd.reader.VCDParseError: [lineno]:[col]: Expected $end. This can occur in VCDs generated for constructs like reg [31:0] regs [31:0] that are an array of vectors, where the resulting VCD would have the declaration $var wire 32 Q! regs[0] [31:0] $end (I had this occur in a file generated by Verilator).

I had difficulty finding the official IEEE Verilog standard's definition of what an "identifier" is, but it seems to me that in the above example, regs[0] would be considered part of the identifier, and [31:0] would be considered the bit index. If you (the maintainers) think this interpretation is correct, then I already have a fix + test case that does this, which I can file a PR for.

(screenshot of the relevant portion of the spec that I could find): image

noloerino avatar Feb 14 '22 06:02 noloerino

I have the same issue with definitions coming from a generate loop: $scope module genblock[3].mod $end will also raise the afore mentioned error.

haflex avatar Feb 06 '23 12:02 haflex

Also I have this error, could you please share the fix meanwhile is officially fixed?

andreabellizzi avatar Jul 06 '23 11:07 andreabellizzi

Currently I am just preprocessing the VCD with sed to make them readable by pyvcd.

sed -E 's/\[([[:digit:]]+)\]/_\1_/g' waves.vcd > waves2.vcd
sed -i -E 's/\$var ([^ ]+ [^ ]+ [^ ]+) (\\)/$var \1 _/g' waves2.vcd

haflex avatar Jul 06 '23 12:07 haflex