1Parser(3)             User Contributed Perl Documentation            Parser(3)
2
3
4

NAME

6       Verilog::Parser - Parse Verilog language files
7

SYNOPSIS

9         use Verilog::Parser;
10
11         my $parser = new Verilog::Parser;
12         $string = $parser->unreadback ();
13         $line   = $parser->lineno ();
14         $parser->parse ($text)
15         $parser->parse_file ($filename)
16

DESCRIPTION

18       Verilog::Parser will tokenize a Verilog file when the parse() method is
19       called and invoke various callback methods.  This is useful for
20       extracting information and editing files while retaining all context.
21       For netlist like extractions, see Verilog::Netlist.
22
23       See the "Which Package" section of Verilog::Language if you are unsure
24       which parsing package to use for a new application.
25
26       Note the parser allows some constructs that are syntax errors according
27       to the specification (for example "foo.bar(1)++".) This is done when
28       the parser can't easily detect these cases.  It's up to the consumer of
29       the parser to filter out such errors if it cares.
30

METHODS

32       $parser = Verilog::Parser->new (args...)
33           Create a new Parser.
34
35           Adding "symbol_table => []" will use the specified symbol table for
36           this parse, and modify the array reference to include those symbols
37           detected by this parse.  As the SystemVerilog language requires
38           packages and typedefs to exist before they are referenced, you must
39           pass the same symbol_table to subsequent parses that are for the
40           same compilation scope.  The internals of this symbol_table should
41           be considered opaque, as it will change between package versions,
42           and must not be modified by user code.
43
44           Adding "use_cb_{callback-name} => 0" will disable the specified
45           callback.  By default, all callbacks will be called; disabling
46           callbacks can greatly speed up the parser as a large percentage of
47           time is spent calling between C and Perl to invoke the callbacks.
48           When using this feature, use_unreadback=>0 should be used too, as
49           since whole tokens are skipped, skipping whitespace shouldn't
50           matter either.
51
52           Adding "use_std => 1" will add parsing of the SystemVerilog built-
53           in std:: package, or "use_std => 0" will disable it.  If
54           unspecified it is silently included (no callbacks will be involed)
55           when suspected to be necessary.
56
57           Adding "use_unreadback => 0" will disable later use of the
58           unreadback method, which may improve performance.
59
60           Adding "use_vars => 0" will disable contassign, defparam, pin, var
61           and port callbacks to Verilog::SigParser.  This can greatly speed
62           parsing when variable and interconnect information is not required.
63
64       $parser->callback_names ()
65           Return an array of callback function names.  This may be used to
66           automatically create callbacks for all functions, or to test for
67           different callback functionality between versions of Verilog-Perl.
68
69       $parser->eof ()
70           Indicate the end of the input stream.  All incomplete tokens will
71           be parsed and all remaining callbacks completed.
72
73       $parser->filename ($set)
74           Return (if $set is undefined) or set current filename.
75
76       $parser->lineno ($set)
77           Return (if $set is undefined) or set current line number.
78
79       $parser->parse ($string)
80           Parse the $string as verilog text.  Can be called multiple times.
81           Note not all callbacks may be invoked until the eof method is
82           called.
83
84       $parser->parse_file ($filename);
85           This method can be called to parse text from a file.  The argument
86           can be a filename or an already opened file handle. The return
87           value from parse_file() is a reference to the parser object.
88
89       $parser->parse_preproc_file ($preproc);
90           This method can be called to parse preprocessed text from a
91           predeclared Verilog::Preproc object.
92
93       $parser->unreadback ($string)
94           Return any input string from the file that has not been sent to the
95           callback.  This will include whitespace and tokens which did not
96           have a callback.  (For example comments, if there is no comment
97           callback.)  This is useful for recording the entire contents of the
98           input, for preprocessors, pretty-printers, and such.
99
100           With the optional argument, set the text to be returned with the
101           next unreadback call.  See also unreadbackCat, which is much
102           faster.
103
104           To use this option, "use_unreadback => 1" must have been passed to
105           the constructor.
106
107       $parser->unreadbackCat ($text)
108           Add text to be returned with the next unreadback call.  This is
109           much faster than using "$parser->unreadback($parser->unreadback .
110           $text)".
111

CALLBACKS

113       In order to make the parser do anything interesting, you must make a
114       subclass where you override one or more of the following callback
115       methods as appropriate.
116
117       $self->attribute ( $token )
118           This method is called when any text in (* *) are recognized.  The
119           first argument, $token, is the contents of the attribute including
120           the delimiters.
121
122       $self->comment ( $token )
123           This method is called when any text in // or /**/ comments are
124           recognized.  The first argument, $token, is the contents of the
125           comment including the comment delimiters.
126
127       $self->endparse ( $token )
128           This method is called when the file has been completely parsed, at
129           the End-Of-File of the parsed file.  It is useful for writing clean
130           up routines.
131
132       $self->keyword ( $token )
133           This method is called when any Verilog keyword is recognized.  The
134           first argument, $token, is the keyword.
135
136       $self->number ( $token )
137           This method is called when any number is recognized.  The first
138           argument, $token, is the number.  The
139           Verilog::Language::number_value function may be useful for
140           converting a Verilog value to a Perl integer.
141
142       $self->operator ( $token )
143           This method is called when any symbolic operator (+, -, etc) is
144           recognized.  The first argument, $token, is the operator.
145
146       $self->preproc ( $token )
147           This method is called when any Verilog preprocessor `command is
148           recognized.  Most of these are handled by the preprocessor, however
149           any unrecognized `defines are passed through.  For backward
150           compatibility, if not defined this function will call the symbol
151           callback.
152
153       $self->string ( $token )
154           This method is called when any text in double quotes are
155           recognized, or on the text of protected regions.  The first
156           argument, $token, is the contents of the string including the
157           quotes.
158
159       $self->symbol ( $token )
160           This method is called when any Verilog symbol is recognized.  A
161           symbol is considered a non-keyword bare-word.  The first argument,
162           $token, is the symbol.
163
164       $self->sysfunc ( $token )
165           This method is called when any Verilog $syscall is recognized.  The
166           first argument, $token, is the symbol.  For backward compatibility,
167           if not defined this function will call the symbol callback.
168

EXAMPLE

170       Here's a simple example which will print every symbol in a verilog
171       file.
172
173         package MyParser;
174         use Verilog::Parser;
175         @ISA = qw(Verilog::Parser);
176
177         # parse, parse_file, etc are inherited from Verilog::Parser
178         sub new {
179             my $class = shift;
180             #print "Class $class\n";
181             my $self = $class->SUPER::new();
182             bless $self, $class;
183             return $self;
184         }
185
186         sub symbol {
187             my $self = shift;
188             my $token = shift;
189
190             $self->{symbols}{$token}++;
191         }
192
193         sub report {
194             my $self = shift;
195
196             foreach my $sym (sort keys %{$self->{symbols}}) {
197                printf "Symbol %-30s occurs %4d times\n",
198                $sym, $self->{symbols}{$sym};
199             }
200         }
201
202         package main;
203
204         my $parser = MyParser->new();
205         $parser->parse_file (shift);
206         $parser->report();
207

BUGS

209       This is being distributed as a baseline for future contributions.
210       Don't expect a lot, the Parser is still naive, and there are many
211       awkward cases that aren't covered.
212
213       The parser currently assumes the string it is passed ends on a newline
214       boundary.  It should be changed to allow arbitrary chunks.
215
216       Cell instantiations without any arguments are not supported, an empty
217       set of parenthesis are required.  (Use "cell cell();", not "cell
218       cell;".)
219

DISTRIBUTION

221       Verilog-Perl is part of the <http://www.veripool.org/> free Verilog EDA
222       software tool suite.  The latest version is available from CPAN and
223       from http://www.veripool.org/verilog-perl
224       <http://www.veripool.org/verilog-perl>.
225
226       Copyright 2000-2010 by Wilson Snyder.  This package is free software;
227       you can redistribute it and/or modify it under the terms of either the
228       GNU Lesser General Public License Version 3 or the Perl Artistic
229       License Version 2.0.
230

AUTHORS

232       Wilson Snyder <wsnyder@wsnyder.org>
233

SEE ALSO

235       Verilog-Perl, Verilog::Preproc, Verilog::SigParser, Verilog::Language,
236       Verilog::Netlist, Verilog::Getopt, vrename, vpassert vppreproc
237
238
239
240perl v5.12.2                      2010-10-25                         Parser(3)
Impressum