DesignUnit.pm

filter: Statementstmt 11.3% 28 / 247 Branchbran 0.0% 0 / 106 Conditioncond 0.0% 0 / 43 MC/DCmcdc 0.0% 0 / 28 Subroutinesub 24.3% 9 / 37 Podpod 0.0% 0 / 22 totaltotal 7.6% 37 / 483 CC 78 SCAR 53.6
CC
78
Cov
7%
entity_instance
702.0
do_component_inserts
210.0
new
182.0
CRAP 213.4
« CompileTool.pm ↑ Summary PreProcessor.pm »
1 package Hardware::Vhdl::Automake::DesignUnit;
2 # just a holder of information, at the moment
3 1 ▶use Hardware::Vhdl::Automake::UnitName;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Hardware::Vhdl::Automake::PreProcessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Temp qw/ tempfile /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
10
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13
14 0 ▶sub new { # class or object method, returns a new object
Subroutine new: not called CC=13 SCAR=52.0
Pod undocumented
15 0 my $class = shift;
16 0 my $arg1 = shift;
17
18 0 ▶ $class = ref $class || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
19 0 my $self={
20 sourcefile => undef,
21 file => undef,
22 name => undef,
23 compiler_options => {},
24 };
25
26 0 ▶ if (ref $arg1 eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg1 eq 'HASH') { } 0 0 0
27 # check required args
28 0 for my $argname (qw/ sourcefile type library pname line2source /) {
29 0 ▶ croak "'$argname' parameter is required for new $class" unless exists $arg1->{$argname};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $arg1->{$argname} 0 0 0
30 }
31
32 # create UnitName from given args
33 0 eval {
34 0 ▶ if (exists $arg1->{sname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg1->{'sname'}) { } 0 0 0
35 0 $self->{name} = Hardware::Vhdl::Automake::UnitName->new($arg1->{type}, $arg1->{library}, $arg1->{pname}, $arg1->{sname});
36 0 delete $arg1->{sname};
37 } else {
38 0 $self->{name} = Hardware::Vhdl::Automake::UnitName->new($arg1->{type}, $arg1->{library}, $arg1->{pname});
39 }
40 };
41 0 ▶ croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
42 0 for my $argname (qw/ type library pname sname /) { delete $arg1->{$argname} }
43
44 # copy other required args to self
45 0 for my $argname (qw/ sourcefile file digest line2source compile_after /) {
46 0 ▶ if (exists $arg1->{$argname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg1->{$argname}) { } 0 0 0
47 0 $self->{$argname} = $arg1->{$argname};
48 0 delete $arg1->{$argname};
49 } else {
50 0 croak "$class->new requires a '$argname' argument";
51 }
52 }
53
54 # copy these optional args to self if they are defined
55 0 for my $argname (qw/ component_inserts entheader_start entheader_end entheader_startline /) {
56 0 ▶ if (exists $arg1->{$argname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg1->{$argname}) 0 0 0
57 0 $self->{$argname} = $arg1->{$argname};
58 0 delete $arg1->{$argname};
59 }
60 }
61 # check there are no passed args left
62 0 ▶ if (scalar keys %$arg1) { croak "unrecognised parameter(s) ".join(', ', keys %$arg1)." passed to Hardware::Vhdl::Automake::DesignUnit constructor" }
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$arg1) 0 0 0
63 } else {
64 0 croak "${class}::new should be passed a hashref of information";
65 }
66
67 0 bless $self, $class;
68 }
69
70 0 ▶sub set_compiler_option {
Subroutine set_compiler_option: not called CC=1 SCAR=6.9
Pod undocumented
71 0 my ($self, $compopt, $optval) = @_;
72 0 $self->{compiler_options}{$compopt} = $optval;
73 }
74
75 0 ▶sub get_compiler_option {
Subroutine get_compiler_option: not called CC=2 SCAR=17.9
Pod undocumented
76 0 my ($self, $compopt) = @_;
77 0 ▶ defined $self->{compiler_options}{$compopt} ? $self->{compiler_options}{$compopt} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'compiler_options'}{$compopt} ? : 0 0 0
78 }
79
80 0 ▶sub line_to_source {
Subroutine line_to_source: not called CC=4 SCAR=30.0
Pod undocumented
81 # given a line number in the generated HDL, return the source file and line number it came from.
82 0 my $self = shift;
83 0 my $genline = shift;
84 # line2source => [
85 # [ <hdl_line>, <source_file>, <source_line> ],
86 # [ <hdl_line>, <source_file>, <source_line> ],
87 # ]
88 0 my $n = @{$self->{line2source}}; # no. of entries in the lookup table
89 0 ▶ if ($n>0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n > 0) { } 0 0 0
90 0 my $i = 0;
91 0 ▶ while ($i+1 < $n && $self->{line2source}[$i+1][0] <= $genline) { $i++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($i + 1 < $n and $self->{"line2source"}[$i + 1][0] <= $genline) 0 0 0
Condition0%0/3
$i + 1 < $n and $self->{"line2source"}[$i + 1][0] <= $genline
!ll&&!rl&&r
000
MC/DC0%0/2
$i + 1 < $n and $self->{"line2source"}[$i + 1][0] <= $genline
$i + 1 < $n $self->{"line2source"}[$i + 1][0] <= $genline
Truth table0%0/3
A and B
A= $i + 1 < $nB= $self->{"line2source"}[$i + 1][0] <= $genline
ABresult
0X0
100
111
92 0 ($self->{line2source}[$i][1], $self->{line2source}[$i][2] + $genline - $self->{line2source}[$i][0]);
93 } else {
94 0 (undef, 0);
95 }
96 }
97
98 0 ▶sub sourcefiles {
Subroutine sourcefiles: not called CC=4 SCAR=30.0
Pod undocumented
99 0 my $self = shift;
100 0 my @files = ($self->sourcefile->file);
101 0 my %got = ( $files[0] => undef );
102 0 for my $l2s (@{$self->{line2source}}) {
103 0 ▶ if (!exists $got{$l2s->[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $got{$l2s->[1]}) 0 0 0
104 0 push @files, $got{$l2s->[1]};
105 0 $got{$l2s->[1]} = undef;
106 }
107 }
108 0 ▶ wantarray ? @files : \@files;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
109 }
110
111 0 ▶sub dump_l2s {
Subroutine dump_l2s: not called CC=2 SCAR=17.9
Pod undocumented
112 0 my ($self, $where) = @_;
113 0 print "##### $where, line2source =\n";
114 0 for my $l2s (@{$self->{line2source}}) {
115 0 print "# $l2s->[0] -> $l2s->[1] line $l2s->[2]\n";
116 }
117 0 print "#####\n";
118 }
119
120 0 ▶sub _line_insert_prepare {
Subroutine _line_insert_prepare: not called CC=4 SCAR=30.0
121 0 my ($self, $insat) = @_;
122 #$self->dump_l2s('before _line_insert_prepare');
123 # prepare to add more hdl lines at hdl file line number $insat (do this before calls to _line_insert)
124 0 my $n = @{$self->{line2source}}; # no. of entries in the lookup table
125 0 my $i = 0;
126 0 ▶ while ($i+1 < $n && $self->{line2source}[$i+1][0] <= $insat+1) { $i++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($i + 1 < $n and $self->{"line2source"}[$i + 1][0] <= $insat + 1) 0 0 0
Condition0%0/3
$i + 1 < $n and $self->{"line2source"}[$i + 1][0] <= $insat + 1
!ll&&!rl&&r
000
MC/DC0%0/2
$i + 1 < $n and $self->{"line2source"}[$i + 1][0] <= $insat + 1
$i + 1 < $n $self->{"line2source"}[$i + 1][0] <= $insat + 1
Truth table0%0/3
A and B
A= $i + 1 < $nB= $self->{"line2source"}[$i + 1][0] <= $insat + 1
ABresult
0X0
100
111
127 0 ▶ if ($self->{line2source}[$i][0] != $insat+1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"line2source"}[$i][0] != $insat + 1) 0 0 0
128 0 splice @{$self->{line2source}}, $i+1, 0, [$insat+1, $self->line_to_source($insat+1)];
129 }
130 0 $self->{insat} = $insat;
131 0 $self->{l2sii} = $i+1;
132 #$self->dump_l2s('after _line_insert_prepare');
133 }
134
135 0 ▶sub _line_insert {
Subroutine _line_insert: not called CC=2 SCAR=17.9
136 0 my ($self, $sfn, $sln) = @_;
137 #print "# _line_insert at index $self->{l2sii}\n";
138 0 splice @{$self->{line2source}}, $self->{l2sii}, 0, [$self->{line2source}[$self->{l2sii}][0], $sfn, $sln];
139 0 $self->{l2sii}++;
140 0 for my $i ($self->{l2sii} .. @{$self->{line2source}}-1) {
141 0 $self->{line2source}[$i][0]++;
142 }
143 #$self->dump_l2s('after _line_insert');
144 }
145
146 0 ▶sub _line_insert_complete {
Subroutine _line_insert_complete: not called CC=1 SCAR=6.9
147 # tidy up after calls to _line_insert
148 0 my ($self) = @_;
149 0 delete $self->{insat};
150 0 delete $self->{l2sii};
151 }
152
153 0 ▶sub _tidy_line2source_table {
Subroutine _tidy_line2source_table: not called CC=4 SCAR=30.0
154 0 my ($self) = @_;
155 0 my $i = @{$self->{line2source}}-1;
156 0 ▶ while ($i>0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 0 0 0
157 0 ▶ if ($self->{line2source}[$i][1] eq $self->{line2source}[$i-1][1]
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"line2source"}[$i][1] eq $self->{"line2source"}[$i - 1][1] and $self->{"line2source"}[$i][2] - $self->{"line2source"}[$i - 1][2] == $self->{"line2source"}[$i][0] - $self->{"line2source"}[$i - 1][0]) 0 0 0
Condition0%0/3
$self->{"line2source"}[$i][1] eq $self->{"line2source"}[$i - 1][1] and $self->{"line2source"}[$i][2] - $self->{"line2source"}[$i - 1][2] == $self->{"line2source"}[$i][0] - $self->{"line2source"}[$i - 1][0]
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"line2source"}[$i][1] eq $self->{"line2source"}[$i - 1][1] and $self->{"line2source"}[$i][2] - $self->{"line2source"}[$i - 1][2] == $self->{"line2source"}[$i][0] - $self->{"line2source"}[$i - 1][0]
$self->{"line2source"}[$i][1] eq $self->{"line2source"}[$i - 1][1] $self->{"line2source"}[$i][2] - $self->{"line2source"}[$i - 1][2] == $self->{"line2source"}[$i][0] - $self->{"line2source"}[$i - 1][0]
Truth table0%0/3
A and B
A= $self->{"line2source"}[$i][1] eq $self->{"line2source"}[$i - 1][1]B= $self->{"line2source"}[$i][2] - $self->{"line2source"}[$i - 1][2] == $self->{"line2source"}[$i][0] - $self->{"line2source"}[$i - 1][0]
ABresult
0X0
100
111
158 && ($self->{line2source}[$i][2]-$self->{line2source}[$i-1][2])==($self->{line2source}[$i][0]-$self->{line2source}[$i-1][0])
159 ) {
160 0 splice @{$self->{line2source}}, $i, 1;
161 }
162 0 $i--;
163 }
164 #$self->dump_l2s('after _tidy_line2source_table');
165 }
166
167 0 ▶sub move_file {
Subroutine move_file: not called CC=6 SCAR=37.4
Pod undocumented
168 0 my $self = shift;
169 0 my $newname = shift;
170 0 ▶ croak "Can't move design unit HDL to '$newname': already exists as a directory" if -d $newname;
Branch: 1 branch
BranchTrueFalseTotal
if -d $newname 0 0 0
171 0 ▶ croak "Can't move design unit HDL to '$newname': source file is missing" unless -f $self->file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $self->file 0 0 0
172 0 ▶ copy($self->file, $newname) || croak "Failed to move design unit HDL to '$newname': $!";
Branch: 1 branch
BranchTrueFalseTotal
copy($self->file, $newname) or croak("Failed to move design unit HDL to '${newname}': $!") 0 0 0
173 0 ▶ unlink $self->file || warn "Failed to delete temporary file '".$self->file."' for '".$self->name->short_string."': $!";
Condition0%0/2
$self->file || warn(q[Failed to delete temporary file '] . $self->file . q[' for '] . $self->name->short_string . "': $!")
l!l
00
MC/DC0%0/1
$self->file || warn(q[Failed to delete temporary file '] . $self->file . q[' for '] . $self->name->short_string . "': $!")
$self->file
Truth table0%0/2
A
A= $self->file
Aresult
11
00
174 0 ▶ carp "Failed to delete temporary file '".$self->file."': it's still there" if -f $self->file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $self->file 0 0 0
175 0 $self->{file} = $newname;
176 }
177
178 0 ▶sub copy_compiler_info_from {
Subroutine copy_compiler_info_from: not called CC=1 SCAR=6.9
Pod undocumented
179 0 my ($self, $copyfrom) = @_;
180 0 $self->{compile_info} = $copyfrom->{compile_info};
181 }
182
183 # accessor functions
184 0 ▶sub name { $_[0]->{name} }
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
185 0 ▶sub sourcefile { $_[0]->{sourcefile} }
Subroutine sourcefile: not called CC=1 SCAR=6.9
Pod undocumented
186 0 ▶sub file { $_[0]->{file} }
Subroutine file: not called CC=1 SCAR=6.9
Pod undocumented
187 0 ▶sub digest { $_[0]->{digest} }
Subroutine digest: not called CC=1 SCAR=6.9
Pod undocumented
188 0 ▶sub compile_after { defined $_[0]->{compile_after} ? @{$_[0]->{compile_after}} : () }
Subroutine compile_after: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'compile_after'} ? : 0 0 0
189 0 ▶sub parent {
Subroutine parent: not called CC=2 SCAR=17.9
Pod undocumented
190 0 my $self = shift;
191 0 ▶ $self->{parent} = $_[0] if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
192 0 $self->{parent};
193 }
194
195 0 ▶sub type { $_[0]->{name}->type } # returns package, package body, entity, architecture, or configuration
Subroutine type: not called CC=1 SCAR=6.9
Pod undocumented
196 0 ▶sub library { $_[0]->{name}->library }
Subroutine library: not called CC=1 SCAR=6.9
Pod undocumented
197 0 ▶sub pname { $_[0]->{name}->pname }
Subroutine pname: not called CC=1 SCAR=6.9
Pod undocumented
198 0 ▶sub sname { $_[0]->{name}->sname }
Subroutine sname: not called CC=1 SCAR=6.9
Pod undocumented
199
200 0 ▶sub get_compile_info { defined $_[0]->{compile_info}{$_[1]} ? $_[0]->{compile_info}{$_[1]} : {} }
Subroutine get_compile_info: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'compile_info'}{$_[1]} ? : 0 0 0
201 0 ▶sub set_compile_info { $_[0]->{compile_info}{$_[1]} = $_[2] }
Subroutine set_compile_info: not called CC=1 SCAR=6.9
Pod undocumented
202
203 # generate phase 2 (insert component definitions) stuff
204
205 0 ▶sub do_component_inserts {
Subroutine do_component_inserts: not called CC=14 SCAR=53.5
Pod undocumented
206 # insert component declarations into the arch or package body hdl, taken from the entity declarations
207 0 my ($self, $status_callback, $ent_dunit_finder) = @_;
208 0 my $ci = $self->{component_inserts};
209 0 ▶ return unless defined $ci && @$ci>0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ci and @$ci > 0 0 0 0
Condition0%0/3
defined $ci and @$ci > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ci and @$ci > 0
defined $ci @$ci > 0
Truth table0%0/3
A and B
A= defined $ciB= @$ci > 0
ABresult
0X0
100
111
210
211 0 ▶ &{$status_callback}({
Branch: 1 branch
BranchTrueFalseTotal
if defined $status_callback 0 0 0
212 type => 'generate2',
213 text => 'Generating (pass 2)',
214 duname => $self->name,
215 }) if defined $status_callback;
216
217 # create new digest object
218 # open original dunit file for reading
219 0 my $fhi;
220 0 ▶ open $fhi, '<', $self->{file} || die "Could not read phase 1 HDL file: $!";
Condition0%0/2
$self->{'file'} || die("Could not read phase 1 HDL file: $!")
l!l
00
MC/DC0%0/1
$self->{'file'} || die("Could not read phase 1 HDL file: $!")
$self->{'file'}
Truth table0%0/2
A
A= $self->{'file'}
Aresult
11
00
221 # create new temp file
222 0 my ($fho, $newfile) = tempfile( "XXXXXXXX", DIR => dirname($self->{file}) );
223 0 my $digester = Digest::MD5->new;
224 0 for my $cii (@$ci) {
225 0 my ($pos, $linenum, $digest_at_insert, $lib, $pname) = @$cii;
226 # find the entity dunit from which we need to insert
227 0 my $ent_dunit = $ent_dunit_finder->($lib, $pname);
228 0 ▶ $self->_component_insert_error($status_callback, $linenum, "Component insertion error; entity $lib.$pname not found in project") unless defined $ent_dunit;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ent_dunit 0 0 0
229 0 my $entstart = $ent_dunit->{entheader_start};
230 0 ▶ $self->_component_insert_error($status_callback, $linenum, "Component insertion error; declaration of $lib.$pname was not found in entity HDL") unless defined $entstart;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entstart 0 0 0
231 0 my $entend = $ent_dunit->{entheader_end};
232 0 ▶ $self->_component_insert_error($status_callback, $linenum, "Component insertion error; end of declaration of $lib.$pname was not found in entity HDL") unless defined $entend;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entend 0 0 0
233
234 # copy from fi to fo up to position $pos
235 0 &_copy_part_file($fho, $fhi, $pos);
236 0 $self->_line_insert_prepare($linenum);
237 # feed $digest_at_insert into digester
238 0 $digester->add('--insert_at:'.$digest_at_insert.':');
239 # output a newline to fo
240 0 print $fho "\ncomponent $pname\n";
241 0 my @insert_command_pos = $self->line_to_source($linenum);
242 0 $self->_line_insert(@insert_command_pos);
243 # open the hdl file for the entity
244 0 my $linesource = Hardware::Vhdl::Automake::PreProcessor->new(no_processing => 1, sourcefile => $ent_dunit->file, startat => $entstart, endat => $entend, linenum => $ent_dunit->{entheader_startline});
245 0 my $lexer = Hardware::Vhdl::Lexer->new({linesource => $linesource});
246 0 my $head = '';
247 0 my ($token, $type);
248 0 ▶ while( (($token, $type) = $lexer->get_next_token) && defined $token) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $lexer->get_next_token and defined $token) 0 0 0
Condition0%0/3
() = $lexer->get_next_token and defined $token
!ll&&!rl&&r
000
MC/DC0%0/2
() = $lexer->get_next_token and defined $token
() = $lexer->get_next_token defined $token
Truth table0%0/3
A and B
A= () = $lexer->get_next_tokenB= defined $token
ABresult
0X0
100
111
249 #diag("$type: '$token'");
250 0 ▶ if (substr($type, 0, 1) eq 'c') {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($type, 0, 1) eq 'c') { } 0 0 0
elsif ($type eq 'wn') { } 0 0 0
251 0 $digester->add($token.' ');
252 } elsif ($type eq 'wn') {
253 0 $digester->add(chr(13));
254 0 $self->_line_insert($ent_dunit->line_to_source($linesource->linenum));
255 }
256 0 print $fho $token;
257 # feed token into digester if (substr($type, 0, 1) eq 'c');
258 }
259 0 $self->_line_insert($ent_dunit->line_to_source($linesource->linenum));
260 0 print $fho "\nend component;";
261 0 $self->_line_insert(@insert_command_pos);
262
263 # adjust line number refs
264 0 $self->_line_insert_complete;
265 }
266 0 &_copy_part_file($fho, $fhi, -s $self->{file});
267 # delete original dunit file, replace dunit file by temp file
268 0 close $fhi;
269 0 close $fho;
270 0 ▶ rename($newfile, $self->{file}) || die "Could not replace pass 1 HDL file: $!";
Branch: 1 branch
BranchTrueFalseTotal
rename $newfile, $self->{"file"} or die "Could not replace pass 1 HDL file: $!" 0 0 0
271 # append digest
272 0 $self->{digest} .= $digester->hexdigest;
273 0 $self->_tidy_line2source_table;
274 0 delete $self->{component_inserts};
275 }
276
277 0 ▶sub entity_instance {
Subroutine entity_instance: not called CC=26 SCAR=65.5
Pod undocumented
278 # if the design unit is an entity, feeds a component instantiation template into the function referenced by $add_output
279 0 my ($self, $add_output) = @_;
280 0 ▶ if ($self->name->type eq 'entity') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->name->type eq "entity") 0 0 0
281 0 my $entstart = $self->{entheader_start};
282 0 my $entend = $self->{entheader_end};
283 0 ▶ unless (defined $entstart && defined $entend) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $entstart and defined $entend) 0 0 0
Condition0%0/3
defined $entstart and defined $entend
!ll&&!rl&&r
000
MC/DC0%0/2
defined $entstart and defined $entend
defined $entstart defined $entend
Truth table0%0/3
A and B
A= defined $entstartB= defined $entend
ABresult
0X0
100
111
284 0 &{$add_output}("-- Instantiation template insertion error; declaration of ".$self->name->short_string." was not found in entity HDL\n");
285 0 return;
286 }
287 0 &{$add_output}(' '.$self->name->pname.'_i : '.$self->name->pname.' ');
288 # open the hdl file for the entity
289 0 my $linesource = Hardware::Vhdl::Automake::PreProcessor->new(no_processing => 1, sourcefile => $self->file, startat => $entstart, endat => $entend, linenum => $self->{entheader_startline});
290 0 my $tp = Hardware::Vhdl::Lexer->new({linesource => $linesource});
291 0 my $bd=0; # bracket depth
292 0 my $intype=0; # are we after the colon in the "identifiers : type" structure?
293 0 my @ids;
294 0 my $typeetc = '';
295 0 my ($tok, $tt);
296 0 ▶ while ((($tok, $tt) = $tp->get_next_token) && defined $tok) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $tp->get_next_token and defined $tok) 0 0 0
Condition0%0/3
() = $tp->get_next_token and defined $tok
!ll&&!rl&&r
000
MC/DC0%0/2
() = $tp->get_next_token and defined $tok
() = $tp->get_next_token defined $tok
Truth table0%0/3
A and B
A= () = $tp->get_next_tokenB= defined $tok
ABresult
0X0
100
111
297 #print " $bd $tt: '$tok'\n";
298 0 my $end=0;
299 0 ▶ if ($tt eq 'cp') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tt eq "cp") 0 0 0
300 0 ▶ if ($tok eq '(') {
Branch: 4 branches
BranchTrueFalseTotal
if ($tok eq '(') { } 0 0 0
elsif ($tok eq ')') { } 0 0 0
elsif ($bd == 1 and $tok eq ';') { } 0 0 0
elsif ($bd == 1 and $tok eq ':') { } 0 0 0
301 0 $bd++;
302 }
303 0 ▶ elsif ($tok eq ')') { $bd--; $end=1 if $bd==0; }
Branch: 1 branch
BranchTrueFalseTotal
if $bd == 0 0 0 0
304 0 ▶ elsif ($bd==1 && $tok eq ';') { $intype=0; $end=2 }
Condition0%0/3
$bd == 1 and $tok eq ";"
!ll&&!rl&&r
000
MC/DC0%0/2
$bd == 1 and $tok eq ";"
$bd == 1 $tok eq ";"
Truth table0%0/3
A and B
A= $bd == 1B= $tok eq ";"
ABresult
0X0
100
111
305 0 ▶ elsif ($bd==1 && $tok eq ':') { $intype=1 }
Condition0%0/3
$bd == 1 and $tok eq ":"
!ll&&!rl&&r
000
MC/DC0%0/2
$bd == 1 and $tok eq ":"
$bd == 1 $tok eq ":"
Truth table0%0/3
A and B
A= $bd == 1B= $tok eq ":"
ABresult
0X0
100
111
306 }
307 0 ▶ if ($end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end) 0 0 0
308 0 $end += @ids;
309 0 for my $id (@ids) {
310 0 ▶ &{$add_output}(" $id => $id".($end==2 ? '' : ',')." --$typeetc\n");
Branch: 1 branch
BranchTrueFalseTotal
$end == 2 ? : 0 0 0
311 0 $end--;
312 }
313 0 @ids=();
314 0 $typeetc='';
315 0 $intype=0;
316 }
317 0 ▶ if ($bd==0) {
Branch: 4 branches
BranchTrueFalseTotal
if ($bd == 0) { } 0 0 0
elsif ($intype) { } 0 0 0
elsif ($tt eq 'ci' and $bd == 1) { } 0 0 0
elsif ($tt eq 'r' and @ids == 0) { } 0 0 0
318 #&{$add_output}($tok) unless $tok eq ';';
319 0 ▶ if ($tok =~ /^(generic|port)$/i) { &{$add_output}("\n ".lc($tok)." map (\n") }
Branch: 2 branches
BranchTrueFalseTotal
if ($tok =~ /^(generic|port)$/i) { } 0 0 0
elsif ($tok eq ')') { } 0 0 0
320 0 elsif ($tok eq ')') { &{$add_output}(' ) ') }
321 } elsif ($intype) {
322 0 ▶ $typeetc .= $tt eq 'wn' ? ' ' : $tok;
Branch: 1 branch
BranchTrueFalseTotal
$tt eq 'wn' ? : 0 0 0
323 ▶ } elsif ($tt eq 'ci' && $bd==1) {
Condition0%0/3
$tt eq "ci" and $bd == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$tt eq "ci" and $bd == 1
$tt eq "ci" $bd == 1
Truth table0%0/3
A and B
A= $tt eq "ci"B= $bd == 1
ABresult
0X0
100
111
324 0 push @ids, $tok;
325 ▶ } elsif ($tt eq 'r' && @ids==0) {
Condition0%0/3
$tt eq "r" and @ids == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$tt eq "r" and @ids == 0
$tt eq "r" @ids == 0
Truth table0%0/3
A and B
A= $tt eq "r"B= @ids == 0
ABresult
0X0
100
111
326 0 &{$add_output}(" $tok\n");
327 }
328 }
329 0 &{$add_output}(";\n");
330 }
331 }
332
333 0 ▶sub _copy_part_file {
Subroutine _copy_part_file: not called CC=4 SCAR=30.0
334 0 my ($fho, $fhi, $upto) = @_;
335 0 while (1) {
336 0 my $nget = $upto - tell($fhi);
337 0 ▶ last if $nget <= 0 || eof($fhi);
Branch: 1 branch
BranchTrueFalseTotal
if $nget <= 0 or eof $fhi 0 0 0
Condition0%0/3
$nget <= 0 or eof $fhi
l!l&&r!l&&!r
000
MC/DC0%0/2
$nget <= 0 or eof $fhi
$nget <= 0 eof $fhi
Truth table0%0/3
A or B
A= $nget <= 0B= eof $fhi
ABresult
1X1
011
000
338 0 ▶ $nget = 16000 if $nget > 16000;
Branch: 1 branch
BranchTrueFalseTotal
if $nget > 16000 0 0 0
339 0 local $/ = \$nget;
340 0 my $buf = readline($fhi);
341 0 print $fho $buf;
342 }
343 }
344
345 0 ▶sub _component_insert_error {
Subroutine _component_insert_error: not called CC=2 SCAR=17.9
346 0 my ($dunit, $status_callback, $linenum, $err) = @_;
347 0 my $report = {
348 type => 'error',
349 text => $err,
350 duname => $dunit->name,
351 genfile => $dunit->file,
352 genlinenum => $linenum,
353 };
354 0 my ($lfn, $lln) = $dunit->line_to_source($report->{genlinenum});
355 0 ▶ if (defined $lfn) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lfn) 0 0 0
356 0 $report->{srcfile} = $lfn;
357 0 $report->{srclinenum} = $lln;
358 }
359 0 &$status_callback($report);
360 0 croak $err;
361 }
362
363 1 1;
« CompileTool.pm ↑ Summary PreProcessor.pm »