westerndigitalcorporation / pyvcd

Python package for writing Value Change Dump (VCD) files.
http://pyvcd.readthedocs.org/
MIT License
106 stars 39 forks source link

Implement vcd parsing #7

Closed dvc94ch closed 3 years ago

dvc94ch commented 6 years ago

Looking for a way to parse myhdl generated vcd dumps to extract the signals to pass to sigrok-cli for protocol analysis. (sigrok-cli doesn't support signal vectors)

jpgrayson commented 6 years ago

I would also like pyvcd to have VCD parsing capabilities. That said, it is not on my near or medium-term agenda to add the feature. I am open to PR's.

Note that I believe VCD parsing to be more challenging that VCD writing. Parsing to an in-memory representation is straightforward enough, but for many common VCD applications, an in-memory representaion is inappropriate due to the size of the underlying VCD.

We might want pyvcd to support several different parsing strategies. Off the top of my head:

This is a fun problem. I hope to work on it someday, but it would also be great if someone beat me to it.

dvc94ch commented 6 years ago

I implemented a vcd-extract tool this afternoon using https://github.com/kevinmehall/rust-vcd, since that seemed like the quickest way to get the job done. Would be nice to also have a python parser implementation

whitequark commented 4 years ago
  • Parse to an in-memory object representation of the VCD data. Appropriate for small VCD files.

This is something that would substantially benefit nMigen; and by "small VCD files" in this case I actually mean "tiny VCD files with tens of samples at most". The use case is formal verification; the detailed discussion is in https://github.com/nmigen/nmigen/issues/254.

To summarize: formal verification tools can produce interesting traces but they are quite decoupled from original HDL and represent everything as bit vectors. This can make reading formal traces unnecessarily hard. Although improvements such as first-class enum support in formal verification tools are possible, the most general case--the one where arbitrary code in the source HDL is used to decode the bit vectors to a human-readable symbolic representation--can only be handled by reading and rewriting VCD files produced by formal tools.

I think the most useful API for me would be an one-pass stream parser, since there's no reason to keep the entire thing in memory (even if the decoder is stateful, it still works cycle by cycle). It just doesn't have to be fast or efficient given the size of such traces, so even if it parsed the entire thing in memory, that'd also work fine.

I'm unfortunately not comfortable to implementing a reader for scratch with the intent to contribute it to pyvcd because pyvcd's coding style substantially differs from the one I'm used to and because my time is limited. I think I would be able to fund implementation of this feature. Would that help?

jpgrayson commented 4 years ago

I think I would be able to fund implementation of this feature. Would that help?

Short answer: no, it would not motivate me.

Slightly longer answer: my employment situation is such that any work I do on PyVCD either needs to align with my employer's goals, or needs to be done on a purely volunteer basis.

That said, I'm happy if someone else is paid to implement this feature. I would, of course, help with review and guidance to get a PR accepted.

Jiangshan00001 commented 3 years ago

https://github.com/Jiangshan00001/pyvcdr @dvc94ch you may try this one.

jpgrayson commented 3 years ago

Well, PyVCD finally has a VCD parsing capability. I'm sure there are many improvements that need to be made, but we'll track those as separate issues. Closing this one.

whitequark commented 3 years ago

Thank you for implementing this!