line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Verilog - Verilog Perl Interface |
2
|
|
|
|
|
|
|
# See copyright, etc in below POD section. |
3
|
|
|
|
|
|
|
###################################################################### |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Verilog::Parser; |
6
|
11
|
|
|
11
|
|
75410
|
use Carp; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
498
|
|
7
|
11
|
|
|
11
|
|
4323
|
use Verilog::Getopt; |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
310
|
|
8
|
11
|
|
|
11
|
|
4757
|
use Verilog::Language; |
|
11
|
|
|
|
|
28
|
|
|
11
|
|
|
|
|
415
|
|
9
|
11
|
|
|
11
|
|
3748
|
use Verilog::Std; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
364
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require DynaLoader; |
12
|
11
|
|
|
11
|
|
54
|
use base qw(DynaLoader); |
|
11
|
|
|
|
|
19
|
|
|
11
|
|
|
|
|
680
|
|
13
|
|
|
|
|
|
|
|
14
|
11
|
|
|
11
|
|
50
|
use strict; |
|
11
|
|
|
|
|
168
|
|
|
11
|
|
|
|
|
226
|
|
15
|
11
|
|
|
11
|
|
40
|
use vars qw($VERSION $Debug); |
|
11
|
|
|
|
|
16
|
|
|
11
|
|
|
|
|
12054
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$VERSION = '3.480'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#$Debug sets the default value for debug. You're better off with the object method though. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @_Callback_Names = qw( |
22
|
|
|
|
|
|
|
attribute |
23
|
|
|
|
|
|
|
endparse |
24
|
|
|
|
|
|
|
keyword |
25
|
|
|
|
|
|
|
number |
26
|
|
|
|
|
|
|
operator |
27
|
|
|
|
|
|
|
preproc |
28
|
|
|
|
|
|
|
string |
29
|
|
|
|
|
|
|
symbol |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
###################################################################### |
33
|
|
|
|
|
|
|
#### Configuration Section |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
bootstrap Verilog::Parser; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#In Parser.xs: |
38
|
|
|
|
|
|
|
# sub _new (class, sigparser) |
39
|
|
|
|
|
|
|
# sub _open (class) |
40
|
|
|
|
|
|
|
# sub _debug (class, level) |
41
|
|
|
|
|
|
|
# sub _prologe (class, flag) |
42
|
|
|
|
|
|
|
# sub _callback_master_enable |
43
|
|
|
|
|
|
|
# sub _use_cb (class, name, flag) |
44
|
|
|
|
|
|
|
# sub parse (class) |
45
|
|
|
|
|
|
|
# sub eof (class) |
46
|
|
|
|
|
|
|
# sub filename (class, [setit]) |
47
|
|
|
|
|
|
|
# sub lineno (class, [setit]) |
48
|
|
|
|
|
|
|
# sub unreadback (class, [setit]) |
49
|
|
|
|
|
|
|
# sub unreadbackCat (class, add) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
###################################################################### |
52
|
|
|
|
|
|
|
#### Constructors |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub new { |
55
|
490
|
50
|
|
490
|
1
|
1261
|
my $class = shift; $class = ref $class if ref $class; |
|
490
|
|
|
|
|
892
|
|
56
|
490
|
|
|
|
|
3666
|
my $self = {_sigparser=>0, |
57
|
|
|
|
|
|
|
symbol_table=>[], # .xs will init further for us |
58
|
|
|
|
|
|
|
use_vars => 1, |
59
|
|
|
|
|
|
|
use_unreadback => 1, # Backward compatibility |
60
|
|
|
|
|
|
|
use_protected => 1, # Backward compatibility |
61
|
|
|
|
|
|
|
use_pinselects => 0, # Backward compatibility |
62
|
|
|
|
|
|
|
use_std => undef, # Undef = silent |
63
|
|
|
|
|
|
|
#use_cb_{callback-name} => 0/1 |
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
#_debug # Don't set, use debug() accessor to change level |
66
|
|
|
|
|
|
|
@_}; |
67
|
|
|
|
|
|
|
|
68
|
490
|
|
|
|
|
841
|
bless $self, $class; |
69
|
|
|
|
|
|
|
# Sets $self->{_cthis} |
70
|
|
|
|
|
|
|
$self->_new($self, |
71
|
|
|
|
|
|
|
# Options go here |
72
|
|
|
|
|
|
|
$self->{symbol_table}, |
73
|
|
|
|
|
|
|
$self->{_sigparser}, |
74
|
|
|
|
|
|
|
$self->{use_unreadback}, |
75
|
|
|
|
|
|
|
$self->{use_protected}, |
76
|
|
|
|
|
|
|
$self->{use_pinselects}, # Undocumented as for use in SigParser only |
77
|
490
|
|
|
|
|
13939
|
); |
78
|
|
|
|
|
|
|
|
79
|
490
|
50
|
|
|
|
1915
|
$self->{use_cb_contassign} = $self->{use_vars} if !exists $self->{use_cb_contassign}; |
80
|
490
|
50
|
|
|
|
1153
|
$self->{use_cb_defparam} = $self->{use_vars} if !exists $self->{use_cb_defparam}; |
81
|
490
|
50
|
|
|
|
1032
|
$self->{use_cb_pin} = $self->{use_vars} if !exists $self->{use_cb_pin}; |
82
|
490
|
50
|
|
|
|
981
|
$self->{use_cb_port} = $self->{use_vars} if !exists $self->{use_cb_port}; |
83
|
490
|
50
|
|
|
|
1019
|
$self->{use_cb_var} = $self->{use_vars} if !exists $self->{use_cb_var}; |
84
|
|
|
|
|
|
|
|
85
|
490
|
|
|
|
|
550
|
foreach my $key (keys %{$self}) { |
|
490
|
|
|
|
|
2706
|
|
86
|
9994
|
100
|
|
|
|
17725
|
if ($key =~ /^use_cb_(.*)/) { |
87
|
4123
|
|
|
|
|
11119
|
$self->_use_cb($1, $self->{$key}); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
490
|
|
|
|
|
1820
|
$self->language(Verilog::Language::language_standard()); |
92
|
490
|
50
|
|
|
|
963
|
$self->debug($Debug) if $Debug; |
93
|
490
|
|
|
|
|
953
|
return $self; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub DESTROY { |
97
|
490
|
|
|
490
|
|
72203
|
my $self = shift; |
98
|
490
|
|
|
|
|
36079
|
$self->_DESTROY; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
###################################################################### |
102
|
|
|
|
|
|
|
#### Accessors |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub callback_names { |
105
|
2
|
|
|
2
|
1
|
5347
|
my @out = sort @_Callback_Names; |
106
|
2
|
|
|
|
|
7
|
return @out; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub debug { |
110
|
1447
|
|
|
1447
|
0
|
1756
|
my $self = shift; |
111
|
1447
|
|
|
|
|
1534
|
my $level = shift; |
112
|
1447
|
100
|
|
|
|
2376
|
if (defined $level) { |
113
|
459
|
|
|
|
|
1238
|
$self->{_debug} = $level; |
114
|
459
|
|
|
|
|
1670
|
$self->_debug($level); |
115
|
|
|
|
|
|
|
} |
116
|
1447
|
|
|
|
|
2328
|
return $self->{_debug}; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub fileline { |
120
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
121
|
0
|
|
0
|
|
|
0
|
return ($self->filename||"").":".($self->lineno||""); |
|
|
|
0
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
0
|
0
|
0
|
sub line { return lineno(@_); } # Old, now undocumented |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
####################################################################### |
127
|
|
|
|
|
|
|
#### Methods |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub reset { |
130
|
489
|
|
|
489
|
0
|
609
|
my $self = shift; |
131
|
489
|
|
|
|
|
1054
|
$self->std; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub std { |
135
|
515
|
|
|
515
|
0
|
618
|
my $self = shift; |
136
|
515
|
|
66
|
|
|
1957
|
my $quiet = !defined $self->{use_std} && $self->{_sigparser}; |
137
|
515
|
100
|
66
|
|
|
2319
|
if (!$self->{symbol_table}[2]->{std} # Not in the symbol table yet |
|
|
|
100
|
|
|
|
|
138
|
|
|
|
|
|
|
&& ($self->{use_std} || $quiet) |
139
|
|
|
|
|
|
|
) { |
140
|
459
|
50
|
|
|
|
869
|
print "Including std::\n" if $self->{_debug}; |
141
|
459
|
|
|
|
|
948
|
my $olddbg = $self->debug; |
142
|
459
|
50
|
|
|
|
798
|
if ($quiet) { |
143
|
459
|
50
|
|
|
|
769
|
print "Disabling debug during std:: loading\n" if $self->{_debug}; |
144
|
459
|
|
|
|
|
775
|
$self->debug(0); |
145
|
459
|
|
|
|
|
1045
|
$self->_callback_master_enable(0); # //verilog-perl callbacks off |
146
|
|
|
|
|
|
|
} |
147
|
459
|
|
|
|
|
50447
|
$self->eof; #Flush user code before callback disable |
148
|
459
|
|
|
|
|
1756
|
$self->parse(Verilog::Std::std); |
149
|
459
|
|
|
|
|
205430
|
$self->eof; |
150
|
459
|
50
|
|
|
|
1871
|
if ($quiet) { |
151
|
459
|
|
|
|
|
1432
|
$self->_callback_master_enable(1); # //verilog-perl callbacks on |
152
|
459
|
|
|
|
|
1053
|
$self->debug($olddbg); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub parse_file { |
158
|
|
|
|
|
|
|
# Read a file and parse |
159
|
0
|
0
|
|
0
|
1
|
0
|
@_ == 2 or croak 'usage: $parser->parse_file($filename)'; |
160
|
0
|
|
|
|
|
0
|
my $self = shift; |
161
|
0
|
|
|
|
|
0
|
my $filename = shift; |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
0
|
my $fh = new IO::File; |
164
|
0
|
0
|
|
|
|
0
|
$fh->open($filename) or croak "%Error: $! $filename"; |
165
|
0
|
|
|
|
|
0
|
$self->reset(); |
166
|
0
|
|
|
|
|
0
|
$self->filename($filename); |
167
|
0
|
|
|
|
|
0
|
$self->lineno(1); |
168
|
0
|
|
|
|
|
0
|
while (defined(my $line = $fh->getline())) { |
169
|
0
|
|
|
|
|
0
|
$self->parse($line); |
170
|
|
|
|
|
|
|
} |
171
|
0
|
|
|
|
|
0
|
$self->eof; |
172
|
0
|
|
|
|
|
0
|
$fh->close; |
173
|
0
|
|
|
|
|
0
|
return $self; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub parse_preproc_file { |
177
|
|
|
|
|
|
|
# Read a preprocess file and parse |
178
|
463
|
50
|
|
463
|
1
|
1848
|
@_ == 2 or croak 'usage: $parser->parse_file(Verilog::Preproc_object_ref)'; |
179
|
463
|
|
|
|
|
762
|
my $self = shift; |
180
|
463
|
|
|
|
|
629
|
my $pp = shift; |
181
|
|
|
|
|
|
|
|
182
|
463
|
50
|
|
|
|
1027
|
ref($pp) or croak "%Error: not passed a Verilog::Preproc object"; |
183
|
463
|
|
|
|
|
1242
|
$self->reset(); |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# Chunk size of ~32K determined experimentally with t/49_largeish.t |
186
|
463
|
|
|
|
|
205556
|
while (defined(my $text = $pp->getall(31*1024))) { |
187
|
487
|
|
|
|
|
88858
|
$self->parse($text); |
188
|
|
|
|
|
|
|
} |
189
|
463
|
|
|
|
|
31943
|
$self->eof; |
190
|
463
|
|
|
|
|
9150
|
return $self; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
###################################################################### |
194
|
|
|
|
|
|
|
#### Called by the parser |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub error { |
197
|
0
|
|
|
0
|
0
|
0
|
my ($self,$text,$token)=@_; |
198
|
0
|
|
|
|
|
0
|
my $fileline = $self->filename.":".$self->lineno; |
199
|
0
|
|
|
|
|
0
|
croak("%Error: $fileline: $text\n" |
200
|
|
|
|
|
|
|
."Stopped"); |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub attribute { |
204
|
|
|
|
|
|
|
# Default Internal callback |
205
|
153
|
|
|
153
|
1
|
262
|
my $self = shift; # Parser invoked |
206
|
153
|
|
|
|
|
256
|
my $token = shift; # What token was parsed |
207
|
153
|
|
|
|
|
896
|
$self->unreadbackCat($token); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub comment { |
211
|
|
|
|
|
|
|
# Default Internal callback |
212
|
3950
|
|
|
3950
|
1
|
4108
|
my $self = shift; # Parser invoked |
213
|
3950
|
|
|
|
|
3843
|
my $token = shift; # What token was parsed |
214
|
3950
|
|
|
|
|
23481
|
$self->unreadbackCat($token); |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub string { |
218
|
|
|
|
|
|
|
# Default Internal callback |
219
|
1039
|
|
|
1039
|
1
|
1439
|
my $self = shift; # Parser invoked |
220
|
1039
|
|
|
|
|
1197
|
my $token = shift; # What token was parsed |
221
|
1039
|
|
|
|
|
4767
|
$self->unreadbackCat($token); |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub keyword { |
225
|
|
|
|
|
|
|
# Default Internal callback |
226
|
64129
|
|
|
64129
|
1
|
123878
|
my $self = shift; # Parser invoked |
227
|
64129
|
|
|
|
|
59459
|
my $token = shift; # What token was parsed |
228
|
64129
|
|
|
|
|
316329
|
$self->unreadbackCat($token); |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub symbol { |
232
|
|
|
|
|
|
|
# Default Internal callback |
233
|
73618
|
|
|
73618
|
1
|
112775
|
my $self = shift; # Parser invoked |
234
|
73618
|
|
|
|
|
70638
|
my $token = shift; # What token was parsed |
235
|
73618
|
|
|
|
|
419917
|
$self->unreadbackCat($token); |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub operator { |
239
|
|
|
|
|
|
|
# Default Internal callback |
240
|
131317
|
|
|
131317
|
1
|
196985
|
my $self = shift; # Parser invoked |
241
|
131317
|
|
|
|
|
118714
|
my $token = shift; # What token was parsed |
242
|
131317
|
|
|
|
|
661546
|
$self->unreadbackCat($token); |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub preproc { |
246
|
|
|
|
|
|
|
# Default Internal callback |
247
|
1704
|
|
|
1704
|
1
|
14251
|
my $self = shift; # Parser invoked |
248
|
1704
|
|
|
|
|
2072
|
my $token = shift; # What token was parsed |
249
|
1704
|
50
|
|
|
|
4670
|
if (Verilog::Language::is_keyword($token)) { |
250
|
0
|
|
|
|
|
0
|
$self->keyword($token); # Do this for backward compatibility with Version 2.* |
251
|
|
|
|
|
|
|
} else { |
252
|
1704
|
|
|
|
|
3075
|
$self->symbol($token); # Do this for backward compatibility with Version 2.* |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
sub number { |
256
|
|
|
|
|
|
|
# Default Internal callback |
257
|
21977
|
|
|
21977
|
1
|
26615
|
my $self = shift; # Parser invoked |
258
|
21977
|
|
|
|
|
22399
|
my $token = shift; # What token was parsed |
259
|
21977
|
|
|
|
|
83088
|
$self->unreadbackCat($token); |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
sub sysfunc { |
263
|
|
|
|
|
|
|
# Default Internal callback - note the default action |
264
|
1655
|
|
|
1655
|
1
|
18111
|
my $self = shift; # Parser invoked |
265
|
1655
|
|
|
|
|
1907
|
my $token = shift; # What token was parsed |
266
|
1655
|
|
|
|
|
2575
|
$self->symbol($token); # Do this for backward compatibility with Version 2.* |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
sub endparse { |
270
|
|
|
|
|
|
|
# Default Internal callback |
271
|
486
|
|
|
486
|
1
|
2369
|
my $self = shift; # Parser invoked |
272
|
486
|
|
|
|
|
651
|
my $token = shift; # What token was parsed |
273
|
486
|
|
|
|
|
1643
|
$self->unreadbackCat($token); |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
###################################################################### |
277
|
|
|
|
|
|
|
#### Package return |
278
|
|
|
|
|
|
|
1; |
279
|
|
|
|
|
|
|
__END__ |