Compiler/ModelSim.pm

filter: Statementstmt 12.5% 31 / 247 Branchbran 0.0% 0 / 128 Conditioncond 0.0% 0 / 35 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 39.1% 9 / 23 Podpod 0.0% 0 / 11 totaltotal 8.5% 40 / 466 CC 83 SCAR 55.8
CC
83
Cov
8%
_compile2
702.0
compile
272.0
_parse_modelsim_info
240.0
CRAP 264.4
« UnitName.pm ↑ Summary CompileTool.pm »
1 package Hardware::Vhdl::Automake::Compiler::ModelSim;
2 1 @ISA = ('Hardware::Vhdl::Automake::CompileTool');
3
4 1 ▶use Hardware::Vhdl::Automake::UnitName;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Hardware::Vhdl::Automake::CompileTool;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14
15 =head1 NAME
16
17 Hardware::Vhdl::Automake::Compiler::ModelSim - ModelSim compilation tool controller
18
19 =cut
20
21 0 ▶sub compile {
Subroutine compile: not called CC=16 SCAR=56.1
Pod undocumented
22 0 my $self = shift;
23 0 my $dunit = shift;
24
25 0 $self->ensure_library( $dunit->library );
26 0 chdir $self->{basedir};
27
28 # remember this dunit as passed to the compiler, but not compiled
29 0 my $dukey = $dunit->name->short_string;
30 0 $self->{compiled}{$dukey} = 0;
31
32 #my $libdir = $self->{lib_mapping}{$dunit->library};
33
34 # we must recompile if there is not compile info for the du or if the code digest has changed
35 0 my $ci = $dunit->get_compile_info( $self->toolid );
36
37 #~ if (exists $ci->{dependencies}) {
38 #~ print "$dukey depends on:\n";
39 #~ for my $ddu (@{$ci->{dependencies}}) {
40 #~ print " ".$ddu->name->short_string."\n";
41 #~ }
42 #~ } else {
43 #~ print "$dukey has no dependency info\n";
44 #~ }
45
46 0 my $uptodate = defined $ci->{digest};
47 0 my $reason = '';
48 0 ▶ if (!$uptodate) { $reason = "there is no record of any previous compilation of the design unit" }
Branch: 1 branch
BranchTrueFalseTotal
unless ($uptodate) 0 0 0
49
50 # we must recompile if the code digest has changed
51 0 ▶ if ($uptodate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uptodate) 0 0 0
52 0 $uptodate = $ci->{digest} eq $dunit->digest;
53 0 ▶ if (!$uptodate) { $reason = "code digest changed" }
Branch: 1 branch
BranchTrueFalseTotal
unless ($uptodate) 0 0 0
54 }
55
56 # we must recompile if the design unit is not in the library
57 0 ▶ if ($uptodate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uptodate) 0 0 0
58 0 ▶ unless (defined $ci->{compiled_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ci->{"compiled_name"}) 0 0 0
59 0 $uptodate=0;
60 0 $reason = "design unit is not listed in library info";
61 }
62 }
63
64 # we must recompile if the compiled file is missing
65 0 my $compfile = $self->compiled_file($dunit);
66 0 ▶ if ($uptodate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uptodate) 0 0 0
67 0 ▶ unless (defined $compfile && -f $compfile) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $compfile and -f $compfile) 0 0 0
Condition0%0/3
defined $compfile and -f $compfile
!ll&&!rl&&r
000
MC/DC0%0/2
defined $compfile and -f $compfile
defined $compfile -f $compfile
Truth table0%0/3
A and B
A= defined $compfileB= -f $compfile
ABresult
0X0
100
111
68 0 $uptodate=0;
69 0 $reason = "compiled data for design unit is missing";
70 }
71 }
72
73 # we must recompile if any of the du's dependencies have been recompiled since this dunit was recompiled
74 0 ▶ if ($uptodate && exists $ci->{dependencies}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uptodate and exists $ci->{"dependencies"}) 0 0 0
Condition0%0/3
$uptodate and exists $ci->{"dependencies"}
!ll&&!rl&&r
000
MC/DC0%0/2
$uptodate and exists $ci->{"dependencies"}
$uptodate exists $ci->{"dependencies"}
Truth table0%0/3
A and B
A= $uptodateB= exists $ci->{"dependencies"}
ABresult
0X0
100
111
75 0 my $bin_age = -M $compfile;
76 0 for my $ddu (@{$ci->{dependencies}}) {
77 0 my $dep_compfile = $self->compiled_file($ddu);
78 0 ▶ if (defined $dep_compfile && -f $dep_compfile && (-M $dep_compfile < $bin_age)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dep_compfile and -f $dep_compfile and -M $dep_compfile < $bin_age) 0 0 0
Condition0%0/6
defined $dep_compfile and -f $dep_compfile and -M $dep_compfile < $bin_age
!ll&&!rl&&r
000
defined $dep_compfile and -f $dep_compfile
!ll&&!rl&&r
000
MC/DC0%0/3
defined $dep_compfile and -f $dep_compfile and -M $dep_compfile < $bin_age
defined $dep_compfile -f $dep_compfile -M $dep_compfile < $bin_age
Truth table0%0/4
A and B and C
A= defined $dep_compfileB= -f $dep_compfileC= -M $dep_compfile < $bin_age
ABCresult
0XX0
10X0
1100
1111
79 0 $uptodate = 0;
80 0 $reason = "depended dunit ".$ddu->name->short_string." changed"; #: '$dep_compfile' is newer than '$compfile'";
81 0 last;
82 }
83 }
84 }
85
86 0 ▶ if ($uptodate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uptodate) { } 0 0 0
87 0 $self->report_status(
88 {
89 type => 'compile_skip',
90 text => 'Skipping ModelSim compile',
91 duname => $dunit->name,
92 file => $dunit->file,
93 }
94 );
95 } else {
96 0 $self->report_status(
97 {
98 type => 'compile',
99 text => 'Doing ModelSim compile',
100 duname => $dunit->name,
101 file => $dunit->file,
102 reason => $reason,
103 }
104 );
105
106 0 $self->_compile2($dunit);
107
108 0 $ci->{digest} = $dunit->digest;
109 0 $dunit->set_compile_info( $self->toolid, $ci );
110
111 # remember this dunit as compiled
112 0 $self->{compiled}{$dukey} = 1;
113 }
114 }
115
116 0 ▶sub init {
Subroutine init: not called CC=7 SCAR=40.3
Pod undocumented
117 0 my $self = shift;
118 0 my $arg1 = shift;
119
120 0 $self->{lib_mapping} = {};
121
122 0 ▶ if ( ref $arg1 eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg1 eq 'HASH') { } 0 0 0
123
124 # check required args
125 0 for my $argname (qw/ basedir /) {
126 0 ▶ croak "'$argname' parameter is required for new Compiler::ModelSim" unless exists $arg1->{$argname};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $arg1->{$argname} 0 0 0
127 }
128
129 # copy allowed args to self
130 0 for my $argname (qw/ basedir /) {
131 0 ▶ if ( exists $arg1->{$argname} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg1->{$argname}) 0 0 0
132 0 $self->{$argname} = $arg1->{$argname};
133 0 delete $arg1->{$argname};
134 }
135 }
136
137 # check there are no passed args left
138 0 ▶ if ( scalar keys %$arg1 ) { croak "unrecognised parameter(s) " . join( ', ', keys %$arg1 ) . " passed" }
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$arg1) 0 0 0
139 } else {
140 0 croak "Compiler::ModelSim::new should be passed a hashref of information";
141 }
142
143 #~ $self->set_modelsim_path("C:\\ProgramFiles\\FpgaAdv40\\Modeltech\\win32pe");
144 0 $self->set_modelsim_path("C:\\ProgramFiles\\Modeltech\\win32pe");
145 }
146
147 0 ▶sub set_modelsim_path {
Subroutine set_modelsim_path: not called CC=2 SCAR=17.9
Pod undocumented
148 0 my $self = shift;
149 0 $self->{modelsim_path} = shift;
150 0 for my $prog (qw/vlib vcom vlog vdel/) {
151 0 $self->{$prog} = catfile( $self->{modelsim_path}, $prog );
152 }
153 }
154
155 0 ▶sub compile_start {
Subroutine compile_start: not called CC=2 SCAR=17.9
Pod undocumented
156 0 my $self = shift;
157 0 $self->report_status( { type => 'compile_start', text => 'Starting ModelSim compilation' } );
158 0 $self->{compiled} = {};
159 0 ▶ unless (-f catfile( $self->{basedir}, 'modelsim.ini') ) { $self->write_modelsim_ini }
Branch: 1 branch
BranchTrueFalseTotal
unless (-f catfile($self->{"basedir"}, "modelsim.ini")) 0 0 0
160 }
161
162 0 ▶sub _compile2 {
Subroutine _compile2: not called CC=26 SCAR=65.5
163 0 my ($self, $dunit) = @_;
164 0 my @r;
165 my @deps;
166 0 my $lang = $dunit->sourcefile->language;
167 0 ▶ if ( defined $lang && $lang =~ /^Verilog$/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $lang and $lang =~ /^Verilog$/i) { } 0 0 0
elsif (defined $lang and $lang =~ /^VHDL/i) { } 0 0 0
Condition0%0/3
defined $lang and $lang =~ /^Verilog$/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $lang and $lang =~ /^Verilog$/i
defined $lang $lang =~ /^Verilog$/i
Truth table0%0/3
A and B
A= defined $langB= $lang =~ /^Verilog$/i
ABresult
0X0
100
111
168 0 @r = $self->sys_capture( [ $self->{vlog}, '-source', '-work', $dunit->library, $dunit->file ] );
169 ▶ } elsif ( defined $lang && $lang =~ /^VHDL/i ) {
Condition0%0/3
defined $lang and $lang =~ /^VHDL/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $lang and $lang =~ /^VHDL/i
defined $lang $lang =~ /^VHDL/i
Truth table0%0/3
A and B
A= defined $langB= $lang =~ /^VHDL/i
ABresult
0X0
100
111
170 0 my @opts;
171 0 ▶ push @opts, $dunit->get_compiler_option('vhdl_language_version') eq '87' ? '-87' : '-93';
Branch: 1 branch
BranchTrueFalseTotal
$dunit->get_compiler_option('vhdl_language_version') eq '87' ? : 0 0 0
172
173 0 my ($optname, $switchname);
174 # switches which we should set if the option is true
175 0 my %opt2switch = (
176 check_for_synthesis => '-check_synthesis', # Turns on limited synthesis rule compliance checking. Checks to see that signals read by a process are in the sensitivity list.
177 prefer_explicit_function_definition => '-explicit', # Directs the compiler to resolve ambiguous function overloading by favoring the explicit function definition over the implicit function definition.
178 ignore_vital_errors => '-ignorevitalerrors', # Directs the compiler to ignore VITAL compliance error
179 hide_internal_data => '-nodebug', # Hides the internal data of the compiled design unit
180 perform_default_binding => '-performdefaultbinding', # Enables default binding when it has been disabled via the RequireConfigForAllDefaultBinding option in the modelsim.ini file.
181 );
182 0 ▶ while (($optname, $switchname) = each (%opt2switch)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %opt2switch) 0 0 0
183 0 ▶ push @opts, $switchname if $dunit->get_compiler_option($optname);
Branch: 1 branch
BranchTrueFalseTotal
if $dunit->get_compiler_option($optname) 0 0 0
184 }
185
186 #~ push @opts, '-coverAll' if $dunit->get_compiler_option('check_for_synthesis'); #! bodge for coverage testing
187
188 # switches which we should set if the option is FALSE
189 %opt2switch = (
190 0 generate_default_binding => '-ignoredefaultbinding', # Instructs the compiler not to generate a default binding during compilation. You must explicitly bind all components in the design if you set this to false.
191 use_builtin_vital => '-novital', # If disabled, causes VCOM to use VHDL code for VITAL procedures rather than the accelerated and optimized timing and primitive packages built into the simulator kernel. Optional.
192 use_builtin_1164 => '-no1164', # Causes the source files to be compiled taking advantage of the built-in version of the IEEE std_logic_1164 package.
193 run_time_range_checks => '-nocheck', # In some designs, this could result in a 2X speed increase.
194 vital95_check => '-novitalcheck', # If disabled, disables VITAL95 compliance checking if you are using VITAL 2.2b.
195 error_case_static => '-nocasestaticerror', # Changes case static warnings into errors.
196 error_others_static => '-noothersstaticerror', # Enables errors that result from "others" clauses that are not locally static.
197 warn_unbound_component => ['-nowarn', 1],
198 warn_process_without_wait => ['-nowarn', 2],
199 warn_null_range => ['-nowarn', 3],
200 warn_no_space_in_time_literal => ['-nowarn', 4],
201 warn_multiple_drivers_on_unresolved_signal => ['-nowarn', 5],
202 warn_compliance => ['-nowarn', 6],
203 warn_optimization => ['-nowarn', 7],
204 );
205 0 ▶ while (($optname, $switchname) = each (%opt2switch)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %opt2switch) 0 0 0
206 0 ▶ push @opts, (ref $switchname ? @$switchname : $switchname) unless $dunit->get_compiler_option($optname);
Branch: 2 branches
BranchTrueFalseTotal
unless $dunit->get_compiler_option($optname) 0 0 0
ref $switchname ? : 0 0 0
207 }
208
209 0 @r = $self->sys_capture( [ $self->{vcom}, @opts, '-source', '-work', $dunit->library, $dunit->file ] );
210 #~ print "Command = <<".join(' ', $self->{vcom}, @opts, '-source', '-work', $dunit->library, $dunit->file).">>\n";
211 }
212 #~ print "Command output = <<".join("", @r).">>\n";
213 {
214
215 # scan the output for errors
216 0 ▶ $r[0] = '' if !defined $r[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r[0] 0 0 0
217 0 ▶ if ( $r[0] !~ /Model Technology ModelSim .* (vcom|vlog) .* Compiler/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r[0] =~ /Model Technology ModelSim .* (vcom|vlog) .* Compiler/i) 0 0 0
218 0 $self->report_status(
219 {
220 type => 'assert_fail',
221 text => 'First line of output from ModelSim compile command was not as expected',
222 got => $r[0],
223 expected => 'Model Technology ModelSim .* (vcom|vlog) .* Compiler',
224 }
225 );
226 0 croak "ModelSim compile failure";
227 }
228 0 shift @r;
229 0 my $sourceline = '';
230 0 my $where = '';
231 0 my $compile_error_flag = 0;
232 0 for my $rl (@r) {
233 0 ▶ if ( $rl =~ /^###### (.*)\((\d+)\):(.*)$/ ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($rl =~ /^###### (.*)\((\d+)\):(.*)$/) { } 0 0 0
elsif ($rl =~ /^(?:\*\* Warning|WARNING): (.*)\((\d+)\):(.*)$/) { } 0 0 0
elsif ($rl =~ /^(?:\*\* Error|ERROR): (.*)\((\d+)\):(.*)$/) { } 0 0 0
elsif ($rl =~ /^(?:\*\* Error|ERROR): (.*)$/) { } 0 0 0
234 0 $where = [ $1, $2 ];
235 0 $sourceline = $3;
236 } elsif ( $rl =~ /^(?:\*\* Warning|WARNING): (.*)\((\d+)\):(.*)$/ ) {
237 0 my $report = {
238 type => 'warning',
239 text => 'ModelSim compile warning; ' . $3,
240 duname => $dunit->name,
241 genfile => $1,
242 genlinenum => $2,
243 };
244 0 ▶ $report->{sourceline} = $sourceline if $1 eq $where->[0] && $2 == $where->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq $where->[0] and $2 == $where->[1] 0 0 0
Condition0%0/3
$1 eq $where->[0] and $2 == $where->[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$1 eq $where->[0] and $2 == $where->[1]
$1 eq $where->[0] $2 == $where->[1]
Truth table0%0/3
A and B
A= $1 eq $where->[0]B= $2 == $where->[1]
ABresult
0X0
100
111
245 0 my ($lfn, $lln) = $dunit->line_to_source($report->{genlinenum});
246 0 ▶ if (defined $lfn) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lfn) 0 0 0
247 0 $report->{srcfile} = $lfn;
248 0 $report->{srclinenum} = $lln;
249 }
250 0 $self->report_status($report);
251 } elsif ( $rl =~ /^(?:\*\* Error|ERROR): (.*)\((\d+)\):(.*)$/ ) {
252 0 my $report = {
253 type => 'error',
254 text => 'ModelSim compile error; ' . $3,
255 duname => $dunit->name,
256 genfile => $1,
257 genlinenum => $2,
258 };
259 0 ▶ $report->{sourceline} = $sourceline if $1 eq $where->[0] && $2 == $where->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq $where->[0] and $2 == $where->[1] 0 0 0
Condition0%0/3
$1 eq $where->[0] and $2 == $where->[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$1 eq $where->[0] and $2 == $where->[1]
$1 eq $where->[0] $2 == $where->[1]
Truth table0%0/3
A and B
A= $1 eq $where->[0]B= $2 == $where->[1]
ABresult
0X0
100
111
260 0 my ($lfn, $lln) = $dunit->line_to_source($report->{genlinenum});
261 0 ▶ if (defined $lfn) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lfn) 0 0 0
262 0 $report->{srcfile} = $lfn;
263 0 $report->{srclinenum} = $lln;
264 }
265 0 $self->report_status($report);
266 #~ if ( $report->{text} =~ /^ModelSim compile error; Could not find .*\\(\S+)\.(\S)\s*$/ ) {
267 #~ print "We may need to compile package $1.$2 first\n";
268 #~ }
269 0 $compile_error_flag = 1;
270 } elsif ( $rl =~ /^(?:\*\* Error|ERROR): (.*)$/ ) {
271 0 my $report = {
272 type => 'error',
273 text => 'ModelSim compile error; ' . $1,
274 duname => $dunit->name,
275 genfile => $dunit->file,
276 genlinenum => 1,
277 };
278 0 my ($lfn, $lln) = $dunit->line_to_source($report->{genlinenum});
279 0 ▶ if (defined $lfn) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lfn) 0 0 0
280 0 $report->{srcfile} = $lfn;
281 0 $report->{srclinenum} = $lln;
282 }
283 0 $self->report_status($report);
284 0 $compile_error_flag = 1;
285 }
286 }
287 0 ▶ if ($compile_error_flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compile_error_flag) 0 0 0
288 0 croak "compile error";
289 }
290
291 }
292 }
293
294 0 ▶sub compile_finish {
Subroutine compile_finish: not called CC=1 SCAR=6.9
Pod undocumented
295 0 my $self = shift;
296 0 $self->report_status( { type => 'compile_finish', text => 'Finished ModelSim compilation' } );
297 }
298
299 0 ▶sub compile_abort {
Subroutine compile_abort: not called CC=1 SCAR=6.9
Pod undocumented
300 0 my $self = shift;
301 0 $self->report_status( { type => 'compile_abort', text => 'Aborting ModelSim compilation' } );
302 }
303
304 0 ▶sub ensure_library {
Subroutine ensure_library: not called CC=5 SCAR=34.0
Pod undocumented
305 0 my $self = shift;
306 0 my $libname = shift;
307 0 my $libdir = catdir( $self->{basedir}, &name_to_filename($libname) );
308 0 ▶ unless ( -d $libdir && -f catfile( $libdir, '_info' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $libdir and -f catfile($libdir, "_info")) 0 0 0
Condition0%0/3
-d $libdir and -f catfile($libdir, "_info")
!ll&&!rl&&r
000
MC/DC0%0/2
-d $libdir and -f catfile($libdir, "_info")
-d $libdir -f catfile($libdir, "_info")
Truth table0%0/3
A and B
A= -d $libdirB= -f catfile($libdir, "_info")
ABresult
0X0
100
111
309 0 $self->report_status(
310 {
311 type => 'mklib',
312 text => 'Creating ModelSim library',
313 library => $libname,
314 location => $libdir,
315 }
316 );
317 0 mkpath(dirname($libdir));
318 0 $self->_vlib($libdir, $libname);
319 }
320 0 ▶ unless ( defined $self->{lib_mapping}{$libname} && $self->{lib_mapping}{$libname} eq $libdir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"lib_mapping"}{$libname} and $self->{"lib_mapping"}{$libname} eq $libdir) 0 0 0
Condition0%0/3
defined $self->{"lib_mapping"}{$libname} and $self->{"lib_mapping"}{$libname} eq $libdir
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"lib_mapping"}{$libname} and $self->{"lib_mapping"}{$libname} eq $libdir
defined $self->{"lib_mapping"}{$libname} $self->{"lib_mapping"}{$libname} eq $libdir
Truth table0%0/3
A and B
A= defined $self->{"lib_mapping"}{$libname}B= $self->{"lib_mapping"}{$libname} eq $libdir
ABresult
0X0
100
111
321 0 $self->{lib_mapping}{$libname} = $libdir;
322 0 $self->write_modelsim_ini;
323 }
324 }
325
326 0 ▶sub _vlib {
Subroutine _vlib: not called CC=3 SCAR=24.8
327 0 my ($self, $libdir, $libname) = @_;
328 0 ▶ my @r = $self->sys_capture( [ $self->{vlib}, $^O eq 'MSWin32' ? '-dos' : '-unix', $libdir ] );
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
329 0 ▶ if (@r) {
Branch: 1 branch
BranchTrueFalseTotal
if (@r) 0 0 0
330
331 # there should be no output unless there is an error
332 0 $self->report_status(
333 {
334 type => 'error',
335 text => 'vlib error: ' . join( '; ', @r ),
336 library => $libname,
337 location => $libdir,
338 }
339 );
340 0 croak 'vlib error: ' . join( '; ', @r );
341 }
342 }
343
344 0 ▶sub write_modelsim_ini {
Subroutine write_modelsim_ini: not called CC=3 SCAR=24.8
Pod undocumented
345 0 my $self = shift;
346 0 my $fh;
347 0 $self->report_status(
348 {
349 type => 'config',
350 text => 'Updating modelsim.ini',
351 }
352 );
353 0 ▶ open $fh, '>', catfile( $self->{basedir}, 'modelsim.ini' ) || croak "Couldn't write modelsim.ini:$!";
Condition0%0/3
catfile($self->{'basedir'}, 'modelsim.ini') || croak("Couldn't write modelsim.ini:$!")
l!l&&r!l&&!r
000
MC/DC0%0/2
catfile($self->{'basedir'}, 'modelsim.ini') || croak("Couldn't write modelsim.ini:$!")
catfile($self->{'basedir'}, 'modelsim.ini') croak("Couldn't write modelsim.ini:$!")
Truth table0%0/3
A || B
A= catfile($self->{'basedir'}, 'modelsim.ini')B= croak("Couldn't write modelsim.ini:$!")
ABresult
1X1
011
000
354 0 print $fh "[Library]\n";
355 0 print $fh "others = \$MODEL_TECH/../modelsim.ini\n";
356 0 ▶ while ( my ( $lib, $dir ) = each %{ $self->{lib_mapping} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"lib_mapping"};}) 0 0 0
357 0 print $fh "$lib = $dir\n";
358 }
359 0 close $fh;
360 }
361
362 0 ▶sub get_deps {
Subroutine get_deps: not called CC=2 SCAR=17.9
Pod undocumented
363 0 my $self = shift;
364 0 my $hdl2bin = {};
365 0 my $hdl2deps = {};
366 0 my ($lib, $libdir);
367 0 ▶ while ( ($lib, $libdir) = each %{$self->{lib_mapping}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"lib_mapping"};}) 0 0 0
368 0 $self->_parse_modelsim_info($libdir, $lib, $hdl2deps, $hdl2bin);
369 }
370 0 ($hdl2bin, $hdl2deps);
371 }
372
373 # this regex pattern captures a VHDL name: ((?:[A-Za-z][A-Za-z0-9_]*)|(?:\\.*?\\))
374 0 ▶sub _parse_modelsim_info {
Subroutine _parse_modelsim_info: not called CC=15 SCAR=54.8
375 0 my ($self, $libdir, $libname, $deps, $src2bin) = @_;
376 0 my $file = catfile($libdir, '_info');
377 0 my %dutypes = (
378 E => 'entity',
379 A => 'architecture',
380 C => 'configuration',
381 P => 'package',
382 B => 'package body',
383 v => 'Verilog unit',
384 );
385
386 0 my $fh;
387 0 ▶ -f $file || return ($deps, $src2bin);
Branch: 1 branch
BranchTrueFalseTotal
-f $file or return $deps, $src2bin 0 0 0
388 0 ▶ open $fh, "<$file" || die "Couldn't read ModelSim library info file '$file': $!\n";
Condition0%0/2
"<$file" || die("Couldn't read ModelSim library info file '${file}': $!\n")
l!l
00
MC/DC0%0/1
"<$file" || die("Couldn't read ModelSim library info file '${file}': $!\n")
"<$file"
Truth table0%0/2
A
A= "<$file"
Aresult
11
00
389
390 0 my $line;
391 0 my $cunit = {type => undef, source => undef, depends => []};
392 0 while (1) {
393 0 my $line = <$fh>;
394 0 ▶ if (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) { } 0 0 0
395 0 chomp $line;
396 } else {
397 0 $line = 'E_'; # dummy value to mark end of file
398 }
399 0 my $p = substr($line, 0, 1); # prefix
400 0 my $a = substr($line, 1); # arguments
401
402 0 ▶ if (exists $dutypes{$p}) {
Branch: 4 branches
BranchTrueFalseTotal
if (exists $dutypes{$p}) { } 0 0 0
elsif ($p eq 'D') { } 0 0 0
elsif ($p eq 'F') { } 0 0 0
elsif ($p eq 'n') { } 0 0 0
403
404 # new dunit data is starting
405 0 ▶ if (defined $cunit->{source}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cunit->{"source"}) 0 0 0
406 0 $deps->{$cunit->{source}} = $cunit->{depends};
407 0 $src2bin->{$cunit->{source}} = $cunit->{compiled_name};
408 }
409
410 # start a new set of info
411 $cunit = {
412 0 type => $dutypes{$p},
413 source => undef,
414 depends => [],
415 compiled_name => $a,
416 };
417
418 } elsif ($p eq 'D') {
419 # a dependency for the current dunit
420 0 ▶ if ($a =~ m/^(A) ((?:[A-Za-z][A-Za-z0-9_]*)|(?:\\.*?\\)) ((?:[A-Za-z][A-Za-z0-9_]*)|(?:\\.*?\\)) ((?:[A-Za-z][A-Za-z0-9_]*)|(?:\\.*?\\)) (\S{22,22})\s*$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($a =~ /^(A) ((?:[A-Za-z][A-Za-z0-9_]*)|(?:\\.*?\\)) ((?:[A-Za-z][A-Za-z0-9_]*)|(?:\\.*?\\)) ((?:[A-Za-z][A-Za-z0-9_]*)|(?:\\.*?\\)) (\S{22,22})\s*$/) { } 0 0 0
elsif ($a =~ /^([EPCBv]) ((?:[A-Za-z][A-Za-z0-9_]*)|(?:\\.*?\\)) ((?:[A-Za-z][A-Za-z0-9_]*)|(?:\\.*?\\))( \S{22,22})?\s*$/) { } 0 0 0
421 0 my ($type, $lib, $pname, $sname, $chash) = ($dutypes{$1}, $2, $3, $4, $5);
422 0 ▶ $lib = $libname if $lib eq 'work';
Branch: 1 branch
BranchTrueFalseTotal
if $lib eq "work" 0 0 0
423 0 push @{$cunit->{depends}}, Hardware::Vhdl::Automake::UnitName->new($type, $lib, $pname, $sname);
424 } elsif ($a =~ m/^([EPCBv]) ((?:[A-Za-z][A-Za-z0-9_]*)|(?:\\.*?\\)) ((?:[A-Za-z][A-Za-z0-9_]*)|(?:\\.*?\\))( \S{22,22})?\s*$/) {
425 0 my ($type, $lib, $pname, $chash) = ($dutypes{$1}, $2, $3, $4);
426 0 ▶ $lib = $libname if $lib eq 'work';
Branch: 1 branch
BranchTrueFalseTotal
if $lib eq "work" 0 0 0
427 0 push @{$cunit->{depends}}, Hardware::Vhdl::Automake::UnitName->new($type, $lib, $pname);
428 } else {
429 0 die "unrecognised line format at $file line $.: '$p$a'; stopped";
430 }
431 } elsif ($p eq 'F') {
432 # the filename of the source code that was compiled into the current dunit
433 0 $cunit->{source} = canonpath($a);
434 0 ▶ $cunit->{source} = lc $cunit->{source} if File::Spec->case_tolerant();
Branch: 1 branch
BranchTrueFalseTotal
if "File::Spec"->case_tolerant 0 0 0
435 } elsif ($p eq 'n') {
436 # the filename/dirname of the compiled dunit
437 0 $cunit->{compiled_name} = $a;
438 }
439 0 ▶ last if ($line eq 'E_');
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "E_" 0 0 0
440 }
441
442 0 ($deps, $src2bin);
443 }
444
445
446 0 ▶sub compiled_file {
Subroutine compiled_file: not called CC=9 SCAR=45.0
Pod undocumented
447 0 my $self = shift;
448 0 my $dunit = shift;
449 0 my $info = $dunit->get_compile_info(ref $self);
450 0 ▶ return undef unless defined $info->{compiled_name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $info->{"compiled_name"} 0 0 0
451 0 my $compiled_name = $info->{compiled_name};
452 0 my $libdir = $self->{lib_mapping}{$dunit->library};
453 0 my $cfile = undef;
454 0 ▶ if ( $dunit->type eq 'architecture' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($dunit->type eq 'architecture') { } 0 0 0
elsif ($dunit->type eq 'package body') { } 0 0 0
elsif ($dunit->type eq 'Verilog unit') { } 0 0 0
455 0 my $parent = $dunit->parent;
456 0 ▶ if (defined $parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent) 0 0 0
457 0 my $info = $parent->get_compile_info(ref $self);
458 0 ▶ $cfile = catfile( $libdir, $info->{compiled_name}, $compiled_name . '.dat' ) if defined $info->{compiled_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $info->{"compiled_name"} 0 0 0
459 }
460 } elsif ( $dunit->type eq 'package body' ) {
461 0 my $parent = $dunit->parent;
462 0 ▶ if (defined $parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent) 0 0 0
463 0 my $info = $parent->get_compile_info(ref $self);
464 0 ▶ $cfile = catfile( $libdir, $info->{compiled_name}, 'body.dat' ) if defined $info->{compiled_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $info->{"compiled_name"} 0 0 0
465 }
466 } elsif ( $dunit->type eq 'Verilog unit' ) {
467 0 $cfile = catfile( $libdir, $compiled_name, 'verilog.dat' );
468 } else { # entity, package, configuration:
469 0 $cfile = catfile( $libdir, $compiled_name, '_primary.dat' );
470 }
471 0 $cfile;
472 }
473
474 1 my $modelsim_filename_char_lookup;
475
476 0 ▶sub name_to_filename {
Subroutine name_to_filename: not called CC=4 SCAR=30.0
Pod undocumented
477 0 my $name = shift;
478 0 my $file = '';
479 0 ▶ if ( substr( $name, 0, 1 ) eq '\\' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($name, 0, 1) eq '\\') { } 0 0 0
480 0 for my $cc ( map { ord $_ } split( //, $name ) ) {
481 0 my $rc = $modelsim_filename_char_lookup->[ $cc ];
482 0 ▶ croak "Illegal character ($cc) in name '$name'" unless defined $rc;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rc 0 0 0
483 0 $file .= $rc;
484 }
485 } else {
486 0 $file = lc $name;
487 }
488 0 $file;
489 }
490
491 # lookup table for ModelSim identifier->filename character translation
492 # undef means that that character is not allowed.
493 1 $modelsim_filename_char_lookup = [
494 undef,
495 undef,
496 undef,
497 undef,
498 undef,
499 undef,
500 undef,
501 undef,
502 undef,
503 undef,
504 undef,
505 undef,
506 undef,
507 undef,
508 undef,
509 undef,
510 undef,
511 undef,
512 undef,
513 undef,
514 undef,
515 undef,
516 undef,
517 undef,
518 undef,
519 undef,
520 undef,
521 undef,
522 undef,
523 undef,
524 undef,
525 undef,
526 '@040',
527 '!',
528 '@042',
529 '#',
530 '$',
531 '%',
532 '&',
533 '\'',
534 '(',
535 ')',
536 '@052',
537 '+',
538 ',',
539 '-',
540 '.',
541 '@057',
542 '0',
543 '1',
544 '2',
545 '3',
546 '4',
547 '5',
548 '6',
549 '7',
550 '8',
551 '9',
552 '@072'
553 , # character 072 actually seems to just get mapped to ':', but this crashes compiler with "Cannot open file" error
554 ';',
555 '@074',
556 '=',
557 '@076',
558 '@077',
559 '@@',
560 '@a',
561 '@b',
562 '@c',
563 '@d',
564 '@e',
565 '@f',
566 '@g',
567 '@h',
568 '@i',
569 '@j',
570 '@k',
571 '@l',
572 '@m',
573 '@n',
574 '@o',
575 '@p',
576 '@q',
577 '@r',
578 '@s',
579 '@t',
580 '@u',
581 '@v',
582 '@w',
583 '@x',
584 '@y',
585 '@z',
586 '[',
587 '@134',
588 ']',
589 '^',
590 '_',
591 '`',
592 'a',
593 'b',
594 'c',
595 'd',
596 'e',
597 'f',
598 'g',
599 'h',
600 'i',
601 'j',
602 'k',
603 'l',
604 'm',
605 'n',
606 'o',
607 'p',
608 'q',
609 'r',
610 's',
611 't',
612 'u',
613 'v',
614 'w',
615 'x',
616 'y',
617 'z',
618 '{',
619 '@174',
620 '}',
621 '~',
622 undef,
623 undef,
624 undef,
625 undef,
626 undef,
627 undef,
628 undef,
629 undef,
630 undef,
631 undef,
632 undef,
633 undef,
634 undef,
635 undef,
636 undef,
637 undef,
638 undef,
639 undef,
640 undef,
641 undef,
642 undef,
643 undef,
644 undef,
645 undef,
646 undef,
647 undef,
648 undef,
649 undef,
650 undef,
651 undef,
652 undef,
653 undef,
654 undef,
655 ' ',
656 '¡',
657 '¢',
658 '£',
659 '¤',
660 '¥',
661 '¦',
662 '§',
663 '¨',
664 '©',
665 'ª',
666 '«',
667 '¬',
668 '­',
669 '®',
670 '¯',
671 '°',
672 '±',
673 '²',
674 '³',
675 '´',
676 'µ',
677 '¶',
678 '·',
679 '¸',
680 '¹',
681 'º',
682 '»',
683 '¼',
684 '½',
685 '¾',
686 '¿',
687 'À',
688 'Á',
689 'Â',
690 'Ã',
691 'Ä',
692 'Å',
693 'Æ',
694 'Ç',
695 'È',
696 'É',
697 'Ê',
698 'Ë',
699 'Ì',
700 'Í',
701 'Î',
702 'Ï',
703 'Ð',
704 'Ñ',
705 'Ò',
706 'Ó',
707 'Ô',
708 'Õ',
709 'Ö',
710 '×',
711 'Ø',
712 'Ù',
713 'Ú',
714 'Û',
715 'Ü',
716 'Ý',
717 'Þ',
718 'ß',
719 'à',
720 'á',
721 'â',
722 'ã',
723 'ä',
724 'å',
725 'æ',
726 'ç',
727 'è',
728 'é',
729 'ê',
730 'ë',
731 'ì',
732 'í',
733 'î',
734 'ï',
735 'ð',
736 'ñ',
737 'ò',
738 'ó',
739 'ô',
740 'õ',
741 'ö',
742 '÷',
743 'ø',
744 'ù',
745 'ú',
746 'û',
747 'ü',
748 'ý',
749 'þ',
750 'ÿ'
751 ];
752
753 1 1;
« UnitName.pm ↑ Summary CompileTool.pm »