The lexer includes a Verilog preprocessor which handles:
- `define,`undef
- `include
- `ifdef,`ifndef,`else,`endif
- `timescale
Once you download, at the toplevel directory there is a runParser script which invokes java using the precompiled .jar files released under dist/.
Just type
> runParser
to see the usage.
I was compelled to use ANTLR 2.7.7 since the token stream mechanism does not try to slurp in the whole source file, an issue which I encountered with the more recent ANTLR 3.0.
While Verilog source files are not generally large, netlist files can be humungous, and one can quickly run out of memory by "slurping in the whole tamale."
Anyway, I've communicated the large file slurp file to the author of ANTLR and he'll be working out a solution in future releases.
(If you think large verilog netlists are problematic to slurp; think aout a SPEF file --- where I first encoutered the problem using ANTLR 3.x. Anyway, back to 2.7.7 works fine, even for large SPEF files.)
Anyway, back to the v2kparser...
I've been testing it out on a lot of the RTL for a large SOC I'm working on now; and, so far so good. It has even helped me find "bad style RTL" in the sense that (defined) 'values were used within source files which never `included the file containing the `define. Now, there's looking at an order of analysis problem!
I always advocate using the software style for writing include files and using them too, as in:
//file to be included all over: file.vh
`ifndef _FILE_VH
`define _FILE_VH_
`define N 5
`define M (1 << `N)
...
`endif
//`_FILE_VH_
and the file which wants to use
//rtl.v
`include "file.vh"