blib/lib/Opcodes.pm

filter: Statementstmt 92.0% 81 / 88 Branchbran 57.6% 15 / 26 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 20 / 20 Podpod 100% 7 / 7 totaltotal 85.4% 129 / 151 CC 19 SCAR 14.2
CC
19
Cov
83%
opflags
9.9
maybranch
5.9
opaliases
4.0
CRAP 4.2
↑ Summary const-c.inc »
1 package Opcodes;
2  
3 1 ▶use 5.006_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our($VERSION, @ISA, @EXPORT, @EXPORT_OK);
7  
8 1 $VERSION = "0.16";
9  
10 1 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use XSLoader ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 @ISA = qw(Exporter);
15 1 @EXPORT =
16 qw(opcodes opname opname2code opflags opaliases
17 opargs opclass opdesc opname
18 OA_CLASS_MASK
19 OA_MARK
20 OA_FOLDCONST
21 OA_RETSCALAR
22 OA_TARGET
23 OA_RETINTEGER
24 OA_OTHERINT
25 OA_DANGEROUS
26 OA_DEFGV
27 OA_TARGLEX
28  
29 OA_BASEOP
30 OA_UNOP
31 OA_BINOP
32 OA_LOGOP
33 OA_LISTOP
34 OA_PMOP
35 OA_SVOP
36 OA_PADOP
37 OA_PVOP_OR_SVOP
38 OA_LOOP
39 OA_COP
40 OA_BASEOP_OR_UNOP
41 OA_FILESTATOP
42 OA_LOOPEXOP
43  
44 OA_SCALAR
45 OA_LIST
46 OA_AVREF
47 OA_HVREF
48 OA_CVREF
49 OA_FILEREF
50 OA_SCALARREF
51 OA_OPTIONAL
52  
53 OA_NOSTACK
54 OA_MAYSCALAR
55 OA_MAYARRAY
56 OA_MAYVOID
57 OA_RETFIXED
58 OA_MAYBRANCH
59 );
60 1 @EXPORT_OK = qw(ppaddr check argnum maybranch);
61 }
62 1 ▶use subs @EXPORT_OK;
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 1 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=3 SCAR=11.1
65 # 'autoload' constants from the constant() XS function.
66 1 my $constname;
67 1 our $AUTOLOAD;
68 1 ($constname = $AUTOLOAD) =~ s/.*:://;
69 1 ▶ die "&Opcodes::constant not defined" if $constname eq 'constant';
Branch: 1 branch
BranchTrueFalseTotal
if $constname eq "constant" 0 1 1
70 1 my ($error, $val) = constant($constname);
71 0 ▶ if ($error) { die $error; }
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 1 1
72 {
73 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
74 1 ▶ *$AUTOLOAD = sub { $val };
Subroutine __ANON__: called CC=1 SCAR=0.0
75 }
76 1 goto &$AUTOLOAD;
77 }
78  
79 1 XSLoader::load 'Opcodes', $VERSION;
80  
81 1 our @opcodes = opcodes();
82  
83 276 ▶sub opname ($) {
Subroutine opname: called CC=1 SCAR=0.0
Pod documented
84 276 $opcodes[ $_[0] ]->[1];
85 }
86  
87 6 ▶sub ppaddr ($) {
Subroutine ppaddr: called CC=1 SCAR=0.0
88 6 $opcodes[ $_[0] ]->[2];
89 }
90  
91 2 ▶sub check ($) {
Subroutine check: called CC=1 SCAR=0.0
92 2 $opcodes[ $_[0] ]->[3];
93 }
94  
95 1 ▶sub opdesc ($) {
Subroutine opdesc: called CC=1 SCAR=0.0
Pod documented
96 1 Opcode::opdesc( opname( $_[0] ));
97 }
98  
99 9 ▶sub opargs ($) {
Subroutine opargs: called CC=1 SCAR=0.0
Pod documented
100 9 $opcodes[ $_[0] ]->[4];
101 }
102  
103 # n no_stack - A handcoded list of ops without any SP handling (Note: stack_base is allowed),
104 # i.e. no args + no return values.
105 # 'n' 512 is not encoded in opcode.pl. We could add it but then we would have to
106 # maintain it in CORE as well as here. Here its is needed for older perls. So
107 # keep it this way. Note that enter,entertry,leave indirectly use the stack.
108 1 our %no_stack = map{$_=>1}qw[null unstack scope lineseq
109 next redo goto break continue nextstate dbstate pushmark
110 regcmaybe regcreset];
111 # S retval may be scalar. s and i are automatically included
112 0 our %retval_scalar = map{$_=>1}qw[];
113 # A retval may be array
114 0 our %retval_array = map{$_=>1}qw[];
115 # V retval may be void
116 0 our %retval_void = map{$_=>1}qw[];
117 # F fixed retval type (S, A or V)
118 0 our %retval_fixed = map{$_=>1}qw[];
119 # N pp_* may return other than op_next
120 1 our %maybranch = map{$_=>1}
121 # LOGOP's which return op_other
122 qw[once cond_expr and or orassign andassign dor dorassign grepwhile mapwhile substcont
123 enterwhen entergiven range
124 ],
125 # other OPs
126 qw[formline grepstart flip dbstate goto leaveeval
127 break
128 subst entersub
129 return last next redo require entereval entertry continue dump
130 ];
131  
132 2 ▶sub opflags ($) {
Subroutine opflags: called CC=8 SCAR=22.9
Pod documented
133 # 0x1ff = 9 bits OCSHIFT
134 2 my $OCSHIFT = constant('OCSHIFT'); # 9
135 2 my $mask = (2 ** $OCSHIFT) - 1;
136 2 my $flags = opargs($_[0]) & $mask; # & 0x1ff
137 # now the extras
138 2 my $opname = opname($_[0]);
139 #$flags += 16 if $retint{$opname};
140 2 ▶ $flags += 512 if $no_stack{$opname};
Branch: 1 branch
BranchTrueFalseTotal
if $Opcodes::no_stack{$opname} 0 2 2
141 2 ▶ $flags += 1024 if $retval_scalar{$opname} or $flags & 20; # 4|16
Branch: 1 branch
BranchTrueFalseTotal
if $Opcodes::retval_scalar{$opname} or $flags & 20 2 0 2
Condition33%1/3
$Opcodes::retval_scalar{$opname} or $flags & 20
l!l&&r!l&&!r
020
MC/DC0%0/2
$Opcodes::retval_scalar{$opname} or $flags & 20
$Opcodes::retval_scalar{$opname} $flags & 20
Truth table33%1/3
A or B
A= $Opcodes::retval_scalar{$opname}B= $flags & 20
ABresult
1X1
011
000
142 2 ▶ $flags += 2048 if $retval_array{$opname};
Branch: 1 branch
BranchTrueFalseTotal
if $Opcodes::retval_array{$opname} 0 2 2
143 2 ▶ $flags += 4096 if $retval_void{$opname};
Branch: 1 branch
BranchTrueFalseTotal
if $Opcodes::retval_void{$opname} 0 2 2
144 2 ▶ $flags += 8192 if $retval_fixed{$opname};
Branch: 1 branch
BranchTrueFalseTotal
if $Opcodes::retval_fixed{$opname} 0 2 2
145 2 ▶ $flags += 16384 if maybranch($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if &maybranch($_[0]) 0 2 2
146 2 return $flags;
147 }
148  
149 # See F<opcode.pl> for $OASHIFT and $OCSHIFT. For flags n 512 we
150 # would have to change that.
151 4 ▶sub opclass ($) {
Subroutine opclass: called CC=1 SCAR=0.0
Pod documented
152 4 my $OCSHIFT = constant('OCSHIFT'); # 9
153 4 my $OASHIFT = constant('OASHIFT'); # 13
154 4 my $mask = (2 ** ($OASHIFT-$OCSHIFT)) - 1; # 0b1111 4bit 13-9=4 bits
155 4 $mask = $mask << $OCSHIFT; # 1e00: 4bit left-shifted by 9
156 4 (opargs($_[0]) & $mask) >> $OCSHIFT;
157 }
158  
159 1 ▶sub argnum ($) {
Subroutine argnum: called CC=1 SCAR=0.0
160 #my $ARGSHIFT = 4;
161 #my $ARGBITS = 32;
162 1 my $OASHIFT = constant('OASHIFT'); # 13
163 # ffffe000 = 32-13 bits left-shifted by 13
164 1 my $mask = ((2 ** (32-$OASHIFT)) - 1) << $OASHIFT;
165 1 (opargs($_[0]) & $mask) >> $OASHIFT;
166 }
167  
168 4 ▶sub opaliases ($) {
Subroutine opaliases: called CC=4 SCAR=13.9
Pod documented
169 4 my $op = shift;
170 4 my @aliases = ();
171 4 my $ppaddr = ppaddr($op);
172 4 for (@opcodes) {
173 1716 ▶ push @aliases, ($_->[0])
Branch: 1 branch
BranchTrueFalseTotal
if $_->[2] == $ppaddr and $_->[0] != $op 8 1708 1716
Condition100%3/3
$_->[2] == $ppaddr and $_->[0] != $op
!ll&&!rl&&r
170448
MC/DC100%2/2
$_->[2] == $ppaddr and $_->[0] != $op
$_->[2] == $ppaddr $_->[0] != $op
Truth table100%3/3
A and B
A= $_->[2] == $ppaddrB= $_->[0] != $op
ABresult
0X0
100
111
174 if $_->[2] == $ppaddr and $_->[0] != $op;
175 }
176 4 @aliases;
177 }
178  
179 3 ▶sub opname2code ($) {
Subroutine opname2code: called CC=3 SCAR=11.1
Pod documented
180 3 my $name = shift;
181 3 ▶ for (0..$#opcodes) { return $_ if opname($_) eq $name; }
Branch: 1 branch
BranchTrueFalseTotal
if &opname($_) eq $name 3 242 245
182 0 return undef;
183 }
184  
185 # All LOGOPs: perl -Mblib -MOpcodes -e'$,=q( );print map {opname $_} grep {opclass($_) == 3} 1..opcodes' =>
186 # regcomp substcont grepwhile mapwhile range and or dor cond_expr andassign orassign dorassign entergiven
187 # enterwhen entertry once
188 # All pp which can return other then op_next (inspected pp*.c):
189 # once and cond_expr or defined grepwhile
190 # substcont formline grepstart mapwhile range flip dbstate goto leaveeval enterwhen break subst entersub
191 # return last next redo require entereval entertry continue
192 # + aliases: maybranch perl -MOpcodes -e'$,=q( );print map {opname $_} grep {opflags($_) & 16384} 1..opcodes'
193 # => subst substcont defined formline grepstart grepwhile mapwhile range and or dor cond_expr andassign
194 # orassign dorassign dbstate return last next redo dump goto entergiven enterwhen require entereval
195 # entertry once
196 3 ▶sub maybranch ($) {
Subroutine maybranch: called CC=5 SCAR=17.8
197 3 ▶ return undef if opclass($_[0]) <= 2; # NOT if lower than LOGOP
Branch: 1 branch
BranchTrueFalseTotal
if &opclass($_[0]) <= 2 0 3 3
198 3 my $opname = opname($_[0]);
199 3 ▶ return 1 if $maybranch{$opname};
Branch: 1 branch
BranchTrueFalseTotal
if $Opcodes::maybranch{$opname} 1 2 3
200 2 for (opaliases($_[0])) {
201 0 ▶ return 1 if $maybranch{opname($_)};
Branch: 1 branch
BranchTrueFalseTotal
if $Opcodes::maybranch{&opname($_)} 0 0 0
202 }
203 2 return undef;
204 }
205  
206  
207 1 1;
208 __END__
↑ Summary const-c.inc »