SigParser(3pm) | User Contributed Perl Documentation | SigParser(3pm) |
Verilog::SigParser - Signal Parsing for Verilog language files
use Verilog::Preproc; use Verilog::SigParser; my $pp = Verilog::Preproc->new(keep_comments=>0,); my $parser = new Verilog::SigParser; $parser->parse_preproc_file($pp); # The below described callbacks are then invoked
Verilog::SigParser builds upon the Verilog::Parser module to provide callbacks for when a signal is declared, a module instantiated, or a module defined.
See the "Which Package" section of Verilog::Language if you are unsure which parsing package to use for a new application. For a higher level interface to this package, see Verilog::Netlist.
The method interface to Verilog::SigParser is described in the Verilog::Parser module which this package inherits. You will probably want to use the preprocessing option of Verilog::Parser with this package.
In order to make the parser do anything interesting, you must make a subclass where you override one or more of the following methods as appropriate.
Note Verilog::Parser callbacks also are invoked when SigParser is parsing.
Prior to version 3.000, the name of the parameters were also included in this callback. This has been replaced with the parampin callback.
If you do not need the pin nor var nor port callbacks, consider the "$self->new (... use_vars=>0 ...)" option to accelerate parsing.
The first argument $name, is the name of the port. $objof is what the port is an object of ('module', 'function', etc). $direction is the port direction ('input', 'output', 'inout', 'ref', 'const ref', or 'interface'). $data_type is the data type ('reg', 'user_type_t', 'signed [31:0]', etc, or for interfaces the "{interface_id}.{modport_name}"). $array is the arraying of the port ('[1:0][2:0]', '', etc). $pinnum is set to the pin number for ANSI style declarations, and 0 for Verilog 1995 declarations made outside the port list.
If you do not need the pin nor var nor port callbacks, consider the "$self->new (... use_vars=>0 ...)" option to accelerate parsing.
The first argument $kwd is how it was declared ('port', 'var', 'genvar', 'parameter', 'localparam', 'typedef') or if applicable a net type ('supply0', 'wire', etc). $name is the name of the variable. $objof is what the variable is an object of ('module', 'function', etc). $nettype is the net type if any was defined ('', 'supply0', 'wire', 'tri', etc). $data_type is the data type ('user_type_t', '[31:0] signed', etc). $array is the arraying of the variable which is the text AFTER the variable name ('[1:0][2:0]', '', etc). $value is what the variable was assigned to ('', or expression).
Note typedefs are included here, because "parameter type" is both a variable and a type declaration.
If you do not need the pin nor var nor port callbacks, consider the "$self->new (... use_vars=>0 ...)" option to accelerate parsing.
Below are some example declarations and the callbacks:
reg [4:0] vect = 5'b10100; # VAR 'var' 'vect' 'module' '' 'reg [4:0]' '' '5'b10100' wire (weak0, weak1) value = pullval; # VAR 'net' 'value' 'module' 'wire' '' '' 'pullval' reg [1:0] mem [12:2]; # VAR 'var' 'mem' 'module' '' 'reg [1:0]' '[12:2]' '' int n[1:2][1:3] = '{'{0,1,2}, '{3{4}}}; # verilog/parser_sv.v:121: VAR 'var' 'n' 'module' '' 'int' '[1:2][1:3]' ''{'{0,1,2},'{3}}' module ( output logic [SZ-1:0] o_sized ); # VAR 'port' 'o_sized' 'module' '' 'logic [SZ-1:0]' '' '' struct packed signed { bit [7:0] m_b; }; # VAR 'member' 'm_b' 'struct' '' 'bit [7:0]' '' ''
This is being distributed as a baseline for future contributions. Don't expect a lot, the Parser is still naive, and there are many awkward cases that aren't covered.
Note the SigParser is focused on extracting signal information. It does NOT extract enough information to derive general interconnect; for example the contents of 'assign' statements are not parsed.
Verilog-Perl is part of the <https://www.veripool.org/> free Verilog EDA software tool suite. The latest version is available from CPAN and from <https://www.veripool.org/verilog-perl>.
Copyright 2000-2022 by Wilson Snyder. This package is free software; you can redistribute it and/or modify it under the terms of either the GNU Lesser General Public License Version 3 or the Perl Artistic License Version 2.0.
Wilson Snyder <wsnyder@wsnyder.org>
Verilog-Perl, Verilog::Parser, Verilog::Language, Verilog::Netlist, Verilog::Getopt
2022-10-20 | perl v5.36.0 |