VM/Opcode.pm

filter: Statementstmt 17.1% 76 / 444 Branchbran 6.0% 20 / 330 Conditioncond 3.6% 12 / 327 MC/DCmcdc 2.9% 5 / 170 Subroutinesub 36.3% 8 / 22 Podpod 100% 11 / 11 totaltotal 10.1% 132 / 1304 CC 268 SCAR 87.2
CC
268
Cov
10%
from_template
11990.0
as_text
5852.0
read
702.0
CRAP 6144.5
« VM/Assembler.pm ↑ Summary VM/Disassembler.pm »
1 # Copyright (c) 2025-2026 Philipp Schafft
2  
3 # licensed under Artistic License 2.0 (see LICENSE file)
4  
5 # ABSTRACT: module for single SIRTX VM opcodes
6  
7  
8 package SIRTX::VM::Opcode;
9  
10 1 ▶use v5.16;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use SIRTX::VM::RegisterFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use SIRTX::VM::Assembler;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use parent 'Data::Identifier::Interface::Userdata';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 our $VERSION = v0.13;
23  
24 1 my %_die_raen = (code => 0, P => 7, codeX => 0, S => 2, T => 4+1);
25  
26 1 my %_raes_to_raen = (
27 NONE => 0,
28 NOENT => 2,
29 NOSYS => 6,
30 NOTSUP => 7,
31 NOMEM => 12,
32 INVAL => 13,
33 FAULT => 18,
34 IO => 19,
35 NODATA => 25,
36 NOSPC => 38,
37 TYPEMM => 39,
38 RO => 45,
39 ILLSEQ => 56,
40 BADEXEC => 79,
41 BADFH => 83,
42 );
43  
44 1 our %_logicals_to_sni = (
45 sni => 10,
46 sid => 115,
47 raen => 116,
48 chat0w => 118,
49 uuid => 119,
50 uri => 121,
51 asciicp => 122,
52 oid => 120,
53 wd => 123,
54 logical => 129,
55 rampool => 135,
56 memorypool => 136,
57 storagepool => 137,
58 sepport => 150,
59 false => 189,
60 true => 190,
61 SIRTX_ACCESS_PATH => 225,
62 SIRTX_ACCESS_RDONLY => 226,
63 SIRTX_ACCESS_WRONLY => 227,
64 SIRTX_ACCESS_RDWR => 228,
65 SIRTX_ACCESS_ONLINE => 229,
66 bb => 294,
67 urandom => 297,
68 ac => 298,
69 accumulator => 298,
70 exit_status => 303,
71 dataout => 315,
72 sideout => 317,
73 );
74 1 my %_sni_to_logicals = reverse %_logicals_to_sni;
75  
76 1 my %_logicals_to_sid = (
77 asi => 1,
78 tagname => 3,
79 SEEK_SET => 34,
80 SEEK_CUR => 35,
81 SEEK_END => 36,
82 backwards => 43,
83 forwards => 44,
84 black => 61,
85 white => 62,
86 grey => 63,
87 red => 119,
88 green => 120,
89 blue => 121,
90 cyan => 122,
91 magenta => 123,
92 yellow => 124,
93 orange => 125,
94 hrair => 159,
95 gtin => 160,
96 left => 192,
97 right => 193,
98 up => 194,
99 down => 195,
100 north => 208,
101 east => 209,
102 south => 210,
103 west => 211,
104 );
105  
106 1 my %_compare_flags = (
107 with => 0x0000, # no-op
108 icase => 0x0001,
109 asciz => 0x0008,
110 nulls_distinct => 0x0080,
111 nulls_equal => 0x0040,
112 nulls_first => 0x0010,
113 nulls_last => 0x0020,
114 prefix => 0x0002,
115 suffix => 0x0004,
116 seekback_end => 0x0400,
117 seekback_start => 0x0200,
118 subject => 0x0100,
119 );
120  
121 my %_logicals = (
122 28 (map {$_ => 'sni:'.$_logicals_to_sni{$_}} keys %_logicals_to_sni),
123 1 (map {$_ => 'sid:'.$_logicals_to_sid{$_}} keys %_logicals_to_sid),
124 );
125  
126 1 my @_simple_0 = ();
127 1 my @_simple_1 = (reg => 'P');
128 1 my @_simple_2 = (reg => 'P', reg => 'T');
129 1 my @_simple_3 = (reg => 'P', reg => 'S', reg => 'T');
130  
131 my %_simple_opcodes = (
132 noop => [\@_simple_0 => {first => 0, second => 0, T => 0}],
133 magic => [\@_simple_0 => {first => 0, codeX => 0, S => 0, T => 4+3, extra => "VM\r\n\xc0\n"}],
134 autodie => [\@_simple_0 => {code => 0, P => 7, codeX => 0, S => 2, T => 4+0}],
135 data_start_marker => [\@_simple_0 => {code => 0, P => 6, codeX => 0, S => 0, T => 0}],
136 break => [\@_simple_0 => {code => 0, P => 6, codeX => 0, S => 1, T => 0+0},
137 [int => 'extra[]'] => {code => 0, P => 6, codeX => 0, S => 1, T => 0+1},
138 [int => 'extra[]', int => 'extra[]'] => {code => 0, P => 6, codeX => 0, S => 1, T => 0+2},
139 [int => 'extra[]', int => 'extra[]', int => 'extra[]'] => {code => 0, P => 6, codeX => 0, S => 1, T => 0+3}],
140  
141 filesize => [[int_half => 'extra[]'] => {code => 0, P => 1, codeX => 0, S => 0, T => 0+1}],
142 section_pointer => [[int_half => 'extra[]'] => {code => 0, P => 1, codeX => 0, S => 1, T => 0+1}],
143 minimum_handles => [[int_half => 'extra[]'] => {code => 0, P => 1, codeX => 0, S => 2, T => 0+1}],
144 minimum_memory => [[int_half => 'extra[]'] => {code => 0, P => 1, codeX => 0, S => 3, T => 0+1}],
145 text_boundary => [[int_half => 'extra[]'] => {code => 0, P => 1, codeX => 0, S => 4, T => 0+1}],
146 load_boundary => [[int_half => 'extra[]'] => {code => 0, P => 1, codeX => 0, S => 5, T => 0+1}],
147  
148 rjump => [[int => 'extra[]'] => {code => 0, P => 7, codeX => 0, S => 4, T => 0+1}],
149  
150 unref => [\@_simple_1 => {code => 0, codeX => 1, S => 0, T => 0+0}],
151 rewind => [\@_simple_1 => {code => 0, codeX => 1, S => 1, T => 0+0}],
152 die => [\@_simple_1 => {code => 0, codeX => 1, S => 2, T => 4+0}],
153 exit => [\@_simple_1 => {code => 0, codeX => 1, S => 3, T => 0+0}],
154 #jump => {code => 0, codeX => 1, S => 4, T => 0+0},
155 rcall => [[int => 'extra[]'] => {code => 0, codeX => 1, S => 5, T => 0+1}],
156 trcall => [[int => 'extra[]'] => {code => 0, codeX => 1, S => 5, T => 4+1}],
157 open_context => [\@_simple_1 => {code => 1, codeX => 1, S => 7, T => 0+0}],
158  
159 replace => [\@_simple_2 => {code => 0, codeX => 2, S => 0}],
160 move => [\@_simple_2 => {code => 0, codeX => 2, S => 1}],
161 seek => [\@_simple_2 => {code => 0, codeX => 2, S => 2}],
162 tell => [\@_simple_2 => {code => 0, codeX => 2, S => 3}],
163 transfer => [\@_simple_2 => {code => 0, codeX => 2, S => 4}],
164  
165 return => [\@_simple_0 => {code => 0, P => 7, codeX => 0, S => 2, T => 0+0},
166 \@_simple_1 => {code => 0, codeX => 1, S => 2, T => 0+0}],
167  
168 contents => [\@_simple_2 => {code => 1, codeX => 2, S => 1}],
169 die => [['raen:' => 'extra[]'] => \%_die_raen],
170 substr => [[reg => 'P', reg => 'T', int => 'extra[]', int => 'extra[]'] => {code => 1, codeX => 2, S => (0+3)}],
171 open_function => [[reg => 'P', int_rel4 => 'extra[]'] => {code => 1, codeX => 1, S => 6, T => 0+1}],
172 relations => [[reg => 'P', reg => 'S', reg => 'T', undef => 'undef'] => {code => 4, codeX => 0},
173 [reg => 'P', undef => 'undef', reg => 'T', reg => 'S'] => {code => 4, codeX => 1}],
174 metadata => [\@_simple_3 => {code => 4, codeX => 2}],
175 control => [[reg => 'P', reg => 'T'] => {code => 1, codeX => 2, S => 0+0},
176 [reg => 'P', 'sni:' => 'extra[]', reg => 'T'] => {code => 1, codeX => 2, S => 4+0},
177 [reg => 'P', 'sni:' => 'extra[]'] => {code => 1, codeX => 1, S => 0, T => 0+1},
178 [reg => 'P', 'sni:' => 'extra[]', 'sni:' => 'extra[]'] => {code => 1, codeX => 1, S => 0, T => 0+2},
179 [reg => 'P', 'sni:' => 'extra[]', int => 'extra[]'] => {code => 1, codeX => 1, S => 0, T => 4+2},
180 [reg => 'P', reg => 'S', reg => 'T'] => {code => 1, codeX => 3}],
181  
182 open => [[reg => 'P', 'sni:' => 'extra[]'] => {code => 0, codeX => 1, S => 6, T => 0+1},
183 [reg => 'P', '"ns"' => 'undef', int => 'extra[]'] => {code => 0, codeX => 1, S => 6, T => 4+1},
184 [reg => 'P', '"ns"' => 'undef', int => 'extra[]', int => 'extra[]'] => {code => 0, codeX => 1, S => 6, T => 4+2}],
185 byte_transfer => [[reg => 'P', reg => 'T', int => 'extra[]', autodie => 'false'] => {code => 1, codeX => 2, S => 4+2},
186 [reg => 'P', reg => 'T', int => 'extra[]', autodie => 'true'] => {code => 1, codeX => 2, S => 4+1}],
187 call => [[reg => 'P', reg => 'T', autodie => 'false'] => {code => 0, codeX => 2, S => 5},
188 [reg => 'P', reg => 'T', autodie => 'true'] => {code => 0, codeX => 2, S => 6}],
189 jump => [[int_rel4 => 'extra[]'] => {code => 0, P => 7, codeX => 0, S => 4, T => 0+1}],
190  
191 '.not_implemented' => [\@_simple_0 => {%_die_raen, extra => [$_raes_to_raen{NOSYS}]}],
192 1 '.bug' => [\@_simple_0 => {%_die_raen, extra => [$_raes_to_raen{ILLSEQ}]}],
193 );
194 1 $_simple_opcodes{nop} = $_simple_opcodes{noop}; # alias
195  
196 1 my @_opcode_to_text;
197  
198 1 my %_synthetic = (
199 open => [
200 [reg => 1, undef => 'undef'] => ['unref', \1],
201 [reg => 1, '"false"' => 'undef'] => ['open', \1, 'sni:189'],
202 [reg => 1, '"true"' => 'undef'] => ['open', \1, 'sni:190'],
203 ],
204 add => [['"out"' => 'undef', reg => 1, reg => 2] => ['control', \1, 'sni:81', \2]],
205 sub => [['"out"' => 'undef', reg => 1, reg => 2] => ['control', \1, 'sni:82', \2]],
206 div => [['"out"' => 'undef', reg => 1, reg => 2] => ['control', \1, 'sni:83', \2]],
207 mod => [['"out"' => 'undef', reg => 1, reg => 2] => ['control', \1, 'sni:84', \2]],
208 jump => [[reg => 1] => ['seek', 'program_text', \1]],
209 return => [[undef => 'undef'] => ['return']],
210 control => [[any => 1, any => 2, any => 3, '"arg"' => 'undef'] => ['control', \1, \2, \3]],
211 push => [[reg => 1, reg => 2] => ['control', \1, 'sni:180', \2]],
212 pop => [
213 ['"out"' => 1, reg => 2] => ['control', \2, 'sni:181'],
214 ['"undef"' => 1, reg => 2] => ['control', \2, 'sni:181'], # alias
215 ],
216 setvalue => [[reg => 1, reg => 2, '"arg"' => 3] => ['control', \1, 'sni:102', \2, \3]],
217 getvalue => [['"out"' => 1, reg => 2, reg => 3] => ['control', \2, 'sni:101', \3]],
218 read_character => [['"out"' => 'undef', reg => 1] => ['control', \1, 'sni:282']],
219 write_character => [
220 [reg => 1, reg => 2] => ['control', \1, 'sni:283', \2],
221 [reg => 1, int => 2] => ['control', \1, 'sni:283', \2],
222 ],
223 read_be8 => [['"out"' => 'undef', reg => 1] => ['control', \1, 'sni:143', '8']],
224 read_be16 => [['"out"' => 'undef', reg => 1] => ['control', \1, 'sni:143', '16']],
225 );
226  
227  
228 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
229 0 my ($pkg, %opts) = @_;
230 0 my $self = bless({}, $pkg);
231  
232 0 foreach my $key (qw(first second code codeX ST P S T size pos)) {
233 0 ▶ my $val = delete $opts{$key} // next;
Condition0%0/2
delete $opts{$key} // (next)
l!l
00
MC/DC0%0/1
delete $opts{$key} // (next)
delete $opts{$key}
Truth table0%0/2
A
A= delete $opts{$key}
Aresult
11
00
234 0 ▶ unless (looks_like_number($val)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&looks_like_number($val)) 0 0 0
235 0 croak 'Invalid argument: '.$key.' is not a number';
236 }
237 0 $self->{$key} = int($val);
238 }
239  
240 0 $self->{extra} = delete $opts{extra};
241  
242 # TODO: Implement more checks here.
243  
244 0 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 0 0
245  
246 0 return $self;
247 }
248  
249  
250 0 ▶sub from_template {
Subroutine from_template: not called CC=109 SCAR=93.9
Pod documented
251 0 my ($pkg, %opts) = @_;
252 0 my $parts = delete $opts{parts};
253 0 my $asm = delete $opts{assembler};
254 0 my $size = delete $opts{size};
255 0 my $line = delete $opts{line};
256 0 my $out = delete $opts{out};
257 0 my $autodie = delete $opts{autodie};
258 0 my ($cmd, @args) = @{$parts};
259  
260 0 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 0 0
261  
262 # try to reheat all registers used in this directive:
263 0 $asm->_reheat_mappings(grep {eval {$asm->_get_value_type($_) eq 'reg'}} @args);
264  
265 0 ▶ if (defined(my $entry = $_synthetic{$cmd})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = $_synthetic{$cmd})) 0 0 0
266 outer:
267 0 ▶ for (my $i = 0; $i < scalar(@{$entry}); $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$entry;}) 0 0 0
268 0 my @argmap = @{$entry->[$i]};
269 0 my %updates;
270  
271 0 ▶ next unless (scalar(@args)*2) == scalar(@argmap);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar(@args) * 2 == scalar @argmap 0 0 0
272  
273 0 ▶ for (my $j = 0; ($j*2) < scalar(@argmap); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j * 2 < scalar @argmap) 0 0 0
274 0 my $type = $argmap[$j*2 + 0];
275 0 my $dst = $argmap[$j*2 + 1];
276 0 my $val = $args[$j];
277  
278 0 ▶ if ($val =~ /^raes:(.+)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /^raes:(.+)$/u) { } 0 0 0
elsif ($val =~ /^logical:(.+)$/u) { } 0 0 0
279 0 ▶ if (defined(my $raen = $_raes_to_raen{uc($1)})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $raen = $_raes_to_raen{uc $1})) 0 0 0
280 0 $val = 'raen:'.$raen;
281 }
282 } elsif ($val =~ /^logical:(.+)$/) {
283 0 ▶ if (defined(my $logical = $_logicals{$1})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $logical = $_logicals{$1})) 0 0 0
284 0 $val = $logical;
285 }
286 }
287  
288 0 ▶ if ($type =~ /^".+"$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ /^".+"$/u) { } 0 0 0
elsif ($type eq 'any') { } 0 0 0
289 0 ▶ next outer if $val ne $asm->_parse_string($type);
Branch: 1 branch
BranchTrueFalseTotal
if $val ne $asm->_parse_string($type) 0 0 0
290 } elsif ($type eq 'any') {
291 # no-op
292 } else {
293 0 ▶ next outer if $asm->_get_value_type($val) ne $type;
Branch: 1 branch
BranchTrueFalseTotal
if $asm->_get_value_type($val) ne $type 0 0 0
294 }
295  
296 0 ▶ if ($dst eq 'undef') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dst eq 'undef') { } 0 0 0
297 # ignore this value
298 } else {
299 0 $updates{$dst} = $val;
300 }
301 }
302  
303 0 ▶ ($cmd, @args) = map {ref ? $updates{${$_}} : $_} @{$entry->[$i+1]};
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
304 }
305 }
306  
307 # replace logics:
308 0 foreach my $arg (@args) {
309 0 ▶ if ($arg =~ /^logical:(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^logical:(.+)$/u) 0 0 0
310 0 ▶ if (defined(my $logical = $_logicals{$1})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $logical = $_logicals{$1})) 0 0 0
311 0 $arg = $logical;
312 }
313 }
314 }
315  
316 0 ▶ if (defined(my $entry = $_simple_opcodes{$cmd})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = $_simple_opcodes{$cmd})) 0 0 0
317 outer:
318 0 ▶ for (my $i = 0; $i < scalar(@{$entry}); $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$entry;}) 0 0 0
319 0 my @argmap = @{$entry->[$i]};
320 0 my %updates;
321 my $last_data;
322 0 my $reset_autodie;
323  
324 0 ▶ if (scalar(@argmap) >= 2 && $argmap[-2] eq 'autodie') {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @argmap >= 2 and $argmap[-2] eq 'autodie') { } 0 0 0
Condition0%0/3
scalar @argmap >= 2 and $argmap[-2] eq "autodie"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @argmap >= 2 and $argmap[-2] eq "autodie"
scalar @argmap >= 2 $argmap[-2] eq "autodie"
Truth table0%0/3
A and B
A= scalar @argmap >= 2B= $argmap[-2] eq "autodie"
ABresult
0X0
100
111
325 0 ▶ next unless ((scalar(@args) + 1)*2) == scalar(@argmap);
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar(@args) + 1) * 2 == scalar @argmap 0 0 0
326 } else {
327 0 ▶ next unless ((scalar(@args) + 0)*2) == scalar(@argmap);
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar(@args) + 0) * 2 == scalar @argmap 0 0 0
328 }
329  
330 0 ▶ for (my $j = 0; ($j*2) < scalar(@argmap); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j * 2 < scalar @argmap) 0 0 0
331 0 my $type = $argmap[$j*2 + 0];
332 0 my $dst = $argmap[$j*2 + 1];
333 0 my $val = $args[$j];
334 0 my $data;
335 0 my $mods = '';
336  
337 0 ▶ if ($type =~ s/_(.+)$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ s/_(.+)$//u) 0 0 0
338 0 $mods = $1;
339 }
340  
341 0 ▶ if ($type ne 'autodie' && $val =~ /^raes:(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "autodie" and $val =~ /^raes:(.+)$/u) 0 0 0
Condition0%0/3
$type ne "autodie" and $val =~ /^raes:(.+)$/u
!ll&&!rl&&r
000
MC/DC0%0/2
$type ne "autodie" and $val =~ /^raes:(.+)$/u
$type ne "autodie" $val =~ /^raes:(.+)$/u
Truth table0%0/3
A and B
A= $type ne "autodie"B= $val =~ /^raes:(.+)$/u
ABresult
0X0
100
111
342 0 ▶ if (defined(my $raen = $_raes_to_raen{uc($1)})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $raen = $_raes_to_raen{uc $1})) 0 0 0
343 0 $val = 'raen:'.$raen;
344 }
345 }
346  
347 0 ▶ if ($type =~ /^".+"$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ /^".+"$/u) { } 0 0 0
elsif ($type eq 'autodie') { } 0 0 0
348 0 ▶ next outer if $val ne $asm->_parse_string($type);
Branch: 1 branch
BranchTrueFalseTotal
if $val ne $asm->_parse_string($type) 0 0 0
349 } elsif ($type eq 'autodie') {
350 0 ▶ next outer if !defined($autodie);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $autodie 0 0 0
351 } else {
352 0 ▶ next outer if $asm->_get_value_type($val) ne $type;
Branch: 1 branch
BranchTrueFalseTotal
if $asm->_get_value_type($val) ne $type 0 0 0
353 }
354  
355 0 ▶ if ($type eq 'reg') {
Branch: 6 branches
BranchTrueFalseTotal
if ($type eq 'reg') { } 0 0 0
elsif ($type eq 'int') { } 0 0 0
elsif ($type =~ /^[a-z]+:$/u) { } 0 0 0
elsif ($type eq 'undef') { } 0 0 0
elsif ($type =~ /^".+"$/u) { } 0 0 0
elsif ($type eq 'autodie') { } 0 0 0
356 0 $data = $asm->_force_mapped($val);
357 } elsif ($type eq 'int') {
358 0 ▶ if ($mods eq 'rel4') {
Branch: 2 branches
BranchTrueFalseTotal
if ($mods eq 'rel4') { } 0 0 0
elsif ($mods eq 'half') { } 0 0 0
359 0 my $org = $out->tell + 4;
360 0 $data = $asm->_parse_int($val, $org) - $org;
361 0 ▶ if ($data & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data & 1) 0 0 0
362 0 croak sprintf('Bad offset: line %s: offset %i', $line, $data);
363 }
364 0 $data /= 2;
365 } elsif ($mods eq 'half') {
366 0 $data = $asm->_parse_int($val, $last_data);
367 0 ▶ if ($data & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data & 1) 0 0 0
368 0 croak sprintf('Bad value: line %s: value %i', $line, $data);
369 }
370 0 $data /= 2;
371 } else {
372 0 $data = $asm->_parse_int($val, $last_data);
373 }
374 } elsif ($type =~ /^[a-z]+:$/) {
375 0 (undef, $data) = $asm->_parse_id($val);
376 } elsif ($type eq 'undef') {
377 0 $data = undef;
378 } elsif ($type =~ /^".+"$/) {
379 0 $data = $val;
380 } elsif ($type eq 'autodie') {
381 0 $reset_autodie = $asm->_parse_bool($dst);
382 0 ▶ next outer if (${$autodie} xor $reset_autodie);
Branch: 1 branch
BranchTrueFalseTotal
if ${$autodie;} xor $reset_autodie 0 0 0
Condition0%0/4
${$autodie;} xor $reset_autodie
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
${$autodie;} xor $reset_autodie
${$autodie;} $reset_autodie
Truth table0%0/4
A xor B
A= ${$autodie;}B= $reset_autodie
ABresult
110
101
011
000
383 0 next;
384 } else {
385 0 croak 'BUG: Unsupported type: '.$type;
386 0 next outer;
387 }
388  
389 0 ▶ if ($dst eq 'extra[]') {
Branch: 2 branches
BranchTrueFalseTotal
if ($dst eq 'extra[]') { } 0 0 0
elsif ($dst eq 'undef') { } 0 0 0
390 0 ▶ push(@{$updates{extra} //= []}, $data);
Condition0%0/2
$updates{"extra"} //= []
l!l
00
MC/DC0%0/1
$updates{"extra"} //= []
$updates{"extra"}
Truth table0%0/2
A
A= $updates{"extra"}
Aresult
11
00
391 } elsif ($dst eq 'undef') {
392 # ignore this value
393 } else {
394 0 $updates{$dst} = $data;
395 }
396  
397 0 $last_data = $data;
398 }
399  
400 0 ▶ ${$autodie} = undef if defined($autodie) && $reset_autodie;
Branch: 1 branch
BranchTrueFalseTotal
if defined $autodie and $reset_autodie 0 0 0
Condition0%0/3
defined $autodie and $reset_autodie
!ll&&!rl&&r
000
MC/DC0%0/2
defined $autodie and $reset_autodie
defined $autodie $reset_autodie
Truth table0%0/3
A and B
A= defined $autodieB= $reset_autodie
ABresult
0X0
100
111
401 0 return $pkg->new(%{$entry->[$i+1]}, %updates, size => $size);
402 }
403 }
404  
405 0 ▶ if ($cmd eq 'compare' && scalar(@args) >= 3 && $args[0] eq 'out') {
Branch: 6 branches
BranchTrueFalseTotal
if ($cmd eq 'compare' and scalar @args >= 3 and $args[0] eq 'out') { } 0 0 0
elsif ($cmd eq 'open' and scalar @args == 2 and $asm->_get_value_type($args[0]) eq 'reg' and $asm->_get_value_type($args[1]) eq 'int') { } 0 0 0
elsif ($cmd eq 'open' and scalar @args == 2 and $asm->_get_value_type($args[0]) eq 'reg' and $asm->_get_value_type($args[1]) =~ /:$/u) { } 0 0 0
elsif ($cmd eq 'jump' and scalar @args >= 3 and $asm->_get_value_type($args[0]) eq 'int' and $args[1] eq 'if' || $args[1] eq 'unless') { } 0 0 0
elsif ($cmd eq 'noop' and scalar @args == 1 and $asm->_get_value_type($args[0]) eq 'string') { } 0 0 0
elsif ($cmd eq 'execution_info_flags') { } 0 0 0
Condition0%0/6
$cmd eq "compare" and scalar @args >= 3 and $args[0] eq "out"
!ll&&!rl&&r
000
$cmd eq "compare" and scalar @args >= 3
!ll&&!rl&&r
000
MC/DC0%0/3
$cmd eq "compare" and scalar @args >= 3 and $args[0] eq "out"
$cmd eq "compare" scalar @args >= 3 $args[0] eq "out"
Truth table0%0/4
A and B and C
A= $cmd eq "compare"B= scalar @args >= 3C= $args[0] eq "out"
ABCresult
0XX0
10X0
1100
1111
406 0 my @flags = @args[3..$#args];
407 0 my $flags = 0;
408  
409 0 foreach my $flag (@flags) {
410 0 ▶ if (defined(my $v = $_compare_flags{$flag})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = $_compare_flags{$flag})) { } 0 0 0
411 0 $flags |= $v;
412 } else {
413 0 croak sprintf('Unsupported compare flag: line %s: flag %s', $line, $flag);
414 }
415 }
416  
417 0 return $pkg->new(code => 3, P => $asm->_force_mapped($args[1]), codeX => 2, S => 0, T => $asm->_force_mapped($args[2]), extra => [$flags]);
418 ▶ } elsif ($cmd eq 'open' && scalar(@args) == 2 && $asm->_get_value_type($args[0]) eq 'reg' && $asm->_get_value_type($args[1]) eq 'int') {
Condition0%0/9
$cmd eq "open" and scalar @args == 2 and $asm->_get_value_type($args[0]) eq "reg" and $asm->_get_value_type($args[1]) eq "int"
!ll&&!rl&&r
000
$cmd eq "open" and scalar @args == 2 and $asm->_get_value_type($args[0]) eq "reg"
!ll&&!rl&&r
000
$cmd eq "open" and scalar @args == 2
!ll&&!rl&&r
000
MC/DC0%0/4
$cmd eq "open" and scalar @args == 2 and $asm->_get_value_type($args[0]) eq "reg" and $asm->_get_value_type($args[1]) eq "int"
$cmd eq "open" scalar @args == 2 $asm->_get_value_type($args[0]) eq "reg" $asm->_get_value_type($args[1]) eq "int"
Truth table0%0/5
A and B and C and D
A= $cmd eq "open"B= scalar @args == 2C= $asm->_get_value_type($args[0]) eq "reg"D= $asm->_get_value_type($args[1]) eq "int"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
419 0 my $num = $asm->_parse_int($args[1]);
420 0 ▶ if (($num >= 0 && $num <= 7) && (!defined($size) || $size != 4)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num >= 0 and $num <= 7 and !defined($size) || $size != 4) { } 0 0 0
Condition0%0/9
$num >= 0 and $num <= 7 and !defined($size) || $size != 4
!ll&&!rl&&r
000
$num >= 0 and $num <= 7
!ll&&!rl&&r
000
not defined $size or $size != 4
l!l&&r!l&&!r
000
MC/DC0%0/4
$num >= 0 and $num <= 7 and !defined($size) || $size != 4
$num >= 0 $num <= 7 not defined $size $size != 4
Truth table0%0/5
A and B and not(C) or D
A= $num >= 0B= $num <= 7C= not defined $sizeD= $size != 4
ABCDresult
0XXX0
10XX0
11000
111X1
11011
421 0 return $pkg->new(code => 0, P => $asm->_force_mapped($args[0]), codeX => 2, S => 7, T => $num);
422 } else {
423 0 return $pkg->new(code => 0, P => $asm->_force_mapped($args[0]), codeX => 1, S => 7, T => 0+1, extra => [$num]);
424 }
425 ▶ } elsif ($cmd eq 'open' && scalar(@args) == 2 && $asm->_get_value_type($args[0]) eq 'reg' && $asm->_get_value_type($args[1]) =~ /:$/) {
Condition0%0/9
$cmd eq "open" and scalar @args == 2 and $asm->_get_value_type($args[0]) eq "reg" and $asm->_get_value_type($args[1]) =~ /:$/u
!ll&&!rl&&r
000
$cmd eq "open" and scalar @args == 2 and $asm->_get_value_type($args[0]) eq "reg"
!ll&&!rl&&r
000
$cmd eq "open" and scalar @args == 2
!ll&&!rl&&r
000
MC/DC0%0/4
$cmd eq "open" and scalar @args == 2 and $asm->_get_value_type($args[0]) eq "reg" and $asm->_get_value_type($args[1]) =~ /:$/u
$cmd eq "open" scalar @args == 2 $asm->_get_value_type($args[0]) eq "reg" $asm->_get_value_type($args[1]) =~ /:$/u
Truth table0%0/5
A and B and C and D
A= $cmd eq "open"B= scalar @args == 2C= $asm->_get_value_type($args[0]) eq "reg"D= $asm->_get_value_type($args[1]) =~ /:$/u
ABCDresult
0XXX0
10XX0
110X0
11100
11111
426 0 my ($type, $num) = $asm->_parse_id($args[1]);
427 0 my $sni = $asm->_type_to_sni($type);
428 0 return $pkg->new(code => 0, P => $asm->_force_mapped($args[0]), codeX => 1, S => 6, T => 0+2, extra => [$sni, $num], size => $size);
429 ▶ } elsif ($cmd eq 'jump' && scalar(@args) >= 3 && $asm->_get_value_type($args[0]) eq 'int' && ($args[1] eq 'if' || $args[1] eq 'unless')) {
Condition0%0/12
$cmd eq "jump" and scalar @args >= 3 and $asm->_get_value_type($args[0]) eq "int" and $args[1] eq "if" || $args[1] eq "unless"
!ll&&!rl&&r
000
$cmd eq "jump" and scalar @args >= 3 and $asm->_get_value_type($args[0]) eq "int"
!ll&&!rl&&r
000
$cmd eq "jump" and scalar @args >= 3
!ll&&!rl&&r
000
$args[1] eq "if" or $args[1] eq "unless"
l!l&&r!l&&!r
000
MC/DC0%0/5
$cmd eq "jump" and scalar @args >= 3 and $asm->_get_value_type($args[0]) eq "int" and $args[1] eq "if" || $args[1] eq "unless"
$cmd eq "jump" scalar @args >= 3 $asm->_get_value_type($args[0]) eq "int" $args[1] eq "if" $args[1] eq "unless"
Truth table0%0/6
A and B and C and D or E
A= $cmd eq "jump"B= scalar @args >= 3C= $asm->_get_value_type($args[0]) eq "int"D= $args[1] eq "if"E= $args[1] eq "unless"
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
430 0 my $org = $out->tell + 4;
431 0 my $extra = $asm->_parse_int($args[0], $org) - $org;
432 0 my @cond = @args[2..$#args];
433 0 my $P = 0;
434 0 my $S = 0;
435 0 my $T = 0;
436  
437 0 ▶ if ($extra & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra & 1) 0 0 0
438 0 croak sprintf('Bad offset: line %s: offset %i', $line, $extra);
439 }
440 0 $extra /= 2;
441  
442 0 ▶ if ($args[1] eq 'if') {
Branch: 2 branches
BranchTrueFalseTotal
if ($args[1] eq 'if') { } 0 0 0
elsif ($args[1] eq 'unless') { } 0 0 0
443 # no-op
444 } elsif ($args[1] eq 'unless') {
445 0 $P |= 0x1;
446 }
447  
448 0 ▶ while (scalar(@cond) >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @cond >= 3) 0 0 0
449 0 my $reg = shift(@cond);
450 0 my $op = shift(@cond);
451 0 my $val = shift(@cond);
452  
453 0 ▶ croak sprintf('Unsupported jump syntax: line %s: register %s', $line, $reg) unless $reg eq 'out';
Branch: 1 branch
BranchTrueFalseTotal
unless $reg eq "out" 0 0 0
454  
455 0 ▶ if ($op eq 'is') {
Branch: 4 branches
BranchTrueFalseTotal
if ($op eq 'is') { } 0 0 0
elsif ($op eq '<' and $val eq '0' or $op eq '<=' and $val eq '-1') { } 0 0 0
elsif ($op eq '==' and $val eq '0') { } 0 0 0
elsif ($op eq '>' and $val eq '0' or $op eq '>=' and $val =~ /^\+?1$/u) { } 0 0 0
456 0 ▶ if ($val eq 'valid') {
Branch: 3 branches
BranchTrueFalseTotal
if ($val eq 'valid') { } 0 0 0
elsif ($val eq 'true') { } 0 0 0
elsif ($val eq 'notfine' or $val eq 'bad' or $val eq 'dog' or $val eq 'hotdog') { } 0 0 0
457 0 $S |= 0x1;
458 } elsif ($val eq 'true') {
459 0 $S |= 0x2;
460 ▶ } elsif ($val eq 'notfine' || $val eq 'bad' || $val eq 'dog' || $val eq 'hotdog') {
Condition0%0/9
$val eq "notfine" or $val eq "bad" or $val eq "dog" or $val eq "hotdog"
l!l&&r!l&&!r
000
$val eq "notfine" or $val eq "bad" or $val eq "dog"
l!l&&r!l&&!r
000
$val eq "notfine" or $val eq "bad"
l!l&&r!l&&!r
000
MC/DC0%0/4
$val eq "notfine" or $val eq "bad" or $val eq "dog" or $val eq "hotdog"
$val eq "notfine" $val eq "bad" $val eq "dog" $val eq "hotdog"
Truth table0%0/5
A or B or C or D
A= $val eq "notfine"B= $val eq "bad"C= $val eq "dog"D= $val eq "hotdog"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
461 0 $S |= 0x4;
462 } else {
463 0 croak sprintf('Unsupported jump syntax: line %s: is-value %s', $line, $val);
464 }
465 ▶ } elsif (($op eq '<' && $val eq '0') || ($op eq '<=' && $val eq '-1')) {
Condition0%0/9
$op eq "<" and $val eq 0 or $op eq "<=" and $val eq -1
l!l&&r!l&&!r
000
$op eq "<" and $val eq 0
!ll&&!rl&&r
000
$op eq "<=" and $val eq -1
!ll&&!rl&&r
000
MC/DC0%0/4
$op eq "<" and $val eq 0 or $op eq "<=" and $val eq -1
$op eq "<" $val eq 0 $op eq "<=" $val eq -1
Truth table0%0/7
A and B or C and D
A= $op eq "<"B= $val eq 0C= $op eq "<="D= $val eq -1
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
466 0 $T |= 0x1;
467 ▶ } elsif ($op eq '==' && $val eq '0') {
Condition0%0/3
$op eq "==" and $val eq 0
!ll&&!rl&&r
000
MC/DC0%0/2
$op eq "==" and $val eq 0
$op eq "==" $val eq 0
Truth table0%0/3
A and B
A= $op eq "=="B= $val eq 0
ABresult
0X0
100
111
468 0 $T |= 0x2;
469 ▶ } elsif (($op eq '>' && $val eq '0') || ($op eq '>=' && $val =~ /^\+?1$/)) {
Condition0%0/9
$op eq ">" and $val eq 0 or $op eq ">=" and $val =~ /^\+?1$/u
l!l&&r!l&&!r
000
$op eq ">" and $val eq 0
!ll&&!rl&&r
000
$op eq ">=" and $val =~ /^\+?1$/u
!ll&&!rl&&r
000
MC/DC0%0/4
$op eq ">" and $val eq 0 or $op eq ">=" and $val =~ /^\+?1$/u
$op eq ">" $val eq 0 $op eq ">=" $val =~ /^\+?1$/u
Truth table0%0/7
A and B or C and D
A= $op eq ">"B= $val eq 0C= $op eq ">="D= $val =~ /^\+?1$/u
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
470 0 $T |= 0x4;
471 } else {
472 0 croak sprintf('Unsupported jump syntax: line %s: operator/value %s %s', $line, $op, $val);
473 }
474  
475 0 ▶ shift(@cond) if scalar(@cond) && $cond[0] eq 'or';
Branch: 1 branch
BranchTrueFalseTotal
if scalar @cond and $cond[0] eq "or" 0 0 0
Condition0%0/3
scalar @cond and $cond[0] eq "or"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @cond and $cond[0] eq "or"
scalar @cond $cond[0] eq "or"
Truth table0%0/3
A and B
A= scalar @condB= $cond[0] eq "or"
ABresult
0X0
100
111
476 }
477  
478 0 ▶ if (scalar @cond) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @cond) 0 0 0
479 0 croak sprintf('Unsupported jump syntax: line %s: condition %s', $line, join(' ', @cond));
480 }
481  
482 0 return $pkg->new(code => 3, P => $P, codeX => 0, S => $S, T => $T, extra => [$extra]);
483 ▶ } elsif ($cmd eq 'noop' && scalar(@args) == 1 && $asm->_get_value_type($args[0]) eq 'string') {
Condition0%0/6
$cmd eq "noop" and scalar @args == 1 and $asm->_get_value_type($args[0]) eq "string"
!ll&&!rl&&r
000
$cmd eq "noop" and scalar @args == 1
!ll&&!rl&&r
000
MC/DC0%0/3
$cmd eq "noop" and scalar @args == 1 and $asm->_get_value_type($args[0]) eq "string"
$cmd eq "noop" scalar @args == 1 $asm->_get_value_type($args[0]) eq "string"
Truth table0%0/4
A and B and C
A= $cmd eq "noop"B= scalar @args == 1C= $asm->_get_value_type($args[0]) eq "string"
ABCresult
0XX0
10X0
1100
1111
484 0 my $string = $asm->_parse_string($args[0]);
485 0 my $l = length($string);
486  
487 0 ▶ if ($l > 6 || ($l & 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l > 6 or $l & 1) 0 0 0
Condition0%0/3
$l > 6 or $l & 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$l > 6 or $l & 1
$l > 6 $l & 1
Truth table0%0/3
A or B
A= $l > 6B= $l & 1
ABresult
1X1
011
000
488 0 croak sprintf('Unsupported noop with data of invalid length: line %s: length %u', $line, $l);
489 }
490  
491 0 return $pkg->new(first => 0, codeX => 0, S => 0, T => ($l/2), extra => $string);
492 } elsif ($cmd eq 'execution_info_flags') {
493 0 my $flags = 0;
494  
495 0 foreach my $flag (@args) {
496 0 ▶ if ($flag eq 'resources_only') {
Branch: 3 branches
BranchTrueFalseTotal
if ($flag eq 'resources_only') { } 0 0 0
elsif ($flag eq 'single_load') { } 0 0 0
elsif ($flag eq 'multi_session') { } 0 0 0
497 0 $flags |= 1<<15;
498 } elsif ($flag eq 'single_load') {
499 0 $flags |= 1<<14;
500 } elsif ($flag eq 'multi_session') {
501 0 $flags |= (1<<13) | (1<<14);
502 } else {
503 0 croak sprintf('Unsupported/unknown execution_info_flags flag: line %s: flag %s', $line, $flag);
504 }
505 }
506  
507 0 return $pkg->new(code => 0, P => 3, codeX => 0, S => 0, T => 0+1, extra => [$flags]);
508 }
509  
510 0 croak 'Unsupported template';
511 }
512  
513  
514 0 ▶sub read {
Subroutine read: not called CC=26 SCAR=65.5
Pod documented
515 0 my ($pkg, $fh, @opts) = @_;
516 0 my $data;
517 my $pos;
518  
519 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
520  
521 0 $pos = $fh->tell;
522  
523 0 ▶ if (defined($pos) && ($pos & 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos and $pos & 1) 0 0 0
Condition0%0/3
defined $pos and $pos & 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pos and $pos & 1
defined $pos $pos & 1
Truth table0%0/3
A and B
A= defined $posB= $pos & 1
ABresult
0X0
100
111
524 0 croak 'Invalid aligned opcode read';
525 }
526  
527 0 ▶ croak 'Cannot read opcode' unless $fh->read($data, 2) == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh->read($data, 2) == 2 0 0 0
528  
529 {
530 0 my ($first, $second) = unpack('CC', $data);
531 0 my $code = ($first & 0370) >> 3;
532 0 my $P = ($first & 0007) >> 0;
533 0 my $codeX = ($second & 0300) >> 6;
534 0 my $S = ($second & 0070) >> 3;
535 0 my $T = ($second & 0007) >> 0;
536  
537 0 my $registers;
538 my $extra_len;
539 0 my $extra;
540  
541 0 ▶ if ($code <= 3) {
Branch: 2 branches
BranchTrueFalseTotal
if ($code <= 3) { } 0 0 0
elsif ($code == 4) { } 0 0 0
542 0 $registers = $codeX;
543 } elsif ($code == 4) {
544 0 $registers = 3;
545 } else {
546 0 croak sprintf('Unsupported/invalid opcode: 0x%02x%02x: Number of registers is undefined/unknown', $first, $second);
547 }
548  
549 0 ▶ if ($code <= 1 && $codeX <= 1) {
Branch: 8 branches
BranchTrueFalseTotal
if ($code <= 1 and $codeX <= 1) { } 0 0 0
elsif ($code <= 1 and $codeX == 3) { } 0 0 0
elsif ($code == 1 and $codeX == 2 and ($S & 4) == 4) { } 0 0 0
elsif ($code == 1 and $codeX == 2 and $S == 3) { } 0 0 0
elsif ($code == 1 and $codeX == 2 and $S == 1) { } 0 0 0
elsif ($code == 0 and $codeX == 2) { } 0 0 0
elsif ($code == 3) { } 0 0 0
elsif ($code == 4) { } 0 0 0
Condition0%0/3
$code <= 1 and $codeX <= 1
!ll&&!rl&&r
000
MC/DC0%0/2
$code <= 1 and $codeX <= 1
$code <= 1 $codeX <= 1
Truth table0%0/3
A and B
A= $code <= 1B= $codeX <= 1
ABresult
0X0
100
111
550 0 $extra_len = $T & 3;
551 ▶ } elsif ($code <= 1 && $codeX == 3) {
Condition0%0/3
$code <= 1 and $codeX == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$code <= 1 and $codeX == 3
$code <= 1 $codeX == 3
Truth table0%0/3
A and B
A= $code <= 1B= $codeX == 3
ABresult
0X0
100
111
552 0 $extra_len = 0;
553 ▶ } elsif ($code == 1 && $codeX == 2 && ($S & 4) == 4) {
Condition0%0/6
$code == 1 and $codeX == 2 and ($S & 4) == 4
!ll&&!rl&&r
000
$code == 1 and $codeX == 2
!ll&&!rl&&r
000
MC/DC0%0/3
$code == 1 and $codeX == 2 and ($S & 4) == 4
$code == 1 $codeX == 2 ($S & 4) == 4
Truth table0%0/4
A and B and C
A= $code == 1B= $codeX == 2C= ($S & 4) == 4
ABCresult
0XX0
10X0
1100
1111
554 0 $extra_len = 1;
555 ▶ } elsif ($code == 1 && $codeX == 2 && $S == (0 + 3)) {
Condition0%0/6
$code == 1 and $codeX == 2 and $S == 3
!ll&&!rl&&r
000
$code == 1 and $codeX == 2
!ll&&!rl&&r
000
MC/DC0%0/3
$code == 1 and $codeX == 2 and $S == 3
$code == 1 $codeX == 2 $S == 3
Truth table0%0/4
A and B and C
A= $code == 1B= $codeX == 2C= $S == 3
ABCresult
0XX0
10X0
1100
1111
556 0 $extra_len = 2;
557 ▶ } elsif ($code == 1 && $codeX == 2 && $S == (0 + 1)) {
Condition0%0/6
$code == 1 and $codeX == 2 and $S == 1
!ll&&!rl&&r
000
$code == 1 and $codeX == 2
!ll&&!rl&&r
000
MC/DC0%0/3
$code == 1 and $codeX == 2 and $S == 1
$code == 1 $codeX == 2 $S == 1
Truth table0%0/4
A and B and C
A= $code == 1B= $codeX == 2C= $S == 1
ABCresult
0XX0
10X0
1100
1111
558 0 $extra_len = 0;
559 ▶ } elsif ($code == 0 && $codeX == 2) {
Condition0%0/3
$code == 0 and $codeX == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$code == 0 and $codeX == 2
$code == 0 $codeX == 2
Truth table0%0/3
A and B
A= $code == 0B= $codeX == 2
ABresult
0X0
100
111
560 0 $extra_len = 0;
561 } elsif ($code == 3) {
562 0 $extra_len = 1;
563 } elsif ($code == 4) {
564 0 $extra_len = 0;
565 } else {
566 0 croak sprintf('Unsupported/invalid opcode: 0x%02x%02x: Size of extra is undefined/unknown', $first, $second);
567 }
568  
569 #warn sprintf('registers: %u, extra: %u', $registers, $extra_len);
570  
571 0 ▶ if ($extra_len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra_len) 0 0 0
572 0 $extra_len *= 2;
573  
574 0 ▶ croak 'Cannot read extra' unless $fh->read($extra, $extra_len) == $extra_len;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh->read($extra, $extra_len) == $extra_len 0 0 0
575 }
576  
577 0 return $pkg->new(first => $first, second => $second, code => $code, codeX => $codeX, P => $P, S => $S, T => $T, extra => $extra, pos => $pos);
578 }
579  
580 0 croak 'Cannot parse opcode';
581 }
582  
583  
584 0 ▶sub write {
Subroutine write: not called CC=9 SCAR=45.0
Pod documented
585 0 my ($self, $out, @opts) = @_;
586 0 my $required;
587 my $size;
588  
589 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
590  
591 0 $required = $self->required_size;
592  
593 0 ▶ if (defined $self->{size}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'size'}) { } 0 0 0
594 0 $size = $self->{size};
595 } else {
596 0 $size = $required;
597 }
598  
599 0 ▶ if ($required > $size) {
Branch: 2 branches
BranchTrueFalseTotal
if ($required > $size) { } 0 0 0
elsif ($required < $size) { } 0 0 0
600 0 croak sprintf('Opcode does not fit in allocated size: required %u, have %u', $required, $size);
601 } elsif ($required < $size) {
602 0 my $diff = $size - $required;
603 0 ▶ croak 'Opcode padding alignment error' if $diff & 1;
Branch: 1 branch
BranchTrueFalseTotal
if $diff & 1 0 0 0
604 0 print $out chr(0) x $diff;
605 }
606  
607 0 print $out chr($self->{first}), chr($self->{second});
608  
609 0 ▶ if (ref $self->{extra}) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{'extra'}) { } 0 0 0
elsif (defined $self->{'extra'}) { } 0 0 0
610 0 print $out pack('n*', @{$self->{extra}});
611 } elsif (defined $self->{extra}) {
612 0 ▶ $self->{extra} .= chr(0) if length($self->{extra}) & 1;
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"extra"} & 1 0 0 0
613 0 print $out $self->{extra};
614 }
615 }
616  
617  
618 0 ▶sub required_alignment {
Subroutine required_alignment: not called CC=2 SCAR=17.9
Pod documented
619 0 my ($self, @opts) = @_;
620  
621 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
622  
623 0 return 2;
624 }
625  
626  
627 0 ▶sub new_alignment {
Subroutine new_alignment: not called CC=2 SCAR=17.9
Pod documented
628 0 my ($self, @opts) = @_;
629  
630 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
631  
632 0 return 2;
633 }
634  
635  
636 0 ▶sub required_size {
Subroutine required_size: not called CC=10 SCAR=47.0
Pod documented
637 0 my ($self, @opts) = @_;
638 0 my $required;
639  
640 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
641  
642 0 ▶ $self->{first} //= ($self->{code} << 3) | $self->{P};
Condition0%0/2
$self->{"first"} //= $self->{"code"} << 3 | $self->{"P"}
l!l
00
MC/DC0%0/1
$self->{"first"} //= $self->{"code"} << 3 | $self->{"P"}
$self->{"first"}
Truth table0%0/2
A
A= $self->{"first"}
Aresult
11
00
643 0 ▶ $self->{ST} //= ($self->{S} << 3) | $self->{T} unless defined $self->{second};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"second"} 0 0 0
Condition0%0/2
$self->{"ST"} //= $self->{"S"} << 3 | $self->{"T"}
l!l
00
MC/DC0%0/1
$self->{"ST"} //= $self->{"S"} << 3 | $self->{"T"}
$self->{"ST"}
Truth table0%0/2
A
A= $self->{"ST"}
Aresult
11
00
644 0 ▶ $self->{second} //= ($self->{codeX} << 6) | $self->{ST};
Condition0%0/2
$self->{"second"} //= $self->{"codeX"} << 6 | $self->{"ST"}
l!l
00
MC/DC0%0/1
$self->{"second"} //= $self->{"codeX"} << 6 | $self->{"ST"}
$self->{"second"}
Truth table0%0/2
A
A= $self->{"second"}
Aresult
11
00
645 0 ▶ $self->{code} //= ($self->{first} & 0xF8 >> 3);
Condition0%0/2
$self->{"code"} //= $self->{"first"} & 31
l!l
00
MC/DC0%0/1
$self->{"code"} //= $self->{"first"} & 31
$self->{"code"}
Truth table0%0/2
A
A= $self->{"code"}
Aresult
11
00
646  
647 0 $required = 2;
648 0 ▶ if (ref $self->{extra}) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{'extra'}) { } 0 0 0
elsif (defined $self->{'extra'}) { } 0 0 0
649 0 $required += 2 * scalar(@{$self->{extra}});
650 } elsif (defined $self->{extra}) {
651 0 my $l = length($self->{extra});
652 0 ▶ $l++ if $l & 1;
Branch: 1 branch
BranchTrueFalseTotal
if $l & 1 0 0 0
653 0 $required += $l;
654 }
655  
656 0 return $required;
657 }
658  
659  
660 0 ▶sub is_return {
Subroutine is_return: not called CC=9 SCAR=45.0
Pod documented
661 0 my ($self, @opts) = @_;
662  
663 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
664  
665 0 $self->required_size;
666  
667 0 ▶ if ($self->{first} == 0x07 && $self->{codeX} == 0 && $self->{S} == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'first'} == 7 and $self->{'codeX'} == 0 and $self->{'S'} == 2) { } 0 0 0
elsif ($self->{'code'} == 0 and $self->{'codeX'} == 1) { } 0 0 0
Condition0%0/6
$self->{"first"} == 7 and $self->{"codeX"} == 0 and $self->{"S"} == 2
!ll&&!rl&&r
000
$self->{"first"} == 7 and $self->{"codeX"} == 0
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"first"} == 7 and $self->{"codeX"} == 0 and $self->{"S"} == 2
$self->{"first"} == 7 $self->{"codeX"} == 0 $self->{"S"} == 2
Truth table0%0/4
A and B and C
A= $self->{"first"} == 7B= $self->{"codeX"} == 0C= $self->{"S"} == 2
ABCresult
0XX0
10X0
1100
1111
668 0 my $T = $self->{T};
669 0 ▶ return $T == 0 || $T == (4+1);
Condition0%0/3
$T == 0 || $T == 5
l!l&&r!l&&!r
000
MC/DC0%0/2
$T == 0 || $T == 5
$T == 0 $T == 5
Truth table0%0/3
A || B
A= $T == 0B= $T == 5
ABresult
1X1
011
000
670 ▶ } elsif ($self->{code} == 0 && $self->{codeX} == 1) {
Condition0%0/3
$self->{"code"} == 0 and $self->{"codeX"} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"code"} == 0 and $self->{"codeX"} == 1
$self->{"code"} == 0 $self->{"codeX"} == 1
Truth table0%0/3
A and B
A= $self->{"code"} == 0B= $self->{"codeX"} == 1
ABresult
0X0
100
111
671 0 my $S = $self->{S};
672 0 ▶ return $S == 2 || $S == 3;
Condition0%0/3
$S == 2 || $S == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
$S == 2 || $S == 3
$S == 2 $S == 3
Truth table0%0/3
A || B
A= $S == 2B= $S == 3
ABresult
1X1
011
000
673 }
674  
675 0 return undef;
676 }
677  
678  
679 0 ▶sub is_autodie {
Subroutine is_autodie: not called CC=3 SCAR=24.8
Pod documented
680 0 my ($self, @opts) = @_;
681  
682 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
683  
684 0 $self->required_size;
685  
686 0 ▶ return $self->{first} == 0x07 && $self->{second} == 0x14;
Condition0%0/3
$self->{'first'} == 7 && $self->{'second'} == 20
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{'first'} == 7 && $self->{'second'} == 20
$self->{'first'} == 7 $self->{'second'} == 20
Truth table0%0/3
A && B
A= $self->{'first'} == 7B= $self->{'second'} == 20
ABresult
0X0
100
111
687 }
688  
689  
690 0 ▶sub is_end_of_text {
Subroutine is_end_of_text: not called CC=9 SCAR=45.0
Pod documented
691 0 my ($self, @opts) = @_;
692  
693 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
694  
695 0 $self->required_size;
696  
697 0 ▶ if ($self->{first} == 0x06 && $self->{codeX} == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'first'} == 6 and $self->{'codeX'} == 0) { } 0 0 0
elsif ($self->{'first'} == 0 and $self->{'codeX'} == 0 and $self->{'S'} == 3 and $self->{'T'} & 4) { } 0 0 0
Condition0%0/3
$self->{"first"} == 6 and $self->{"codeX"} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"first"} == 6 and $self->{"codeX"} == 0
$self->{"first"} == 6 $self->{"codeX"} == 0
Truth table0%0/3
A and B
A= $self->{"first"} == 6B= $self->{"codeX"} == 0
ABresult
0X0
100
111
698 0 my $S = $self->{S};
699 0 ▶ return $S == 0 || $S == 7;
Condition0%0/3
$S == 0 || $S == 7
l!l&&r!l&&!r
000
MC/DC0%0/2
$S == 0 || $S == 7
$S == 0 $S == 7
Truth table0%0/3
A || B
A= $S == 0B= $S == 7
ABresult
1X1
011
000
700 ▶ } elsif ($self->{first} == 0x00 && $self->{codeX} == 0 && $self->{S} == 3 && ($self->{T} & 4)) {
Condition0%0/9
$self->{"first"} == 0 and $self->{"codeX"} == 0 and $self->{"S"} == 3 and $self->{"T"} & 4
!ll&&!rl&&r
000
$self->{"first"} == 0 and $self->{"codeX"} == 0 and $self->{"S"} == 3
!ll&&!rl&&r
000
$self->{"first"} == 0 and $self->{"codeX"} == 0
!ll&&!rl&&r
000
MC/DC0%0/4
$self->{"first"} == 0 and $self->{"codeX"} == 0 and $self->{"S"} == 3 and $self->{"T"} & 4
$self->{"first"} == 0 $self->{"codeX"} == 0 $self->{"S"} == 3 $self->{"T"} & 4
Truth table0%0/5
A and B and C and D
A= $self->{"first"} == 0B= $self->{"codeX"} == 0C= $self->{"S"} == 3D= $self->{"T"} & 4
ABCDresult
0XXX0
10XX0
110X0
11100
11111
701 0 return 1;
702 }
703  
704 0 return undef;
705 }
706  
707  
708 0 ▶sub as_text {
Subroutine as_text: not called CC=76 SCAR=86.7
Pod documented
709 0 my ($self, @opts) = @_;
710 0 my $name = eval {$self->_name};
711 0 my $opcode_to_text = $self->{opcode_to_text};
712 0 ▶ my $extra = $self->{extra} // '';
Condition0%0/2
$self->{"extra"} // ""
l!l
00
MC/DC0%0/1
$self->{"extra"} // ""
$self->{"extra"}
Truth table0%0/2
A
A= $self->{"extra"}
Aresult
11
00
713 0 my $command;
714  
715 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
716  
717 0 ▶ if (defined $opcode_to_text) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opcode_to_text) { } 0 0 0
718 0 ▶ if (scalar(@{$opcode_to_text->{argmap}}) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$opcode_to_text->{'argmap'};} == 0) { } 0 0 0
719 0 $command = $name;
720 } else {
721 0 my @argmap = @{$opcode_to_text->{argmap}};
722 0 my @extra = unpack('n*', $extra);
723  
724 0 $command = $name;
725  
726 0 ▶ for (my $j = 0; ($j*2) < scalar(@argmap); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j * 2 < scalar @argmap) 0 0 0
727 0 my $type = $argmap[$j*2 + 0];
728 0 my $dst = $argmap[$j*2 + 1];
729  
730 0 ▶ if ($type eq 'reg') {
Branch: 9 branches
BranchTrueFalseTotal
if ($type eq 'reg') { } 0 0 0
elsif ($type =~ /^(?:sni|raen):$/u and $dst eq 'extra[]') { } 0 0 0
elsif ($type eq 'int_half' and $dst eq 'extra[]') { } 0 0 0
elsif ($type eq 'int_rel4' and $dst eq 'extra[]') { } 0 0 0
elsif ($type eq 'int' and $dst eq 'extra[]') { } 0 0 0
elsif ($type eq 'undef' and $dst eq 'undef') { } 0 0 0
elsif ($type =~ /^"([0-9a-zA-Z]+)"$/u and $dst eq 'undef') { } 0 0 0
elsif ($type eq 'autodie' and $dst eq 'true') { } 0 0 0
elsif ($type eq 'autodie' and $dst eq 'false') { } 0 0 0
731 0 $command .= sprintf(' r%u', $self->{$dst});
732 ▶ } elsif ($type =~ /^(?:sni|raen):$/ && $dst eq 'extra[]') {
Condition0%0/3
$type =~ /^(?:sni|raen):$/u and $dst eq "extra[]"
!ll&&!rl&&r
000
MC/DC0%0/2
$type =~ /^(?:sni|raen):$/u and $dst eq "extra[]"
$type =~ /^(?:sni|raen):$/u $dst eq "extra[]"
Truth table0%0/3
A and B
A= $type =~ /^(?:sni|raen):$/uB= $dst eq "extra[]"
ABresult
0X0
100
111
733 0 $command .= sprintf(' %s%u', $type, shift(@extra));
734 ▶ } elsif ($type eq 'int_half' && $dst eq 'extra[]') {
Condition0%0/3
$type eq "int_half" and $dst eq "extra[]"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "int_half" and $dst eq "extra[]"
$type eq "int_half" $dst eq "extra[]"
Truth table0%0/3
A and B
A= $type eq "int_half"B= $dst eq "extra[]"
ABresult
0X0
100
111
735 0 $command .= sprintf(' %u', shift(@extra)*2);
736 ▶ } elsif ($type eq 'int_rel4' && $dst eq 'extra[]') {
Condition0%0/3
$type eq "int_rel4" and $dst eq "extra[]"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "int_rel4" and $dst eq "extra[]"
$type eq "int_rel4" $dst eq "extra[]"
Truth table0%0/3
A and B
A= $type eq "int_rel4"B= $dst eq "extra[]"
ABresult
0X0
100
111
737 0 $command .= sprintf(' %u', shift(@extra)*2 + $self->{pos} + 4);
738 ▶ } elsif ($type eq 'int' && $dst eq 'extra[]') {
Condition0%0/3
$type eq "int" and $dst eq "extra[]"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "int" and $dst eq "extra[]"
$type eq "int" $dst eq "extra[]"
Truth table0%0/3
A and B
A= $type eq "int"B= $dst eq "extra[]"
ABresult
0X0
100
111
739 0 $command .= sprintf(' %u', shift(@extra));
740 ▶ } elsif ($type eq 'undef' && $dst eq 'undef') {
Condition0%0/3
$type eq "undef" and $dst eq "undef"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "undef" and $dst eq "undef"
$type eq "undef" $dst eq "undef"
Truth table0%0/3
A and B
A= $type eq "undef"B= $dst eq "undef"
ABresult
0X0
100
111
741 0 $command .= ' undef';
742 ▶ } elsif ($type =~ /^"([0-9a-zA-Z]+)"$/ && $dst eq 'undef') {
Condition0%0/3
$type =~ /^"([0-9a-zA-Z]+)"$/u and $dst eq "undef"
!ll&&!rl&&r
000
MC/DC0%0/2
$type =~ /^"([0-9a-zA-Z]+)"$/u and $dst eq "undef"
$type =~ /^"([0-9a-zA-Z]+)"$/u $dst eq "undef"
Truth table0%0/3
A and B
A= $type =~ /^"([0-9a-zA-Z]+)"$/uB= $dst eq "undef"
ABresult
0X0
100
111
743 0 $command .= ' '.$1;
744 ▶ } elsif ($type eq 'autodie' && $dst eq 'true') {
Condition0%0/3
$type eq "autodie" and $dst eq "true"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "autodie" and $dst eq "true"
$type eq "autodie" $dst eq "true"
Truth table0%0/3
A and B
A= $type eq "autodie"B= $dst eq "true"
ABresult
0X0
100
111
745 0 $command =~ s/^(\S+)(\s?)/$1!$2/;
746 ▶ } elsif ($type eq 'autodie' && $dst eq 'false') {
Condition0%0/3
$type eq "autodie" and $dst eq "false"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "autodie" and $dst eq "false"
$type eq "autodie" $dst eq "false"
Truth table0%0/3
A and B
A= $type eq "autodie"B= $dst eq "false"
ABresult
0X0
100
111
747 0 $command =~ s/^(\S+)(\s?)/$1?$2/;
748 } else {
749 0 $command = undef;
750 0 last;
751 }
752 }
753 }
754 } else {
755 0 my $first = $self->{first};
756 0 my $second = $self->{second};
757 0 my $code = ($first & 0370) >> 3;
758 0 my $P = ($first & 0007) >> 0;
759 0 my $codeX = ($second & 0300) >> 6;
760 0 my $S = ($second & 0070) >> 3;
761 0 my $T = ($second & 0007) >> 0;
762  
763 0 ▶ if ($code == 0 && $codeX == 3 && defined(my $regname = SIRTX::VM::RegisterFile->_physical_name_by_number($second & 0077))) {
Branch: 10 branches
BranchTrueFalseTotal
if ($code == 0 and $codeX == 3 and defined(my $regname = 'SIRTX::VM::RegisterFile'->_physical_name_by_number($second & 63))) { } 0 0 0
elsif ($first == 0 and $codeX == 0 and $S > 0 and $T == 0) { } 0 0 0
elsif ($first == 0 and $codeX == 0 and $S > 0 and $T == 4) { } 0 0 0
elsif ($first == 0 and $codeX == 0 and $S > 0 and $T & 4) { } 0 0 0
elsif ($first == 0 and $codeX == 0 and $S == 0 and $T > 0 and $T < 4) { } 0 0 0
elsif ($code == 0 and $codeX == 2 and $S == 7) { } 0 0 0
elsif ($code == 0 and $codeX == 1 and $S == 6 and $T == 2) { } 0 0 0
elsif ($code == 0 and $codeX == 1 and $S == 7 and $T == 1) { } 0 0 0
elsif ($code == 3 and $codeX == 2 and $S == 0) { } 0 0 0
elsif ($code == 3 and $codeX == 0) { } 0 0 0
Condition0%0/6
$code == 0 and $codeX == 3 and defined(my $regname = "SIRTX::VM::RegisterFile"->_physical_name_by_number($second & 63))
!ll&&!rl&&r
000
$code == 0 and $codeX == 3
!ll&&!rl&&r
000
MC/DC0%0/3
$code == 0 and $codeX == 3 and defined(my $regname = "SIRTX::VM::RegisterFile"->_physical_name_by_number($second & 63))
$code == 0 $codeX == 3 defined(my $regname = "SIRTX::VM::RegisterFile"->_physical_name_by_number($second & 63))
Truth table0%0/4
A and B and C
A= $code == 0B= $codeX == 3C= defined(my $regname = "SIRTX::VM::RegisterFile"->_physical_name_by_number($second & 63))
ABCresult
0XX0
10X0
1100
1111
764 0 $command = sprintf('map r%u %s', $P, $regname);
765 ▶ } elsif ($first == 0 && $codeX == 0 && $S > 0 && $T == 0) {
Condition0%0/9
$first == 0 and $codeX == 0 and $S > 0 and $T == 0
!ll&&!rl&&r
000
$first == 0 and $codeX == 0 and $S > 0
!ll&&!rl&&r
000
$first == 0 and $codeX == 0
!ll&&!rl&&r
000
MC/DC0%0/4
$first == 0 and $codeX == 0 and $S > 0 and $T == 0
$first == 0 $codeX == 0 $S > 0 $T == 0
Truth table0%0/5
A and B and C and D
A= $first == 0B= $codeX == 0C= $S > 0D= $T == 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
766 0 ▶ $command = sprintf('.endsection ; %s', $SIRTX::VM::Assembler::_header_ids_rev{$S} // '???');
Condition0%0/2
$SIRTX::VM::Assembler::_header_ids_rev{$S} // "???"
l!l
00
MC/DC0%0/1
$SIRTX::VM::Assembler::_header_ids_rev{$S} // "???"
$SIRTX::VM::Assembler::_header_ids_rev{$S}
Truth table0%0/2
A
A= $SIRTX::VM::Assembler::_header_ids_rev{$S}
Aresult
11
00
767 ▶ } elsif ($first == 0 && $codeX == 0 && $S > 0 && $T == 4) {
Condition0%0/9
$first == 0 and $codeX == 0 and $S > 0 and $T == 4
!ll&&!rl&&r
000
$first == 0 and $codeX == 0 and $S > 0
!ll&&!rl&&r
000
$first == 0 and $codeX == 0
!ll&&!rl&&r
000
MC/DC0%0/4
$first == 0 and $codeX == 0 and $S > 0 and $T == 4
$first == 0 $codeX == 0 $S > 0 $T == 4
Truth table0%0/5
A and B and C and D
A= $first == 0B= $codeX == 0C= $S > 0D= $T == 4
ABCDresult
0XXX0
10XX0
110X0
11100
11111
768 0 ▶ $command = sprintf('.section %s', $SIRTX::VM::Assembler::_header_ids_rev{$S} // '???');
Condition0%0/2
$SIRTX::VM::Assembler::_header_ids_rev{$S} // "???"
l!l
00
MC/DC0%0/1
$SIRTX::VM::Assembler::_header_ids_rev{$S} // "???"
$SIRTX::VM::Assembler::_header_ids_rev{$S}
Truth table0%0/2
A
A= $SIRTX::VM::Assembler::_header_ids_rev{$S}
Aresult
11
00
769 ▶ } elsif ($first == 0 && $codeX == 0 && $S > 0 && ($T & 4)) {
Condition0%0/9
$first == 0 and $codeX == 0 and $S > 0 and $T & 4
!ll&&!rl&&r
000
$first == 0 and $codeX == 0 and $S > 0
!ll&&!rl&&r
000
$first == 0 and $codeX == 0
!ll&&!rl&&r
000
MC/DC0%0/4
$first == 0 and $codeX == 0 and $S > 0 and $T & 4
$first == 0 $codeX == 0 $S > 0 $T & 4
Truth table0%0/5
A and B and C and D
A= $first == 0B= $codeX == 0C= $S > 0D= $T & 4
ABCDresult
0XXX0
10XX0
110X0
11100
11111
770 0 ▶ $command = sprintf('.section %s %s', $SIRTX::VM::Assembler::_header_ids_rev{$S} // '???', _escape_text($extra));
Condition0%0/2
$SIRTX::VM::Assembler::_header_ids_rev{$S} // "???"
l!l
00
MC/DC0%0/1
$SIRTX::VM::Assembler::_header_ids_rev{$S} // "???"
$SIRTX::VM::Assembler::_header_ids_rev{$S}
Truth table0%0/2
A
A= $SIRTX::VM::Assembler::_header_ids_rev{$S}
Aresult
11
00
771 ▶ } elsif ($first == 0 && $codeX == 0 && $S == 0 && $T > 0 && $T < 4) {
Condition0%0/12
$first == 0 and $codeX == 0 and $S == 0 and $T > 0 and $T < 4
!ll&&!rl&&r
000
$first == 0 and $codeX == 0 and $S == 0 and $T > 0
!ll&&!rl&&r
000
$first == 0 and $codeX == 0 and $S == 0
!ll&&!rl&&r
000
$first == 0 and $codeX == 0
!ll&&!rl&&r
000
MC/DC0%0/5
$first == 0 and $codeX == 0 and $S == 0 and $T > 0 and $T < 4
$first == 0 $codeX == 0 $S == 0 $T > 0 $T < 4
Truth table0%0/6
A and B and C and D and E
A= $first == 0B= $codeX == 0C= $S == 0D= $T > 0E= $T < 4
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
772 0 $command = sprintf('noop %s', _escape_text($extra));
773 ▶ } elsif ($code == 0 && $codeX == 2 && $S == 7) {
Condition0%0/6
$code == 0 and $codeX == 2 and $S == 7
!ll&&!rl&&r
000
$code == 0 and $codeX == 2
!ll&&!rl&&r
000
MC/DC0%0/3
$code == 0 and $codeX == 2 and $S == 7
$code == 0 $codeX == 2 $S == 7
Truth table0%0/4
A and B and C
A= $code == 0B= $codeX == 2C= $S == 7
ABCresult
0XX0
10X0
1100
1111
774 0 $command = sprintf('open r%u %u', $P, $T);
775 ▶ } elsif ($code == 0 && $codeX == 1 && $S == 6 && $T == (0+2)) {
Condition0%0/9
$code == 0 and $codeX == 1 and $S == 6 and $T == 2
!ll&&!rl&&r
000
$code == 0 and $codeX == 1 and $S == 6
!ll&&!rl&&r
000
$code == 0 and $codeX == 1
!ll&&!rl&&r
000
MC/DC0%0/4
$code == 0 and $codeX == 1 and $S == 6 and $T == 2
$code == 0 $codeX == 1 $S == 6 $T == 2
Truth table0%0/5
A and B and C and D
A= $code == 0B= $codeX == 1C= $S == 6D= $T == 2
ABCDresult
0XXX0
10XX0
110X0
11100
11111
776 0 my ($sni, $id) = unpack('nn', $extra);
777 0 ▶ $sni = $_sni_to_logicals{$sni} // $sni;
Condition0%0/3
$_sni_to_logicals{$sni} // $sni
l!l&&r!l&&!r
000
MC/DC0%0/2
$_sni_to_logicals{$sni} // $sni
$_sni_to_logicals{$sni} $sni
Truth table0%0/3
A // B
A= $_sni_to_logicals{$sni}B= $sni
ABresult
1X1
011
000
778 0 $command = sprintf('open r%u %s:%u', $P, $sni, $id);
779 ▶ } elsif ($code == 0 && $codeX == 1 && $S == 7 && $T == (0+1)) {
Condition0%0/9
$code == 0 and $codeX == 1 and $S == 7 and $T == 1
!ll&&!rl&&r
000
$code == 0 and $codeX == 1 and $S == 7
!ll&&!rl&&r
000
$code == 0 and $codeX == 1
!ll&&!rl&&r
000
MC/DC0%0/4
$code == 0 and $codeX == 1 and $S == 7 and $T == 1
$code == 0 $codeX == 1 $S == 7 $T == 1
Truth table0%0/5
A and B and C and D
A= $code == 0B= $codeX == 1C= $S == 7D= $T == 1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
780 0 $command = sprintf('open r%u %u', $P, unpack('n', $extra));
781 ▶ } elsif ($code == 3 && $codeX == 2 && $S == 0) {
Condition0%0/6
$code == 3 and $codeX == 2 and $S == 0
!ll&&!rl&&r
000
$code == 3 and $codeX == 2
!ll&&!rl&&r
000
MC/DC0%0/3
$code == 3 and $codeX == 2 and $S == 0
$code == 3 $codeX == 2 $S == 0
Truth table0%0/4
A and B and C
A= $code == 3B= $codeX == 2C= $S == 0
ABCresult
0XX0
10X0
1100
1111
782 0 my $flags = unpack('n', $extra);
783 0 $command = sprintf('compare out, r%u r%i', $P, $T);
784 0 ▶ $command .= ' with' if $flags;
Branch: 1 branch
BranchTrueFalseTotal
if $flags 0 0 0
785 0 foreach my $key (sort keys %_compare_flags) {
786 0 ▶ $command .= ' '.$key if $flags & $_compare_flags{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $flags & $_compare_flags{$key} 0 0 0
787 }
788 ▶ } elsif ($code == 3 && $codeX == 0) {
Condition0%0/3
$code == 3 and $codeX == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$code == 3 and $codeX == 0
$code == 3 $codeX == 0
Truth table0%0/3
A and B
A= $code == 3B= $codeX == 0
ABresult
0X0
100
111
789 0 $command = sprintf('jump %u', unpack('n', $extra)*2 + $self->{pos} + 4);
790 0 ▶ if ($P & 0x01) {
Branch: 1 branch
BranchTrueFalseTotal
if ($P & 1) { } 0 0 0
791 0 $command .= ' unless';
792 } else {
793 0 $command .= ' if';
794 }
795  
796 0 ▶ $command .= ' out is valid or' if $S & 0x01;
Branch: 1 branch
BranchTrueFalseTotal
if $S & 1 0 0 0
797 0 ▶ $command .= ' out is true or' if $S & 0x02;
Branch: 1 branch
BranchTrueFalseTotal
if $S & 2 0 0 0
798 0 ▶ $command .= ' out is notfine or' if $S & 0x04;
Branch: 1 branch
BranchTrueFalseTotal
if $S & 4 0 0 0
799  
800 0 ▶ $command .= ' out < 0 or' if $T & 0x01;
Branch: 1 branch
BranchTrueFalseTotal
if $T & 1 0 0 0
801 0 ▶ $command .= ' out == 0 or' if $T & 0x02;
Branch: 1 branch
BranchTrueFalseTotal
if $T & 2 0 0 0
802 0 ▶ $command .= ' out > 0 or' if $T & 0x04;
Branch: 1 branch
BranchTrueFalseTotal
if $T & 4 0 0 0
803  
804 0 $command =~ s/ or$//;
805 }
806 }
807  
808 0 ▶ unless (defined $command) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $command) 0 0 0
809 0 $command = sprintf('.byte 0x%02x 0x%02x', $self->{first}, $self->{second});
810 0 ▶ $command .= ', '.join(' ', map {sprintf('0x%02x', ord)} split(//, $self->{extra})) if defined $self->{extra};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"extra"} 0 0 0
811 }
812  
813 {
814 0 ▶ my $pos = defined($self->{pos}) ? sprintf('%04x', $self->{pos}) : '????';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'pos'} ? : 0 0 0
815 $command = sprintf('%-48s ; at 0x%s: code=%2u, P=%u, codeX=%u, S=%u, T=%u, extra=[%s]',
816 $command, $pos,
817 $self->{code}, $self->{P},
818 $self->{codeX}, $self->{S}, $self->{T},
819 0 join(', ', map {sprintf('0x%04x', $_)} unpack('n*', $extra)),
820 );
821 }
822  
823 0 return $command;
824 }
825  
826 # ---- Private helpers ----
827 0 ▶sub _name { # TODO: Private for now, might be exposed later on
Subroutine _name: not called CC=5 SCAR=34.0
828 0 my ($self, @opts) = @_;
829  
830 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
831  
832 0 ▶ return $self->{opcode_to_text}{name} if defined $self->{opcode_to_text};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"opcode_to_text"} 0 0 0
833  
834 {
835 0 my $code;
836  
837 0 $self->required_size;
838  
839 0 $code = ($self->{first} << 8) | $self->{second};
840  
841 0 foreach my $entry (@_opcode_to_text) {
842 0 ▶ if ($entry->{masked_code} == ($code & $entry->{mask})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->{"masked_code"} == ($code & $entry->{"mask"})) 0 0 0
843 0 $self->{opcode_to_text} = $entry;
844 0 return $entry->{name};
845 }
846 }
847 }
848  
849 0 croak 'Unknown/no name for opcode';
850 }
851  
852 0 ▶sub _extra {
Subroutine _extra: not called CC=12 SCAR=50.5
853 0 my ($self, @opts) = @_;
854 0 my %res = (type => 'opcode');
855  
856 0 ▶ croak 'Stray options passed' if scalar @opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @opts 0 0 0
857  
858 0 $self->required_size;
859  
860 0 ▶ if ($self->{first} == 0x01 && $self->{codeX} == 0 && $self->{S} == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'first'} == 1 and $self->{'codeX'} == 0 and $self->{'S'} == 1) { } 0 0 0
elsif ($self->{'first'} == 6 and $self->{'codeX'} == 0 and $self->{'S'} == 7 and defined $self->{'pos'}) { } 0 0 0
Condition0%0/6
$self->{"first"} == 1 and $self->{"codeX"} == 0 and $self->{"S"} == 1
!ll&&!rl&&r
000
$self->{"first"} == 1 and $self->{"codeX"} == 0
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"first"} == 1 and $self->{"codeX"} == 0 and $self->{"S"} == 1
$self->{"first"} == 1 $self->{"codeX"} == 0 $self->{"S"} == 1
Truth table0%0/4
A and B and C
A= $self->{"first"} == 1B= $self->{"codeX"} == 0C= $self->{"S"} == 1
ABCresult
0XX0
10X0
1100
1111
861 0 my $T = $self->{T};
862  
863 0 ▶ if ($T == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($T == 1) 0 0 0
864 0 $res{start_offsets} = [unpack('n', $self->{extra})*2];
865 }
866 ▶ } elsif ($self->{first} == 0x06 && $self->{codeX} == 0 && $self->{S} == 7 && defined($self->{pos})) {
Condition0%0/9
$self->{"first"} == 6 and $self->{"codeX"} == 0 and $self->{"S"} == 7 and defined $self->{"pos"}
!ll&&!rl&&r
000
$self->{"first"} == 6 and $self->{"codeX"} == 0 and $self->{"S"} == 7
!ll&&!rl&&r
000
$self->{"first"} == 6 and $self->{"codeX"} == 0
!ll&&!rl&&r
000
MC/DC0%0/4
$self->{"first"} == 6 and $self->{"codeX"} == 0 and $self->{"S"} == 7 and defined $self->{"pos"}
$self->{"first"} == 6 $self->{"codeX"} == 0 $self->{"S"} == 7 defined $self->{"pos"}
Truth table0%0/5
A and B and C and D
A= $self->{"first"} == 6B= $self->{"codeX"} == 0C= $self->{"S"} == 7D= defined $self->{"pos"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
867 0 my $T = $self->{T};
868 0 my $length;
869  
870 0 ▶ if ($T == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($T == 1) { } 0 0 0
elsif ($T == 2) { } 0 0 0
871 0 $length = unpack('n', $self->{extra})*2;
872 } elsif ($T == 2) {
873 0 $length = unpack('N', $self->{extra})*2;
874 }
875  
876 0 $res{start_offsets} = [$length + $self->{pos} + 4];
877 0 $res{length} = $length;
878 0 $res{type} = 'chunk';
879 }
880  
881 0 return %res;
882 }
883  
884 1 foreach my $key (keys %_simple_opcodes) {
885 38 my $entry = $_simple_opcodes{$key};
886  
887 38 ▶ next if $key eq 'nop'; # skip alias.
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "nop" 1 37 38
888  
889 37 ▶ for (my $i = 0; $i < scalar(@{$entry}); $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$entry;}) 51 37 88
890 51 my @argmap = @{$entry->[$i]};
891 51 my $opcode = $entry->[$i + 1];
892 51 my $first = $opcode->{first};
893 51 my $second = $opcode->{second};
894 51 my $code = $opcode->{code};
895 51 my $codeX = $opcode->{codeX};
896 51 my $ST = $opcode->{ST};
897 51 my $P = $opcode->{P};
898 51 my $S = $opcode->{S};
899 51 my $T = $opcode->{T};
900 51 my $mask = 0;
901  
902 51 ▶ for (my $j = 0; ($j*2) < scalar(@argmap); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j * 2 < scalar @argmap) 90 51 141
903 90 my $type = $argmap[$j*2 + 0];
904 90 my $dst = $argmap[$j*2 + 1];
905  
906 90 ▶ if ($dst eq 'P') {
Branch: 3 branches
BranchTrueFalseTotal
if ($dst eq 'P') { } 29 61 90
elsif ($dst eq 'S') { } 4 57 61
elsif ($dst eq 'T') { } 17 40 57
907 29 $P = 0;
908 29 $mask |= 0x0700;
909 } elsif ($dst eq 'S') {
910 4 $S = 0;
911 4 $mask |= 0070;
912 } elsif ($dst eq 'T') {
913 17 $T = 0;
914 17 $mask |= 0007;
915 }
916 }
917  
918 51 ▶ $first //= ($code << 3) | $P if defined($code) && defined($P);
Branch: 1 branch
BranchTrueFalseTotal
if defined $code and defined $P 47 4 51
Condition80%4/5
defined $code and defined $P
!ll&&!rl&&r
2247
$first //= $code << 3 | $P
l!l
047
MC/DC100%2/2
defined $code and defined $P
defined $code defined $P
MC/DC0%0/1
$first //= $code << 3 | $P
$first
Truth table100%3/3
A and B
A= defined $codeB= defined $P
ABresult
0X0
100
111
Truth table50%1/2
A
A= $first
Aresult
11
00
919 51 ▶ $ST //= ($S << 3) | $T if defined($S) && defined($T);
Branch: 1 branch
BranchTrueFalseTotal
if defined $S and defined $T 50 1 51
Condition60%3/5
defined $S and defined $T
!ll&&!rl&&r
1050
$ST //= $S << 3 | $T
l!l
050
MC/DC50%1/2
defined $S and defined $T
defined $S defined $T
MC/DC0%0/1
$ST //= $S << 3 | $T
$ST
Truth table66%2/3
A and B
A= defined $SB= defined $T
ABresult
0X0
100
111
Truth table50%1/2
A
A= $ST
Aresult
11
00
920 51 ▶ $second //= ($codeX << 6) | $ST if defined($codeX) && defined($ST);
Branch: 1 branch
BranchTrueFalseTotal
if defined $codeX and defined $ST 50 1 51
Condition60%3/5
defined $codeX and defined $ST
!ll&&!rl&&r
1050
$second //= $codeX << 6 | $ST
l!l
050
MC/DC50%1/2
defined $codeX and defined $ST
defined $codeX defined $ST
MC/DC0%0/1
$second //= $codeX << 6 | $ST
$second
Truth table66%2/3
A and B
A= defined $codeXB= defined $ST
ABresult
0X0
100
111
Truth table50%1/2
A
A= $second
Aresult
11
00
921  
922 51 $mask ^= 0xFFFF;
923  
924 51 ▶ if (defined($first) && defined($second)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $first and defined $second) 49 2 51
Condition66%2/3
defined $first and defined $second
!ll&&!rl&&r
2049
MC/DC50%1/2
defined $first and defined $second
defined $first defined $second
Truth table66%2/3
A and B
A= defined $firstB= defined $second
ABresult
0X0
100
111
925 49 my $code = ($first << 8) | $second;
926  
927 49 push(@_opcode_to_text, {
928 masked_code => $code,
929 masked_first => $first,
930 masked_second => $second,
931 mask => $mask,
932 name => $key,
933 argmap => $entry->[$i+0],
934 opcode => $entry->[$i+1],
935 });
936 }
937 }
938 }
939  
940 0 ▶sub _escape_text {
Subroutine _escape_text: not called CC=4 SCAR=30.0
941 0 my ($text) = @_;
942 return '"'.join('',
943 map {
944 0 my $x = ord;
945 0 ▶ $x >= 0x20 && $x <= 0x7E && $x != 0x5C ? $_ : sprintf('\\x%02x', $x)
Branch: 1 branch
BranchTrueFalseTotal
$x >= 32 && $x <= 126 && $x != 92 ? : 0 0 0
Condition0%0/6
$x >= 32 and $x <= 126 and $x != 92
!ll&&!rl&&r
000
$x >= 32 and $x <= 126
!ll&&!rl&&r
000
MC/DC0%0/3
$x >= 32 and $x <= 126 and $x != 92
$x >= 32 $x <= 126 $x != 92
Truth table0%0/4
A and B and C
A= $x >= 32B= $x <= 126C= $x != 92
ABCresult
0XX0
10X0
1100
1111
946 } split //, $text
947 ).'"';
948 }
949  
950 #warn sprintf('# %04x / %04x => %s', $_->{masked_code}, $_->{mask}, $_->{name}) foreach @_opcode_to_text;
951  
952 1 1;
953  
954 __END__
« VM/Assembler.pm ↑ Summary VM/Disassembler.pm »