rvp - Rough Verilog Parser Perl Module

The basic idea is that first you call read_verilog will a list of all of your files. The files are parsed and information stored away. You are then handed back a pointer to the information which you can use in calls to the various get_ function to get information about the verilog design.

For Example:

 #!/usr/bin/perl -w
 use rvp;   # use the rough verilog parser
 # Read in all the files specified on the command line
 $vdata = rvp->read_verilog(\@ARGV,[],{},1,[],[],'');
 # Print out all the modules found
 foreach $module ($vdata->get_modules()) { print "$module\n"; }

Unless you are doing something very strange, you can probably ignore all of the functions that have the words 'context' or 'anchors' in them!


read_verilog

reads in verilog files, parses them and stores results in an internal data structure (which I call a RVP database).

  Arguments:  - reference to array of files to read (can have paths)
              - reference to hash of defines with names as keys
              - reference to array of global includes - not used anymore,
                 just kept for backwards compatibility
              - quite flag. 1=be quiet, 0=be chatty.
              - reference to array of include directories
              - reference to array of library directories
              - library extension string (eg '.v') or reference to array of strings
  Returns:    - a pointer to the internal data structure.
  Example:
    $defines{'TRUE'}=1;  # same as +define+TRUE=1 on verilog cmd line
    $vdata = rvp->read_verilog(\@files,[],\%defines,1,
                                     \@inc_dirs,\@lib_dirs,\@lib_exts);


get_problems

Return any problems that happened during parsing

  Returns:    - array of strings of problems. Each one is:
                    "TYPE:FILE:LINE: description"


set_debug

Turns on debug printing in the parser.

  Returns:    - nothing


unset_debug

Turns off debug printing in the parser.

  Returns:    - nothing


get_files

Get a list of all the files in the database.

  Returns:    - list of all the files
  Example:   @all_files = $vdata->get_files();


get_files_modules

Get a list of all the modules in a particular file.

  Arguments:  - name of file
  Returns:    - list of module names
  Example:   @modules = $vdata->get_files_modules($file);


get_files_full_name

Get the full name (including path) of a file.

  Arguments:  - name of file
  Returns:    - full path name
  Example  $full_name = $vdata->get_files_full_name($file);


get_files_stats

Get statistics about a file

  Arguments:  - name of file
  Returns:    - number of lines in the file (more later...)
  Example  $full_name = $vdata->get_files_stats($file);


file_exists

Test if a particular module file in the database.

  Arguments:  - file name to test.
  Returns:    - 1 if exists otherwise 0
  Example:   if ($vdata->file_exists($file))....


get_modules

Get a list of all the modules in the database.

  Returns:   - list of all the modules
  Example:   @all_modules = $vdata->get_modules();


get_modules_t_and_f

Get a list of all the tasks and functions in a particular module.

  Arguments:  - name of module
  Returns:    - list of tasks and function names
  Example:    if ( @t_and_f = $vdata->get_modules_t_and_f($m))...


get_modules_t_or_f

Get information on a task or function in a module.

  Arguments:  - module name
              - task or function name
  Returns:    - A 4 element list: type (task or function), definition line,
                  file, anchor
  Example:    ($t_type,$t_line ,$t_file,$t_anchor)=
                $vdata->get_modules_t_or_f($m,$tf);


get_modules_signals

Get a list of all the signals in a particular module.

  Arguments:  - name of module
  Returns:    - list of signal names
  Example:    if ( @signs = $vdata->get_modules_signals($m))...


get_modules_file

Get the file name (no path) that a module is defined in.

  Arguments:  - module name
  Returns:    - file name without path, and the line number module starts on
  Example:    ($f) = $vdata->get_modules_file($m);


get_modules_type

Get the type of the module - It is one of: module, macromodule or primitive (rvp treats these all as modules).

  Arguments:  - module name
  Returns:    - type
  Example:    $t = $vdata->get_modules_type($m);


get_files_includes

Get the file names (no path) of files included in a file.

  Arguments:  - file name
  Returns:    - list of file names without paths
  Example:    @f = $vdata->get_files_includes($file);


get_files_included_by

Get the file names (no path) of files that included this file.

  Arguments:  - file name
  Returns:    - list of file names without paths
  Example:    @f = $vdata->get_files_included_by($file);


module_ignored

Test if a particular module has been ignored because of duplicates found

  Arguments:  - module name to test
  Returns:    - 1 if ignored otherwise 0
  Example:   if ($vdata->module_ignored($module))....


module_exists

Test if a particular module exists in the database.

  Arguments:  - module name to test
  Returns:    - 1 if exists otherwise 0
  Example:   if ($vdata->module_exists($module))....


get_ignored_modules

Return a list of the ignored modules. These are modules where duplicates have been found.

  Returns:    - List of ignored modules
  Example:    - foreach $module ($vdata->get_ignored_modules())....


get_module_signal

Get information about a particular signal in a particular module.

  Arguments:  - name of module
              - name of signal
  Returns:    - A list containing: 
                 - the line signal is defined
                 - the line signal is assigned first (or -1)
                 - line in instantiating module where an input 
                       is driven from (or -1)
                 - the type of the signal (input,output,reg etc)
                 - the file the signal is in
                 - posedge flag (1 if signal ever seen with posedge)
                 - negedge flag (1 if signal ever seen with negedge)
                 - second type (eg reg for a registered output)
                 - signal real source file
                 - signal real source line
                 - range string if any ( not including [ and ] )
                 - the file signal is assigned first (or '')
                 - file for the instantiating module where an input 
                       is driven from (or "")
                 - a pointer to an array of dimensions for memories
                       each element of the array is a dimension, array
                       is empty for non-memories
  Note posedge and negedge information is propagated up the hierarchy to
  attached signals. It is not propagated down the hierarchy.
  Example:    ($s_line,$s_a_line,$s_i_line,$s_type,$s_file,$s_p,$s_n,
               $s_type2,$s_r_file,$s_r_line,$range,$s_a_file,$s_i_file) = 
                      $vdata->get_module_signal($m,$sig);


get_first_signal_port_con

Get the first port that this signal in this module is connected to.

  Arguments:  - module name
              - signal name
  Returns:    - a 5 element list: instantiated module name, instance name
                  port name, line number and file
  Example:    ($im,$in,$p,$l,$f)=$vdata->get_first_signal_port_con($m,$s);


get_next_signal_port_con

Get the next port that this signal in this module is connected to.

  Returns:    - a 5 element list: instantiated module name, instance name
                  port name, line number and file
  Example:    ($im,$in,$p,$l,$f)=$vdata->get_next_signal_port_con();


get_first_signal_con_to

Get the first signal that is connected to this port in an instantiation of this module. This only works for instances that use the .port(sig) notation.

  Arguments:  - module name
              - signal name
  Returns:    - a 4 element list: signal connected to this port
                                  module signal is in
                                  instance (of this module) where the connection
                                    occurs
  Example:    ($cts,$ctm,$cti)=$vdata->get_first_signal_con_to($m,$s);


get_next_signal_con_to

Get the next signal that is connected to this port in an instantiation of this module. This only works for instances that use the .port(sig) notation.

  Arguments:  - module name
              - signal name
  Returns:    - a 4 element list: signal connected to this port
                                  module signal is in
                                  instance (of this module) where the connection
                                    occurs
  Example:    ($cts,$ctm,$cti)=$vdata->get_next_signal_con_to();


get_first_instantiator

Get the first thing that instantiates this module.

  Arguments:  - module name
  Returns:    - a 4 element list: instantiating module, file, instance name, line
  Example:    
                ($im,$f,$i) = $vdata->get_first_instantiator($m );


get_next_instantiator

Get the first thing that instantiates the module specified in get_first_instantiator (or _by_context).

  Returns:    - a 4 element list: instantiating module, file, 
                                    instance name, line
  Example:    
                ($im,$f,$i) = $vdata->get_next_instantiator();


get_first_instantiation

Get the first thing that this module instantiates.

  Arguments:  - module name
  Returns:    - a 4 element list: instantiated module name, file, 
                  instance name, and line number
  Example:    
                ($im,$f,$i,$l) = $vdata->get_first_instantiation($m);


get_next_instantiation

Get the next thing that this module instantiates.

  Returns:    - a 4 element list: instantiated module name, file, 
                  instance name, and line number
  Example:    
                ($im,$f,$i,$l) = $vdata->get_next_instantiation();


get_current_instantiations_port_con

Gets the port connections for the current instantiations (which is got using get_first_instantiation and get_next_instantiation). If the instantiation does not use .port(...) syntax and rvp does not have the access to the source of the module then the port names will be returned as numbers in connection order starting at 0.

  Returns:    - A hash (well, really a list that can be assigned to a hash). 
               The keys of the hash are the port names. The values of the
               hash is everything (except comments) that appeared in the 
               brackets in the verilog.
  Example:    %port_con = $vdata->get_current_instantiations_port_con();
              foreach $port (keys %port_con) { ...


get_current_instantiations_parameters

Gets the parameters for the current instantiations (which is set using get_first_instantiation and get_next_instantiation). If the instantiation parameters does not use the verilog 2001 .name(...) syntax and rvp does not have the access to the source of the module then the parameter names will be returned as numbers reflecting the order (starting at 0).

  Returns:    - A hash (well, really a list that can be assigned to a hash). 
               The keys of the hash are the parameters names. The values of the
               hash is everything (except comments) in the value.
  Example:    %parameters = $vdata->get_current_instantiations_parameters();
              foreach my $p (keys %parameters) { ...


get_modules_parameters

Gets the parameters for a module.

  Arguments:  - module name
  Returns:    - A hash (well, really a list that can be assigned to a hash). 
               The keys of the hash are the parameters names. The values of the
               hash is everything (except comments) in the value.
  Example:    %parameters = $vdata->get_modules_parameters();
              foreach my $p (keys %parameters) { ...


get_define

Find out where a define is defined and what the value is

  Arguments:  - name of the define
             Optional arguments where a you want the correct location and
               value for a particular use of a multiplely defined define:
              - file where define is used 
              - line where define is used
  Returns:    - list with three elements: file, line, value
                 or if the define does not exist it returns a empty list.
                 if the define was defined on the command line it sets file=""
                  and line=0
  Example:    ($f,$l,$v) = $vdata->get_define($word,$file,$line);


get_context

Get the context (if any) for a line in a file.

  Arguments:  - file name
              - line number
  Returns:    - line number if there is a context, zero if there is none.
  Example:      $l = $vdata->get_context($filename,$line);


get_module_start_by_context

Test if the context is a module definition start.

  Arguments:  - file name
              - line number
  Returns:    - module name if it is a module start, 0 otherwise
  Example:     if($vdata->get_module_start_by_context($filename,$line))..


get_has_value_by_context

Check if the context has a value (ie a new module or something). Contexts that just turn on and off preprocessor ignoring do not have values.

  Arguments:  - file name
              - line number
  Returns:    - 1 if there is a value, 0 otherwise
  Example:    if ($vdata->get_has_value_by_context($file,$line))..


get_context_name_type

Find the reason for a new context - is it a module / function or task. Contexts that just turn on and off preprocessor ignoring do not have values.

  Arguments:  - file name
              - line number
  Returns:    - name
              - type [ module | function | task ]
  Example:    ($n,$t)=$vdata->get_context_name_type($file,$line);


get_pre_ignore_by_context

Test if the context is preprocessor ignore.

  Arguments:  - file name
              - line number
  Returns:    - 1 if it is, 0 otherwise
  Example:    if ($vdata->get_pre_ignore_by_context($file,$line))..


get_first_instantiator_by_context

Get the first thing that instantiates this module using the context. The context must be a module_start.

  Arguments:  - file name (for context) 
              - line name (for context)
  Returns:    - a 4 element list: instantiating module, file, instance name, line
  Example:    
              @i=$vdata->get_first_instantiator_by_context($f,$l );


get_inst_on_line

Gets the instance name of a line in a file

  Arguments:  - file name
              - line number
  Returns:    - name if the line has an instance name, 0 otherwise
  Example:    if ( $new_inst = $vdata->get_inst_on_line($file,$line) ) ...


get_signal_by_context

Same as get_module_signal but works by specifying a context.

  Arguments:  - context file name
              - context line number
              - signal name
  Returns:    same as get_module_signal
  Example:


get_t_or_f_by_context

Same as get_modules_t_or_f but works by specifying a context.

  Arguments:  - context file name
              - context line number
              - task name
  Returns:    - same as get_modules_t_or_f
  Example:


get_parameter_by_context

Return the file and line for a named parameter using context

  Arguments:  - context file name
              - context line number
              - parameter name
  Returns:    - file and line of definition
  Example:


get_anchors

Get the anchors for a line in a file.

  Returns:    - a list of anchors
  Example:   foreach $anchor ( $vdata->get_anchors($file,$line) ) ..


expand_defines

Expand the defines in a line of verilog code. for best use this should be called line by line, so that the defines get the correct values when defines are defined multiple times

  Arguments:  - a pointer to the string to expand the defines in
              - the file the line is from
              - the line number of the line
  Returns:    - nothing
  Example:   $vdata->expand_defines(\$line_to_expand,$file,$line);


verilog_gatetype_keywords

  Returns:    - a list of verilog gatetype keywords
  Example:   @keywords = rvp->verilog_gatetype_keywords();


verilog_compiler_keywords

  Returns:    - a list of verilog compiler keywords
  Example:   @keywords = rvp->verilog_compiler_keywords();


verilog_signal_keywords

  Returns:    - a list of verilog signal keywords
  Example:   @keywords = rvp->verilog_signal_keywords();


chunk_read_init

Initialise a file for chunk reading (see chunk_read for more details). It actually reads the whole file into a string, which chunk_read then reads a chunk at a time. The file is closed before chuck_read_init returns.

  Arguments:  - the file to read (with path if needed)
              - tabstop: 0 = leave tabs alone
                         N = turn tabs spaces with each tabstop=N
  Returns:    - a handle to pass to chunk_read or 0 if file open fails
  Example:    
            my $chunkRead = rvp->chunkr_read_init($f,$opts{tabstop});


chunk_read

Reads verilog a chunk at a time. The file is opened using chunk_read_init. Then chunk_read is used to read the file a chunk at a time. A chunk is a line or part of a line that is all the same type.

  The types are: 
              comment   - either // or /* */ comment
              attribute - verilog 2001 (* *) atribute
              include   - a line containing `include "file"
              string    - a string
              code      - anything else (verilog code, defines, compliler keywords)

Nothing is removed from the file, so if each chunk is printed after being read you will end up with exactly the same file as you put in.

  Arguments:  - handle (from chunk_read_init)
  Returns:    - 0 at the end of file, or a hash ref with the following keys:
              type       - one of the types (see above)
              text       - the text read from the file
              line       - the line number the text is on
              isANewLine - true if chunk is the first chunk of the line
              isStart    - true if the chunk is the start (eg "/*..." for 
                             a comment )
              isEnd      - true if the chunk is the end ( eg "*/" )
                      NOTE: isEnd is set to undefined for a
                       type="code" that ends in a newline. This is
                       because chunk_read doesn't know if the code is
                       ending or not. If you need to know in this case
                       you can read the next chunk and see what type it is.
  Example:    
            my $chunkRead = rvp->chunk_read_init($f,0);
            while ($chunk = rvp->chunk_read($chunkRead)) {
                    print $chunk->{text} unless $chunk->{type} eq "comment";
            }