in reply to verilog perl usage

I do have these tools installed, but I have not used them much. This may be way too basic for what you're asking, but here is what I know...

To get help on vhier:

$ vhier --help

To show all the Verilog modules in a file:

$ cat top.v module top; dff i0 (); endmodule module dff; endmodule $ $ vhier top.v --modules dff top

Adapting the EXAMPLE code from Verilog::Parser:

use warnings; use strict; package MyParser; use Verilog::Parser; our @ISA = qw(Verilog::Parser); # parse, parse_file, etc are inherited from Verilog::Parser sub new { my $class = shift; #print "Class $class\n"; my $self = $class->SUPER::new(); bless $self, $class; return $self; } sub symbol { my $self = shift; my $token = shift; $self->{symbols}{$token}++; } sub report { my $self = shift; foreach my $sym (sort keys %{$self->{symbols}}) { printf "Symbol %-30s occurs %4d times\n", $sym, $self->{symbol +s}{$sym}; } } package main; my $text = <<"EOF"; module m; reg ina, inb; endmodule EOF my $parser = MyParser->new(); $parser->parse($text); $parser->eof(); $parser->report(); __END__ Output: Symbol ina occurs 1 times Symbol inb occurs 1 times Symbol m occurs 1 times

See also: http://www.veripool.org/wiki/verilog-perl

What are you trying to do?

Replies are listed 'Best First'.
Re^2: verilog perl usage
by perlvoyager (Initiate) on Feb 26, 2009 at 00:19 UTC
    Thanks toolic,appreciate your help.the information was very useful. I am trying to do the following a)open the files in a given directory/subdirectories-only files with extension .v/.vh/.svn/.sv/.svi. At present concentrating on only .v and .vh b)search for verilog module definition c)for each module that is defined more than once the list of all files(full path /relative path) in which the module is defined should be printed. d)must be able to exclude // from parsing i figured out i could do much of the stuff using o the vhier,but i am unsure of how to use the verilog arguments like 1.+incdir+dir =item -Idir Add the directory to the list of directories that should be searched for include directories or libraries. 2.and also the vhier -f file:Read the specified file, and act as if all text inside it was specified as command line parameters. Should a filehandle be passed or just the filename? I know this sounds really silly asking such basic questions but I am good at writing perl code rather than using packages Would appreciate if you could throw some light on this. Thanks
      It looks like vhier can do all the things you want to do. The script accepts filenames, just like any standard unix command. Just give it a try.
      $ vhier -f file.txt --modules --input-files
        Hi toolic I am trying to give a particular directory for vhier to search for the include directories and libraries The usage is vhier +incdir+dir. This translates to what I give on the command prompt, I am in a directory just above i2c( vhier +incdir+./i2c --modules i2c_master_top.v).this gives that it cannot find i2c. I have tried a lot of options on the command prompt like vhier --II<./i2c> and vhier +incdir+I<./i2c>. This usage is mentioned in vhier script itself(downloaded from cpan version 3.110) wonder if you could throw some light on how to give the option for the include directories.would really appreciate it. thanks for your time
Re^2: verilog perl usage
by mahurshi (Initiate) on Mar 14, 2009 at 05:43 UTC
    Excellent example. Could you also show an example of how to identify the ports of the module, what blocks are instantiated in it, what ports those blocks have, and what they're connected to.. If you could show me one or two examples, or perhaps, point me to a website with such examples, that would be great. I am currently parsing files manually but would love to switch to using Verilog::Perl if it makes things simpler. My goal is to be able to access ports of the module, identify all the instantiations of other blocks in a module, find out what ports are present in those instantations for each block, and what wires they are connected to. I am currently stuck with parsing the files manually and building hash tables to get this info but would love to switch to this package and get rid of my buggy parsing subroutines.
      would love to switch to this package and get rid of my buggy parsing subroutines.
      You are a wise monk, indeed. I have also come to realize that parsing Verilog is not a trivial matter. Every time I get the urge to do so, I take a step back and ask myself these questions:
      1. Can any of the tools for which my $company pays millions of dollars per annum already do what I need?
      2. Are there any free tools available out on the 'net which can do what I need?

      If the answer to the above is "no", then I turn to Perl.

      would love to switch to using Verilog::Perl if it makes things simpler
      Since I have not used these tools, I can not comment on their capabilities or limitations. However, according to the documentation, they seem quite useful. I think it is well worth a try.
      point me to a website with such examples
      I have done some searching, but I have not found any examples. I encourage you to give it a try, and report back here if you discover anything. CPAN modules usually have an "examples" directory in the install area. Have you looked there?
      Could you also show an example of how to identify the ports of the module, what blocks are instantiated in it, what ports those blocks have, and what they're connected to
      Sure. This is my first program using Verilog::Netlist (see also Re^3: verilog-perl vhier usage). I merely adapted the EXAMPLE given in the POD on CPAN. My Verilog example code is extremely simple. I can not guarantee it will work for whatever code you have. But, give it a try.

      May I ask what you plan to do with the parsed output?

        Thanks a lot again for your second example. This is really along the lines of what I am expecting out of the parser. What I want to do (eventually) with the parsing really depends on how much I am able to do with it :-). At the very minimum, I would like to identify the instantiations, port names, widths, connections, etc to do various kinds of post processing. Coming back to the piece of code you posted: I was able to get it to work by commenting out the exit_if_error() part. I have to admit first that I still need to spend some time to learn what each of these function calls really mean. Here is the example code I tried to test it with:
        cat top.v module top (a, b, c, d); input a; input b; output c; output d; inverter i_inverter (.in_a(a), .out_c(c)); buffer i_buffer (.in_b(b), .out_d(d)); endmodule
        Granted, this is not much, but this is enough for a starter like me :-) What I didn't give the script were the module definitions of "inverter" and "buffer" modules. I still expected it to at least write out the instantiation names and their port connections. I agree with the error messages below from the scripts output, but I don't understand why doesn't show the instantiation names. Why doesn't it associate the pin names (in_*, out_*) to the instantiation names? Does it absolutely require module references for that?
        %Error: top.v:10: Cannot find buffer %Error: top.v:9: Cannot find inverter %Error: top.v:10: Module reference not found: buffer %Error: top.v:9: Module reference not found: inverter Exiting due to errors Module names in netlist: top ModuleName=top HierInstName=top PortDir=input PortName=a PortDir=input PortName=b PortDir=output PortName=c PortDir=output PortName=d PinName=in_b NetName=b PinName=out_d NetName=d PinName=in_a NetName=a PinName=out_c NetName=c
        Thanks again for your help