optimize.pm

filter: Statementstmt 30.4% 21 / 69 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 8 / 10 Podpod n/a totaltotal 24.1% 29 / 120 CC 23 SCAR 58.5
CC
23
Cov
19%
__ANON__
506.0
dbgprint
6.0
BEGIN
2.0
CRAP 348.5
↑ Summary optimize/int.pm »
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package optimize;
4 3 ▶use Carp; BEGIN { eval { croak "hi\n" }}
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use B::Generate;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use B::Utils qw(walkallops_simple);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use B qw(OPf_KIDS OPf_MOD OPf_PARENS OPf_WANT_SCALAR OPf_STACKED);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Attribute::Handlers;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 our $VERSION = "0.05";
11  
12 our $DEBUG = 0;
13 our %pads;
14 our $state;
15 our %loaded;
16 our $stash = '';
17 our %register;
18  
19 0 ▶sub dbgprint { print @_ if $DEBUG; }
Subroutine dbgprint: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $optimize::DEBUG 0 0 0
20  
21 3 ▶use optimizer "extend-c" => sub {
Subroutine BEGIN: called CC=1 SCAR=6.8
Subroutine __ANON__: not called CC=22 SCAR=62.3
22 0 my $op = shift;
23 0 ▶ return unless $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 0 0
24  
25 0 ▶ if ($op->name eq 'nextstate') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->name eq "nextstate") 0 0 0
26 0 $state = $op;
27 0 $stash = $state->stash->NAME;
28 0 dbgprint $state->file . ":" . $state->line . " " . $state->stash->NAME . "\n";
29 0 ▶ if ($stash =~ /^(optimize|B::|types$|float$|double$|int$|number$|^O$|^DB$)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($optimize::stash =~ /^(optimize|B::|types$|float$|double$|int$|number$|^O$|^DB$)/) 0 0 0
30 0 dbgprint "Don't optimize ourself $stash\n";
31 0 return;
32 }
33 }
34  
35 0 ▶ dbgprint ref($op)." - " . $op->name . " -> " . ref($op->next) . " - " .
Branch: 1 branch
BranchTrueFalseTotal
$op->next->can('name') ? : 0 0 0
36 ($op->next->can('name') ? $op->next->name : "null") . "\n";
37 0 my $cv;
38 0 eval {
39 0 $cv = $op->find_cv;
40 };
41 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
42 0 $@ =~ s/\n//;
43 0 print "$@ in " . $state->file . ":" . $state->line . "\n";;
44 0 return;
45 }
46  
47 # $DB::single = 1 if defined &DB::DB;
48 # const $foo with attributes:
49 # pb -MO=Concise,-exec -e'my $foo : optimize(int) = 1.5;'
50 # pb -MO=Deparse -e'my $foo : optimize(int) = 1.5;'
51 # ('attributes'->import('main', \$foo, 'optimize(int)'), my $foo) = 1.5;
52 0 ▶ dbgprint "sv: ",ref($op->sv),"\n" if $op->name eq 'const';
Branch: 1 branch
BranchTrueFalseTotal
if $op->name eq "const" 0 0 0
53 0 ▶ if ($op->name eq 'const' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($op->name eq "const" and ref($op->sv) =~ /^B::(P|G)V$/) 0 0 0
Condition0%0/3
$op->name eq "const" and ref($op->sv) =~ /^B::(P|G)V$/
!ll&&!rl&&r
000
MC/DC0%0/2
$op->name eq "const" and ref($op->sv) =~ /^B::(P|G)V$/
$op->name eq "const" ref($op->sv) =~ /^B::(P|G)V$/
Truth table0%0/3
A and B
A= $op->name eq "const"B= ref($op->sv) =~ /^B::(P|G)V$/
ABresult
0X0
100
111
54 ref($op->sv) =~ /^B::(P|G)V$/ # GV threaded, PV not-threaded
55 )
56 {
57 #dbgprint "const: ",$op->sv->sv,"\n";
58 0 ▶ if ($op->next->next->name eq 'padsv') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->next->next->name eq "padsv") 0 0 0
59 #dbgprint "padsv ->",
60 # $op->next->next->next,"->",$op->next->next->next->next->name, "\n";
61 0 ▶ if ($op->next->next->next->next->name eq 'srefgen') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->next->next->next->next->name eq "srefgen") 0 0 0
62 #dbgprint "srefgen ->", $op->next->next->next->next->next->name, "\n";
63 0 ▶ if ($op->next->next->next->next->next->name eq 'const') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->next->next->next->next->next->name eq "const") 0 0 0
64 #dbgprint "const ->", $op->next->next->next->next->next->name, "\n";
65 0 ▶ if ($op->next->next->next->next->next->next->name eq 'method_named') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->next->next->next->next->next->next->name eq "method_named") 0 0 0
66 #dbgprint "method: ", $op->next->next->next->next->next->next->name,":",
67 # $op->next->next->next->next->next->next->sv->sv, "\n";
68 0 ▶ if ($op->next->next->next->next->next->next->sv->sv eq 'import') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->next->next->next->next->next->next->sv->sv eq "import") 0 0 0
69  
70 # Here we establish that this is an use of attributes on lexicals
71 # however we want to establish what attribute it is
72 0 my $attribute = $op->next->next->next->next->next->sv->sv;
73 0 dbgprint "my const $attribute\n"; # fails threaded
74
75 0 ▶ if ($attribute =~/^optimize\(\s*(.*)\s*\)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attribute =~ /^optimize\(\s*(.*)\s*\)/) 0 0 0
76 #dbgprint "attr: $attribute\n";
77 0 my @attributes = split /\s*,\s*/, $1;
78 0 dbgprint "GOT " . join("-", @attributes) . "\n";
79 0 my $opnn = $op->next->next;
80 0 ▶ if ($opnn->name eq 'padsv') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opnn->name eq "padsv") 0 0 0
81 0 my $sv = (($cv->PADLIST->ARRAY)[0]->ARRAY)[$opnn->targ];
82 0 my $ref = $pads{$cv->ROOT->seq}->[$opnn->targ] = [$sv->sv(),{}];
83 0 for (@attributes) {
84 0 $ref->[1]{$_}++;
85 0 ▶ unless($loaded{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($optimize::loaded{$_}) 0 0 0
86 0 require "optimize/$_.pm";
87 0 $loaded{$_} = "optimize::$_";
88 }
89 }
90 }
91 }
92 }
93 }
94 }
95 }
96 }
97 }
98  
99 0 for (values %loaded) {
100 0 dbgprint "$_->check ",$op->name,"\n";
101 0 $_->check($op);
102 #dbgprint "Called $_\n";
103 }
104 # calling types
105 0 ▶ if (exists($register{$stash})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $optimize::register{$optimize::stash}) 0 0 0
106 0 for my $callback (values %{$register{$stash}}) {
107 0 ▶ $callback->($op) if $callback;
Branch: 1 branch
BranchTrueFalseTotal
if $callback 0 0 0
108 }
109 }
110  
111 0 };
112  
113 sub register {
114 my $class = shift;
115 my $callback = shift;
116 my $package = shift;
117 my ($name) = (caller)[0];
118 #$DB::single = 1 if defined &DB::DB; # magic to allow debugging into CHECK blocks
119 $register{$package}->{$name} = $callback;
120 }
121  
122 sub unregister {
123 my $class = shift;
124 my $package = shift;
125 my ($name) = (caller)[0];
126 $register{$package}->{$name} = 0;
127 }
128  
129 sub UNIVERSAL::optimize : ATTR {
130 ;
131 }
132  
133 1;
134 __END__
↑ Summary optimize/int.pm »