Preproc(3)
π NAME π
Bestie, you're reading Preproc(3) from the User Contributed Perl Documentation section β it's the manual page for Verilog::Preproc, and its whole gig is preprocessing Verilog files. Slay.
β¨ SYNOPSIS β¨
Okay so the vibe is: make a preprocessor, open a file, grab a line. The parameters placeholder β written I<parameters> in the original β is where the named params from PARAMETERS go, iykyk.
use Verilog::Getopt;
my $vp = Verilog::Preproc->new(parameters);
$vp->open(filename=>"verilog_file.v");
my $line = $vp->getline();
π¦ EXAMPLE π¦
This is a complete verilog pre-parser! For a command line version, see vppreproc.
# This is a complete verilog pre-parser!
# For a command line version, see vppreproc
use Verilog::Getopt;
use Verilog::Preproc;
my $opt = new Verilog::Getopt;
@ARGV = $opt->parameter(@ARGV);
my $vp = Verilog::Preproc->new(options=>$opt,);
$vp->open(filename=>"verilog_file.v");
while (defined (my $line = $vp->getline())) {
print $line;
}
πΈ DESCRIPTION πΈ
Verilog::Preproc reads Verilog files, and preprocesses them according to the SystemVerilog 2009 (1800-2009) specification. Programs can be easily converted from reading a IO::File into reading preprocessed output from Verilog::Preproc.
If you're unsure which parsing package to use for a new application, see the "Which Package" section of Verilog-Perl. π«Ά
π MEMBER FUNCTIONS π
$self->eof()β Returns true at the end of the file.$self->filename()β Returns the filename of the most recently returnedgetline(). May not match the filename passed on the command line, as`linedirectives are honored.$self->getall()β Return the entire translated text up to the final EOF, similar to callingjoin('',$self->getline)but significantly faster. With optional argument, returns approximately that number of characters. Returnsundefat EOF.$self->getline()β Return the next line of text. Returnsundefat EOF. (Just likeIO::File->getline().)$self->lineno()β Returns the line number of the lastgetline(). Note that the line number may change several times betweengetline(), for example when traversing multiple include files.$self->parent()β Returns a reference to theVerilog::Netlist::Filewhich created this object, if any.$self->new(parameters)β Creates a new preprocessor. See the PARAMETERS section for the options that may be passed tonew.$self->open(filename=>filename)β Opens the specified file. Iffilenameends in.gz, decompress while reading. If called before a file is completely parsed, the new file will be parsed completely before returning to the previously open file. (As if it was an include file.)
Open may also be called without named parameters, in which case the only argument is the filename.
$self->unreadback(text)β Insert text into the input stream at the given point. The text will not be parsed, just returned to the application. This letscomment()callbacks insert special code into the output stream.
π PARAMETERS π
The following named parameters may be passed to the new constructor. Yes, same new as above, bestie.
ieee_predefines=>0β Withieee_predefinesfalse, disable definingSV_COV_STARTand other IEEE mandated definitions.include_open_nonfatal=>1β Withinclude_open_nonfatalset to one, ignore any include files that do not exist.keep_comments=>0β Withkeep_commentsset to zero, strip all comments. When set to one (the default), insert comments in output streams. When set to'sub', call thecomment()function so that meta-comments can be processed outside of the output stream. Note that some programs use meta-comments to embed useful information (synthesis and lint), so strip with caution if feeding to tools other than your own. Defaults to 1.keep_whitespace=>0β Withkeep_whitespaceset to zero, compress all whitespace to a single space or newline. When set to one (the default), retain whitespace. Defaults to 1.line_directives=>0β Withline_directivesset to zero, suppress`linecomments which indicate filename and line number changes. Use thelineno()andfilename()methods instead to retrieve this information. Defaults true.options=>Verilog::Getopt objectβ Specifies the object to be used for resolving filenames and defines. Other classes may be used, as long as their interface matches that ofGetopt.pedantic=>1β Withpedanticset, rigorously obey the Verilog pedantic. This used to disable the`__FILE__and`__LINE__features but no longer does as they were added to the 1800-2009 standard. It remains to disable`errorand may disable other future features that are not specified in the language standard. Defaults false.synthesis=>1β Withsynthesisset, defineSYNTHESIS, and ignore text between"ambit","pragma","synopsys"or"synthesis"translate_offandtranslate_onmeta comments. Note using metacomments is discouraged as they have led to silicon bugs (versusifdef SYNTHESIS); seehttps://www.veripool.org/papers/TenIPEdits_SNUGBos07_paper.pdf.
π§ CALLBACKS π§
Default callbacks are implemented that are suitable for most applications. Derived classes may override these callbacks as needed.
$self->comment(comment)β Called with each comment, whenkeep_comments=>'sub'is used. Defaults to do nothing.$self->undef(defname)β Called with each`undef. Defaults to use options object.$self->undefineall()β Called with each`undefineall. Defaults to use options object.$self->define(defname, value, params)β Called with each`define. Defaults to use options object.$self->def_params(defname)β Called to determine if the define exists and the parameters it expects. Returnundefif the define doesn't exist,0if the define exists with no arguments, or argument list with leading parenthesis if the define has arguments. Defaults to use options object'sdefparamsmethod.$self->def_substitute(string)β Called to determine what string to insert for a define substitution. Called with the value of the define after parameters have been expanded computed per the SystemVerilog spec. Generally this function would just return the same string as it is passed, but this can be overridden to allow customized preprocessing.$self->def_value(defname)β Called to return value to substitute for specified define. Defaults to use options object.$self->error(message)β Called on errors, with the error message as an argument. Defaults todie.$self->include(filename)β Specifies a include file has been found. Defaults to call$self->openafter resolving the filename with theoptionsparameter.
π COMPLIANCE π
The preprocessor supports the constructs defined in the SystemVerilog 2017 standard (IEEE 1800-2017), which is a superset of Verilog 1995 (IEEE 1364-1995), Verilog 2001 (IEEE 1364-2001), Verilog 2005 (IEEE 1364-2005) SystemVerilog 2005 (IEEE 1800-2005), SystemVerilog 2009 (IEEE 1800-2009), and SystemVerilog 2012 (IEEE 1800-2012).
Verilog::Preproc adds the `error macro (unless the pedantic parameter is set.):
`__FILE__β The__FILE__define expands to the current filename as a string, like C++'s__FILE__. This was incorporated into to the 1800-2009 standard (but supported by Verilog-Perl since 2004!)`__LINE__β The__LINE__define expands to the current filename as a string, like C++'s__LINE__. This was incorporated into to the 1800-2009 standard (but supported by Verilog-Perl since 2004!)`error "string"β`errorwill be reported whenever it is encountered. (Like C++#error.)
These are useful for error macros, similar to assert() in C++.
π 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.
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.
π AUTHORS π
Wilson Snyder <wsnyder@wsnyder.org>
β SEE ALSO β
Verilog-Perl,Verilog::Language,Verilog::GetoptIO::File- This package is layered on a C++ interface which may be found in the kit.
okay that's the whole page! π this was Preproc(3) from perl v5.42.0, dated 2025-07-25. byeeee πβ¨
π¦ where this page comes from
- fedora 43: perl-Verilog-Perl 3.482-6.fc43 Β· LGPL-3.0-only OR Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms