SigParser(3)

πŸ’… SigParser(3) β€” Verilog::SigParser

okay so bestie, buckle up β€” this is the Perl doc page for Verilog::SigParser (yes, from the User Contributed Perl Documentation collection, we love a community moment ✨). Signal parsing for Verilog language files, and it's giving main character energy fr fr.


🌸 NAME 🌸

Verilog::SigParser β€” Signal Parsing for Verilog language files. that's the whole vibe, literally.


✨ SYNOPSIS ✨

like, here's how you actually use it:

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

so you spin up a preprocessor, hand it to the parser, and the callbacks below just start firing. iconic behavior honestly πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

Verilog::SigParser builds on top of the Verilog::Parser module β€” it's the glow-up, the sequel β€” and it gives you callbacks for when a signal is declared, when a module gets instantiated, or when a module gets defined. three whole moods πŸ’«

if you're sitting there like "wait, which parsing package do I even pick for my new app??" β€” go read the "Which Package" section of Verilog::Netlist... no wait, of Verilog::Language, sorry, my bad 😭. and if you want a higher level interface to this package, that's Verilog::Netlist, periodt.


🧚 METHODS 🧚

the method interface to Verilog::SigParser is described over in the Verilog::Parser module, which this package inherits from (we're a nepo baby, but a legit one). and ngl, you're probably gonna want to use the preprocessing option of Verilog::Parser with this package. trust πŸ’…


πŸ‘‘ CALLBACKS πŸ‘‘

so here's the thing β€” to make the parser actually do anything interesting, you gotta make a subclass and override one or more of these methods as it suits you. that's the assignment. 🫢

heads up: Verilog::Parser callbacks also get invoked while SigParser is parsing. no cap.

πŸ’– $self->attribute($text)

scanned an attribute or meta-comment. the parser peeks at the first word of each comment line (//key rest to end of line) or comment block (/*key rest */). then it calls $self->attribute( meta_text ) β€” but only if that first word has a true value in the hash $self->metacomment. gatekeeping, but make it parsing ✨

πŸ’– $self->class($token, $name, $virtual)

called at a class. slay.

πŸ’– $self->covergroup($token, $name)

called at a covergroup.

πŸ’– $self->contassign($token, $lhs, $rhs)

called at a continuous assign keyword, and it brings the left and right hand part of the assignment along with it. ⚠️ important: wire initializations do not count as assignments β€” those show up through the var callback's value parameter instead. don't get it twisted.

πŸ’– $self->defparam($token, $lhs, $rhs)

called at a defparam keyword, with the left and right hand part of the assignment. same energy, different keyword.

πŸ’– $self->endcell($token)

called at the end of defining a cell. super useful for writing clean up routines 🧹

πŸ’– $self->endgroup($token)

called at the end of defining a covergroup. also useful for clean up routines.

πŸ’– $self->endinterface($token)

called at a endinterface keyword. clean up routine material.

πŸ’– $self->endclass($token)

called at a endclass keyword. clean up routines, you know the drill.

πŸ’– $self->endtaskfunc($token)

called at a endfunction or endtask keyword. useful for writing clean up routines.

πŸ’– $self->endmodport($token)

called at a endmodport keyword. clean up routines ✨

πŸ’– $self->endmodule($token)

called at a endmodule keyword. clean up routines.

πŸ’– $self->endpackage($token)

called at a endpackage keyword. clean up routines.

πŸ’– $self->endprogram($token)

called at a endprogram keyword. clean up routines.

πŸ’– $self->function($keyword, $name, $data-type)

called when a function is defined. type is the output size or typename, plus signed where it applies β€” for example "", "[3:0]", "integer", or "signed [2:0]". ✨

πŸ’– $self->import($package, $id)

called when an import is defined.

πŸ’– $self->instant($module, $cell, $range)

called when an instantiation is defined. first parameter = the name of the module being instantiated. second = the name of the cell, which may be "" for primitives. third = the range, if the cell was arrayed.

πŸ•°οΈ lore drop: prior to version 3.000, the name of the parameters was also included in this callback. that's been replaced with the parampin callback. glow-up complete πŸ’…

πŸ’– $self->interface($keyword, $name)

called when an interface is defined.

πŸ’– $self->modport($keyword, $name)

called when an interface modport is defined.

πŸ’– $self->module($keyword, $name, ignored, $in_celldefine)

called when a module is defined.

πŸ’– $self->package($keyword, $name)

called when a package is defined.

πŸ’– $self->parampin($name, $connection, $index)

called when a parameter is connected to an instantiation β€” IE the "#(...)" syntax. it's also used for UDP delays (three calls for "#(delay0,delay1,delay2)"), because the parser genuinely doesn't know whether the instantiation is for a UDP versus a module. it's doing its best 😭

πŸ’– $self->pin($name, $connection, $index)

called when a pin on an instant is defined and "use_pinselects" is not set (that's the default β€” see pinselects() below). if a pin name wasn't provided and the connection is by position, name will be '' or undef.

if you don't need the pin, var, or port callbacks, consider the "$self->new (... use_vars=>0 ...)" option to accelerate parsing. free speed, bestie πŸ”₯

πŸ’– $self->pinselects($name, $connections, $index)

if "$self->new (... use_pinselects=>1 ...)" is used, this function gets called instead of "$self->pin (...)". the difference? the second parameter ("$connections") is a Perl hash containing all connected nets in the case of concatenations β€” including the MSB and LSB bounds used at those locations. fancy.

πŸ’– $self->port($name, $objof, $direction, $data_type, $array, $pinnum)

called when a module port is defined. ⚠️ it may get called twice on a port if the 1995 style is used β€” first call at the port header, second call at the input/output declaration. yeah, twice. it's not a bug, it's a lifestyle.

here's the whole cast, one by one:

  • $name β€” the name of the port πŸŽ€
  • $objof β€” what the port is an object of ('module', 'function', etc)
  • $direction β€” the port direction ('input', 'output', 'inout', 'ref', 'const ref', or 'interface')
  • $data_type β€” the data type ('reg', 'user_type_t', 'signed [31:0]', etc β€” or, for interfaces, the "{interface_id}.{modport_name}")
  • $array β€” the arraying of the port ('[1:0][2:0]', '', etc)
  • $pinnum β€” set to the pin number for ANSI style declarations, and 0 for Verilog 1995 declarations made outside the port list
if you don't need the pin, var, or port callbacks, consider the "$self->new (... use_vars=>0 ...)" option to accelerate parsing. yes I'm repeating myself, it's important 🫢

πŸ’– $self->program($keyword, $name)

called when a program is defined.

πŸ’– $self->signal_decl($keyword, $signame, $vector, $mem, $signed, $value)

girl, this one is no longer used β€” see $self->var instead. she's retired, let her rest πŸ’€

πŸ’– $self->task($keyword, $name)

called when a task is defined.

πŸ’– $self->var($kwd, $name, $objof, $nettype, $data_type, $array, $value)

called when a variable or net is defined. the whole ensemble:

  • $kwd β€” how it was declared ('port', 'var', 'genvar', 'parameter', 'localparam', 'typedef'), or, if applicable, a net type ('supply0', 'wire', etc)
  • $name β€” the name of the variable
  • $objof β€” what the variable is an object of ('module', 'function', etc)
  • $nettype β€” the net type, if any was defined ('', 'supply0', 'wire', 'tri', etc)
  • $data_type β€” the data type ('user_type_t', '[31:0] signed', etc)
  • $array β€” the arraying of the variable, which is the text AFTER the variable name ('[1:0][2:0]', '', etc)
  • $value β€” what the variable was assigned to ('', or expression)
🚨 note: typedefs are included here too, because "parameter type" is both a variable and a type declaration. multi-hyphenate.
if you don't need the pin, var, or port callbacks, consider the "$self->new (... use_vars=>0 ...)" option to accelerate parsing. (third time's the charm πŸ’œ)

below are some example declarations and the callbacks they fire:

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]' '' ''

πŸ’€ BUGS πŸ’€

ngl, 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. she's doing her best 😭

also note: 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. so don't come for her about that.

🌈 DISTRIBUTION 🌈

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>. go get it bestie ✨

Copyright 2000-2024 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. two licenses, two vibes, your choice πŸ’…


πŸŽ€ AUTHORS πŸŽ€

Wilson Snyder <wsnyder@wsnyder.org> β€” the icon, the legend, the author πŸ‘‘


🫢 SEE ALSO 🫢

Verilog-Perl, Verilog::Parser, Verilog::Language, Verilog::Netlist, Verilog::Getopt β€” go read them, iykyk πŸ“š


and that's the whole page, bestie!! this little masterpiece is perl v5.42.0, dated 2025-07-25, and it's page SigParser(3) β€” see you in the group chat πŸ’–πŸ¦‹βœ¨

πŸ“¦ where this page comes from