Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing $var declaration where identifier contains square brackets #22

Open
noloerino opened this issue Feb 14, 2022 · 3 comments

Comments

@noloerino
Copy link

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

@haflex
Copy link

haflex commented Feb 6, 2023

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.

@andreabellizzi
Copy link

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

@haflex
Copy link

haflex commented Jul 6, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants