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::Preproc; |
6
|
14
|
|
|
14
|
|
73798
|
use Carp; |
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
687
|
|
7
|
14
|
|
|
14
|
|
457
|
use Verilog::Getopt; |
|
14
|
|
|
|
|
22
|
|
|
14
|
|
|
|
|
357
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require DynaLoader; |
10
|
14
|
|
|
14
|
|
59
|
use base qw(DynaLoader); |
|
14
|
|
|
|
|
19
|
|
|
14
|
|
|
|
|
888
|
|
11
|
14
|
|
|
14
|
|
76
|
use strict; |
|
14
|
|
|
|
|
38
|
|
|
14
|
|
|
|
|
385
|
|
12
|
14
|
|
|
14
|
|
63
|
use vars qw($VERSION); |
|
14
|
|
|
|
|
24
|
|
|
14
|
|
|
|
|
14076
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '3.480'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
###################################################################### |
17
|
|
|
|
|
|
|
#### Configuration Section |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
bootstrap Verilog::Preproc; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#In Preproc.xs: |
22
|
|
|
|
|
|
|
# sub _new (class, keepcmt, linedir, pedantic, synthesis) |
23
|
|
|
|
|
|
|
# sub _open (class) |
24
|
|
|
|
|
|
|
# sub getall (class) |
25
|
|
|
|
|
|
|
# sub getline (class) |
26
|
|
|
|
|
|
|
# sub eof (class) |
27
|
|
|
|
|
|
|
# sub filename (class) |
28
|
|
|
|
|
|
|
# sub lineno (class) |
29
|
|
|
|
|
|
|
# sub unreadback (class, text) |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
###################################################################### |
32
|
|
|
|
|
|
|
#### Accessors |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
499
|
50
|
|
499
|
1
|
8806
|
my $class = shift; $class = ref $class if ref $class; |
|
499
|
|
|
|
|
1009
|
|
36
|
499
|
|
|
|
|
1619
|
my $self = {keep_comments=>1, |
37
|
|
|
|
|
|
|
keep_whitespace=>1, |
38
|
|
|
|
|
|
|
line_directives=>1, |
39
|
|
|
|
|
|
|
ieee_predefined=>1, |
40
|
|
|
|
|
|
|
pedantic=>0, |
41
|
|
|
|
|
|
|
synthesis=>0, |
42
|
|
|
|
|
|
|
options=>Verilog::Getopt->new(), # If the user didn't give one, still work! |
43
|
|
|
|
|
|
|
parent => undef, |
44
|
|
|
|
|
|
|
#include_open_nonfatal=>0, |
45
|
|
|
|
|
|
|
@_}; |
46
|
499
|
|
|
|
|
1004
|
bless $self, $class; |
47
|
|
|
|
|
|
|
# Sets $self->{_cthis} |
48
|
499
|
100
|
|
|
|
1506
|
$self->{keep_comments} = 2 if ($self->{keep_comments} eq 'sub'); |
49
|
499
|
50
|
|
|
|
1016
|
$self->{keep_comments} = 3 if ($self->{keep_comments} eq 'expand'); #TBD |
50
|
|
|
|
|
|
|
$self->_new($self, |
51
|
|
|
|
|
|
|
$self->{keep_comments}, |
52
|
|
|
|
|
|
|
$self->{keep_whitespace}, |
53
|
|
|
|
|
|
|
$self->{line_directives}, |
54
|
|
|
|
|
|
|
$self->{pedantic}, |
55
|
|
|
|
|
|
|
$self->{synthesis}, |
56
|
499
|
|
|
|
|
29485
|
); |
57
|
499
|
100
|
|
|
|
1749
|
if ($self->{synthesis}) { |
58
|
|
|
|
|
|
|
# Fourth argument 1 for cmdline - no `undefineall effect |
59
|
2
|
|
|
|
|
6
|
$self->define('SYNTHESIS',1,undef,1); |
60
|
|
|
|
|
|
|
} |
61
|
499
|
50
|
|
|
|
1050
|
if ($self->{ieee_predefined}) { |
62
|
499
|
|
|
|
|
1450
|
$self->define('SV_COV_START', 0,undef,1); |
63
|
499
|
|
|
|
|
1103
|
$self->define('SV_COV_STOP', 1,undef,1); |
64
|
499
|
|
|
|
|
1259
|
$self->define('SV_COV_RESET', 2,undef,1); |
65
|
499
|
|
|
|
|
1111
|
$self->define('SV_COV_CHECK', 3,undef,1); |
66
|
499
|
|
|
|
|
1052
|
$self->define('SV_COV_MODULE', 10,undef,1); |
67
|
499
|
|
|
|
|
1226
|
$self->define('SV_COV_HIER', 11,undef,1); |
68
|
499
|
|
|
|
|
1080
|
$self->define('SV_COV_ASSERTION', 20,undef,1); |
69
|
499
|
|
|
|
|
979
|
$self->define('SV_COV_FSM_STATE', 21,undef,1); |
70
|
499
|
|
|
|
|
1217
|
$self->define('SV_COV_STATEMENT', 22,undef,1); |
71
|
499
|
|
|
|
|
1090
|
$self->define('SV_COV_TOGGLE', 23,undef,1); |
72
|
499
|
|
|
|
|
1054
|
$self->define('SV_COV_OVERFLOW', -2,undef,1); |
73
|
499
|
|
|
|
|
1089
|
$self->define('SV_COV_ERROR', -1,undef,1); |
74
|
499
|
|
|
|
|
1119
|
$self->define('SV_COV_NOCOV', 0,undef,1); |
75
|
499
|
|
|
|
|
1090
|
$self->define('SV_COV_OK', 1,undef,1); |
76
|
499
|
|
|
|
|
960
|
$self->define('SV_COV_PARTIAL', 2,undef,1); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
#use Data::Dumper; print Dumper($self); |
79
|
499
|
|
|
|
|
1074
|
return $self; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub DESTROY { |
83
|
463
|
|
|
463
|
|
22248
|
my $self = shift; |
84
|
463
|
|
|
|
|
32593
|
$self->_DESTROY; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub STORABLE_freeze { |
88
|
1
|
|
|
1
|
0
|
455
|
my ($self, $cloning) = @_; |
89
|
|
|
|
|
|
|
# Prevent crash on Storable::store then retrieve |
90
|
1
|
|
|
|
|
2
|
delete $self->{_cthis}; |
91
|
1
|
|
|
|
|
85
|
return; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub open { |
95
|
555
|
|
|
555
|
1
|
3301
|
my $self = shift; |
96
|
555
|
|
|
|
|
866
|
my %params = ( |
97
|
|
|
|
|
|
|
# filename => |
98
|
|
|
|
|
|
|
# open_nonfatal => 0, |
99
|
|
|
|
|
|
|
); |
100
|
555
|
100
|
|
|
|
1180
|
if ($#_ > 0) { %params=(@_); } else { $params{filename}=shift; } |
|
33
|
|
|
|
|
127
|
|
|
522
|
|
|
|
|
992
|
|
101
|
|
|
|
|
|
|
# We allow either open(name) or open(filename=>name); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Allow user to put `defined names on the command line instead of filenames, |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# then convert them properly. |
106
|
555
|
|
|
|
|
787
|
my $filename = $params{filename}; |
107
|
555
|
|
|
|
|
1139
|
$filename = $self->remove_defines($filename); |
108
|
555
|
50
|
|
|
|
1229
|
printf ("Perl open $filename\n") if $self->{debug}; |
109
|
555
|
|
|
|
|
1358
|
$filename = $self->{options}->file_path($filename); |
110
|
555
|
50
|
|
|
|
1299
|
printf ("Perl openfp $filename\n") if $self->{debug}; |
111
|
555
|
100
|
|
|
|
6871
|
if (!-r $filename) { |
112
|
3
|
100
|
|
|
|
30
|
if (!$params{open_nonfatal}) { |
113
|
1
|
|
|
|
|
5
|
$self->error("Cannot open $filename"); |
114
|
|
|
|
|
|
|
} |
115
|
2
|
|
|
|
|
44
|
return undef; |
116
|
|
|
|
|
|
|
} else { |
117
|
552
|
|
|
|
|
49859
|
$self->_open($filename); |
118
|
|
|
|
|
|
|
} |
119
|
552
|
|
|
|
|
3142
|
return $self; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub debug { |
123
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
124
|
0
|
|
|
|
|
0
|
my $level = shift; |
125
|
0
|
|
|
|
|
0
|
$self->{debug} = $level; |
126
|
0
|
|
|
|
|
0
|
$self->_debug($level); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub parent { |
130
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
131
|
0
|
|
|
|
|
0
|
return $self->{parent}; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
###################################################################### |
135
|
|
|
|
|
|
|
#### Utilities |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub remove_defines { |
138
|
555
|
|
|
555
|
0
|
658
|
my $self = shift; |
139
|
555
|
|
|
|
|
599
|
my $sym = shift; |
140
|
555
|
|
|
|
|
634
|
my $val = "x"; |
141
|
555
|
|
|
|
|
1164
|
while (defined $val) { |
142
|
555
|
50
|
|
|
|
993
|
last if $sym eq $val; |
143
|
555
|
|
|
|
|
1056
|
(my $xsym = $sym) =~ s/^\`//; |
144
|
555
|
|
|
|
|
1509
|
$val = $self->{options}->defvalue_nowarn($xsym); #Undef if not found |
145
|
555
|
50
|
|
|
|
1347
|
$sym = $val if defined $val; |
146
|
|
|
|
|
|
|
} |
147
|
555
|
|
|
|
|
794
|
return $sym; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub fileline { |
151
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
152
|
0
|
|
0
|
|
|
0
|
return ($self->filename||"").":".($self->lineno||""); |
|
|
|
0
|
|
|
|
|
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
###################################################################### |
156
|
|
|
|
|
|
|
#### Called by the parser |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub error { |
159
|
1
|
|
|
1
|
1
|
2
|
my ($self,$text,$token)=@_; |
160
|
1
|
|
|
|
|
7
|
my $fileline = $self->filename.":".$self->lineno; |
161
|
1
|
|
|
|
|
181
|
croak ("%Error: $fileline: $text\n" |
162
|
|
|
|
|
|
|
."Stopped"); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
0
|
1
|
|
sub comment {} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub def_substitute { |
168
|
20
|
|
|
20
|
1
|
57
|
my ($self, $out) = @_; |
169
|
20
|
|
|
|
|
1777
|
return $out; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
sub include { |
172
|
33
|
|
|
33
|
1
|
3485
|
my ($self,$filename)=@_; |
173
|
33
|
50
|
|
|
|
94
|
print "INCLUDE $filename\n" if $self->{debug}; |
174
|
33
|
|
|
|
|
240
|
$self->{options}->includes($self->filename, $filename); |
175
|
|
|
|
|
|
|
$self->open(filename => $filename, |
176
|
|
|
|
|
|
|
open_nonfatal => $self->{include_open_nonfatal}, |
177
|
33
|
|
|
|
|
203
|
); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# Note rather than overriding these, a derived Verilog::Getopt class can |
181
|
|
|
|
|
|
|
# accomplish the same thing. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub undef { |
184
|
140
|
|
|
140
|
1
|
3948
|
my $self = shift; |
185
|
140
|
|
|
|
|
241
|
$self->{options}->undef(@_); |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
sub undefineall { |
188
|
19
|
|
|
19
|
1
|
1454
|
my $self = shift; |
189
|
19
|
|
|
|
|
40
|
$self->{options}->undefineall(@_); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
sub define { |
192
|
8519
|
|
|
8519
|
1
|
48028
|
my $self = shift; |
193
|
|
|
|
|
|
|
#print "DEFINE @_\n"; |
194
|
8519
|
|
|
|
|
32860
|
$self->{options}->fileline($self->filename.":".$self->lineno); |
195
|
8519
|
|
|
|
|
14440
|
$self->{options}->define(@_); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
sub def_params { |
198
|
|
|
|
|
|
|
# Return define parameters |
199
|
2529
|
|
|
2529
|
1
|
58757
|
my $self = shift; |
200
|
2529
|
|
|
|
|
4809
|
my $val = $self->{options}->defparams(@_); |
201
|
|
|
|
|
|
|
#printf "DEFPARAMS @_ -> %s\n", $val if $self->{debug}; |
202
|
2529
|
100
|
|
|
|
3851
|
$val = "" if !defined $val; |
203
|
2529
|
|
|
|
|
149281
|
return $val; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
sub def_value { |
206
|
|
|
|
|
|
|
# Return value |
207
|
1716
|
|
|
1716
|
1
|
2642
|
my $self = shift; |
208
|
|
|
|
|
|
|
#printf "DEFVALUE @_ -> %s\n", $self->{options}->defvalue_nowarn(@_); |
209
|
1716
|
|
|
|
|
3003
|
return $self->{options}->defvalue(@_); |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
###################################################################### |
213
|
|
|
|
|
|
|
#### Package return |
214
|
|
|
|
|
|
|
1; |
215
|
|
|
|
|
|
|
__END__ |