| 1 | package ModelSim::List; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||
| 7 | 3 | our $error; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | sub new ($) { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | my $class = ref $_[0] ? ref shift : shift; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 11 | 2 | return bless {}, $class; | |||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | sub parse ($$) { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 5 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 16 | 5 | my ($ast, $fh); | |||||||||||||||||||||||||||
| 17 | 5 | ▶ | unless(open $fh, $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 1 | $error = "file error - Can't open $file for reading: $!\n"; | |||||||||||||||||||||||||||
| 19 | 1 | return undef; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 4 | $_ = <$fh>; | |||||||||||||||||||||||||||
| 22 | 4 | ▶ | if (/^\@/o) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 3 | $ast = _parse_event_list($fh, $file); | |||||||||||||||||||||||||||
| 24 | } else { | ||||||||||||||||||||||||||||
| 25 | 1 | $ast = _parse_normal_list($fh, $file); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 4 | close $fh; | |||||||||||||||||||||||||||
| 28 | 4 | ▶ | return undef unless $ast; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 4 | %$self = %$ast; | |||||||||||||||||||||||||||
| 30 | 4 | return 1; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | ▶ | sub _parse_normal_list ($$) { | ||||||||||||||||||||||||||
|
Subroutine
_parse_normal_list: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||
| 34 | 1 | my ($fh, $file) = @_; | |||||||||||||||||||||||||||
| 35 | 1 | my $ast = {}; | |||||||||||||||||||||||||||
| 36 | 1 | my (%cols, @cols); | |||||||||||||||||||||||||||
| 37 | 1 | my $state = 0; | |||||||||||||||||||||||||||
| 38 | 1 | ▶ | do {{ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 17 | ▶ | next if /^\s*$/o; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 17 | ▶ | if ($state == 0) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 41 | 4 | ▶ | if (/\b\/\w+|\bdelta\b|\bns\b/o) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | # process signal name list: | ||||||||||||||||||||||||||||
| 43 | 3 | ▶ | while (/[\w\/]+/go) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 6 | $cols{$+[0]} = $&; | |||||||||||||||||||||||||||
| 45 | #warn "$& - ", $+[0], "\n"; | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||||||||
| 48 | # process the first data line: | ||||||||||||||||||||||||||||
| 49 | 1 | @cols = _sort_cols(%cols); | |||||||||||||||||||||||||||
| 50 | 1 | undef %cols; | |||||||||||||||||||||||||||
| 51 | 1 | _parse_data_line($ast, @cols); | |||||||||||||||||||||||||||
| 52 | 1 | $state = 1; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } elsif ($state == 1) { | ||||||||||||||||||||||||||||
| 55 | # process data line: | ||||||||||||||||||||||||||||
| 56 | 13 | _parse_data_line($ast, @cols); | |||||||||||||||||||||||||||
| 57 | } else { | ||||||||||||||||||||||||||||
| 58 | 0 | chomp; | |||||||||||||||||||||||||||
| 59 | 0 | $error = "file error - Syntax error: line $.: $_\n"; | |||||||||||||||||||||||||||
| 60 | 0 | return undef; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | }} while (<$fh>); | ||||||||||||||||||||||||||||
| 63 | #die Data::Dumper->Dump([$ast], [qw(self)]); | ||||||||||||||||||||||||||||
| 64 | 1 | return $ast; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # used in sub _parse_normal_list: | ||||||||||||||||||||||||||||
| 68 | 14 | ▶ | sub _parse_data_line { | ||||||||||||||||||||||||||
|
Subroutine
_parse_data_line: called CC=8 SCAR=21.1
| |||||||||||||||||||||||||||||
| 69 | 14 | my ($ast, @cols) = @_; | |||||||||||||||||||||||||||
| 70 | 14 | s/^\s+//; | |||||||||||||||||||||||||||
| 71 | 14 | my @data = split(/\s+/, $_); | |||||||||||||||||||||||||||
| 72 | 14 | my $time = $data[0]; | |||||||||||||||||||||||||||
| 73 | 14 | ▶ | for(my $i = 1; $i < @data; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 70 | my $sig = $cols[$i]; | |||||||||||||||||||||||||||
| 75 | 70 | my $val = $data[$i]; | |||||||||||||||||||||||||||
| 76 | #warn "@cols", " -> ", $sig, "\n"; | ||||||||||||||||||||||||||||
| 77 | #warn "@data", " -> ", $val, "\n"; | ||||||||||||||||||||||||||||
| 78 | 70 | ▶ | next if $sig eq 'delta'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 70 | ▶ | $ast->{$sig} = [] unless ref $ast->{$sig}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 70 | ▶ | if (@{$ast->{$sig}} and ${$ast->{$sig}}[-2] eq $val) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$ast->{$sig};} and do {
$$ast{$sig}
}->[-2] eq $val
MC/DC100%2/2
@{$ast->{$sig};} and do {
$$ast{$sig}
}->[-2] eq $val
@{$ast->{$sig};}
do {
$$ast{$sig}
}->[-2] eq $val
Truth table100%3/3
A and B
A= @{$ast->{$sig};}B= do {
$$ast{$sig}
}->[-2] eq $val
| |||||||||||||||||||||||||||||
| 81 | 44 | next; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 26 | ▶ | if (@{$ast->{$sig}} and ${$ast->{$sig}}[-1] eq $time) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@{$ast->{$sig};} and do {
$$ast{$sig}
}->[-1] eq $time
MC/DC0%0/2
@{$ast->{$sig};} and do {
$$ast{$sig}
}->[-1] eq $time
@{$ast->{$sig};}
do {
$$ast{$sig}
}->[-1] eq $time
Truth table66%2/3
A and B
A= @{$ast->{$sig};}B= do {
$$ast{$sig}
}->[-1] eq $time
| |||||||||||||||||||||||||||||
| 84 | 0 | ${$ast->{$sig}}[-2] = $val; | |||||||||||||||||||||||||||
| 85 | 0 | next; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 26 | push @{$ast->{$sig}}, $val, $time; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # used in sub _parse_normal_list: | ||||||||||||||||||||||||||||
| 92 | 1 | ▶ | sub _sort_cols { | ||||||||||||||||||||||||||
|
Subroutine
_sort_cols: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 93 | 1 | my %cols = @_; | |||||||||||||||||||||||||||
| 94 | 1 | my @cols; | |||||||||||||||||||||||||||
| 95 | 1 | foreach my $colnum (sort keys %cols) { | |||||||||||||||||||||||||||
| 96 | 6 | push @cols, $cols{$colnum}; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 1 | return @cols; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 3 | ▶ | sub _parse_event_list { | ||||||||||||||||||||||||||
|
Subroutine
_parse_event_list: called CC=9 SCAR=22.3
| |||||||||||||||||||||||||||||
| 102 | 3 | my ($fh, $file) = @_; | |||||||||||||||||||||||||||
| 103 | 3 | my $ast = {}; | |||||||||||||||||||||||||||
| 104 | 3 | my $time; | |||||||||||||||||||||||||||
| 105 | 3 | ▶ | do {{ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 315 | ▶ | next if /^\s*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 315 | ▶ | if (/^\@(\d+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 144 | $time = $1; | |||||||||||||||||||||||||||
| 109 | 144 | next; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 171 | ▶ | unless (defined $time) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | $error = "file error - $file: Invalid file format\n"; | |||||||||||||||||||||||||||
| 113 | 0 | return undef; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 171 | ▶ | if (/^([\w\/]+)\s+(\w+)\s*$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 171 | my ($sig, $val) = ($1, $2); | |||||||||||||||||||||||||||
| 117 | 171 | ▶ | $ast->{$sig} = [] unless ref $ast->{$sig}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 171 | ▶ | if (@{$ast->{$sig}} and ${$ast->{$sig}}[-1] eq $time) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$ast->{$sig};} and do {
$$ast{$sig}
}->[-1] eq $time
MC/DC100%2/2
@{$ast->{$sig};} and do {
$$ast{$sig}
}->[-1] eq $time
@{$ast->{$sig};}
do {
$$ast{$sig}
}->[-1] eq $time
Truth table100%3/3
A and B
A= @{$ast->{$sig};}B= do {
$$ast{$sig}
}->[-1] eq $time
| |||||||||||||||||||||||||||||
| 119 | 17 | ${$ast->{$sig}}[-2] = $val; | |||||||||||||||||||||||||||
| 120 | 17 | next; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | 154 | push @{$ast->{$sig}}, $val, $time; | |||||||||||||||||||||||||||
| 123 | 154 | next; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | 0 | $error = "file error - $file: Invalid file format\n"; | |||||||||||||||||||||||||||
| 126 | 0 | return undef; | |||||||||||||||||||||||||||
| 127 | }} while (<$fh>); | ||||||||||||||||||||||||||||
| 128 | #die Data::Dumper->Dump([$ast], [qw(self)]); | ||||||||||||||||||||||||||||
| 129 | 3 | return $ast; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 280 | ▶ | sub strobe { | ||||||||||||||||||||||||||
|
Subroutine
strobe: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | 280 | my ($self, $signal, $time) = @_; | |||||||||||||||||||||||||||
| 134 | 280 | ▶ | unless ($self->{$signal}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | $error = "strobe error - $signal: No such signal name.\n"; | |||||||||||||||||||||||||||
| 136 | 0 | return undef; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | 280 | my @events = @{$self->{$signal}}; | |||||||||||||||||||||||||||
| 139 | 280 | ▶ | if ($time < $events[1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 6 | $error = "strobe error - $signal: time $time underflow.\n"; | |||||||||||||||||||||||||||
| 141 | 6 | return undef; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 274 | my $value; | |||||||||||||||||||||||||||
| 144 | 274 | ▶ | while (@events) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 3373 | my $val = shift @events; | |||||||||||||||||||||||||||
| 146 | 3373 | my $tm = shift @events; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 3373 | ▶ | if ($time < $tm) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 265 | return $value; | |||||||||||||||||||||||||||
| 150 | } else { | ||||||||||||||||||||||||||||
| 151 | 3108 | $value = $val; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | 9 | return $value; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 365 | ▶ | sub _val_eq { | ||||||||||||||||||||||||||
|
Subroutine
_val_eq: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 158 | 365 | my ($val, $pat) = @_; | |||||||||||||||||||||||||||
| 159 | 365 | ▶ | return $val =~ $pat if (ref($pat) eq 'Regexp'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 223 | return $val eq $pat; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 159 | ▶ | sub time_of { | ||||||||||||||||||||||||||
|
Subroutine
time_of: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||
| 164 | 159 | my ($self, $signal, $value, $start, $end) = @_; | |||||||||||||||||||||||||||
| 165 | 159 | ▶ | $start = 0 unless defined $start; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 159 | ▶ | if (defined $start and defined $end) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $start and defined $end
MC/DC50%1/2
defined $start and defined $end
defined $start
defined $end
Truth table66%2/3
A and B
A= defined $startB= defined $end
| |||||||||||||||||||||||||||||
| 167 | 127 | ▶ | if ($start > $end) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 1 | $error = "time_of error - Starting time $start greater than the ". | |||||||||||||||||||||||||||
| 169 | "ending time $end\n"; | ||||||||||||||||||||||||||||
| 170 | 1 | return undef; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | 158 | ▶ | unless ($self->{$signal}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 0 | $error = "time_of error - $signal: No such signal name.\n"; | |||||||||||||||||||||||||||
| 175 | 0 | return undef; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | 158 | my @events = @{$self->{$signal}}; | |||||||||||||||||||||||||||
| 178 | 158 | my $time; | |||||||||||||||||||||||||||
| 179 | 158 | ▶ | return $start if _val_eq($self->strobe($signal, $start), $value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 143 | ▶ | while (@events) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 2239 | my $val = shift @events; | |||||||||||||||||||||||||||
| 182 | 2239 | my $tm = shift @events; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 2239 | ▶ | if ($tm < $start) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 2032 | next; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | 207 | ▶ | if (_val_eq $val, $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 136 | ▶ | if (defined $end and $tm > $end) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $end and $tm > $end
MC/DC100%2/2
defined $end and $tm > $end
defined $end
$tm > $end
Truth table100%3/3
A and B
A= defined $endB= $tm > $end
| |||||||||||||||||||||||||||||
| 189 | 5 | $error = "time_of warning - $signal: Never achieved value $value ". | |||||||||||||||||||||||||||
| 190 | "during the time interval specified.\n"; | ||||||||||||||||||||||||||||
| 191 | 5 | return undef; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | 131 | return $tm; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | 7 | $error = "time_of warning - $signal: Never achieved value $value ". | |||||||||||||||||||||||||||
| 197 | "during the time interval specified.\n"; | ||||||||||||||||||||||||||||
| 198 | 7 | return undef; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # Return the error info: | ||||||||||||||||||||||||||||
| 202 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 203 | 0 | return $error; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 3 | 1; | |||||||||||||||||||||||||||
| 207 | __END__ | ||||||||||||||||||||||||||||