Verilog gate-level netlist files are simply text files that are usually output from some software, such as Synopsys Design Compiler, and are therefore well suited for Perl analysis.
Being simple text files, there is nothing special about Perl. Check out any Perl tutorial that talks about the basics of Perl syntax and regular expressions, and what you learn should be easy to adapt to your Verilog tasks. See For example: http://perldoc.perl.org/perlintro.html for a general introduction. http://perldoc.perl.org/perlretut.html - for a good regular expression tutorial.
However, even a simple program can have many hidden errors. For example, let's say you want to print all the module names from the Verilog hierarchical netlist:
use strict; use warnings; my $infile = $ARGV[0] or die "$0 Usage:\n\t$0 <input verilog file>\n\n"; open(my $in_fh , '<' , $infile) or die "$0 Error: Couldn't open $infile for reading: $!\n"; while(<$in_fh>) { if (m/^module\s+(\S+)/) { print "$1\n"; } } close($in_fh) or die "$0 Error: Couldn't close $infile after reading: $!\n";
Even this short example is full of potential errors: what if the module name does not match the keyword "module"? what if between the opening “no” (“module” and “module name”, what if there is a space (or spaces) between the beginning of the line and the keyword “module”?
You need to know these problems. If you only need a one-time solution for a specific Verilog-related task, a simple Perl script such as the aforementioned solution is a good solution providing proper documentation to warn future users of their known flaws.
If you need something more complex related to more complex Verilog code analysis, I would try to find out if any of your existing tools (compiler, linter, formal equivalence checker, simulator, etc.) provide you access to data you need. All of these tools include mature and working Verilog guerrillas optimized for speed / memory and often provide a Tcl interface for accessing data.
Some of the above people recommended Verilog-Perl. I tried this and found it to be very slow. If you work with netlists over 100 MB, I would not use this solution, but your mileage may vary.
Offer kaye
source share