regops.perl

filter: Statementstmt 100% 51 / 51 Branchbran 79.1% 19 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 93.5% 72 / 77 CC 1 SCAR 0.0
CC
1
Cov
93%
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« hlines.c ↑ Summary conv.im »
1 #!perl -w
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶my $in = shift or die "No input name";
Branch: 1 branch
BranchTrueFalseTotal
my $in = shift @ARGV or die "No input name" 1 0 1
5 1 ▶my $out = shift or die "No output name";
Branch: 1 branch
BranchTrueFalseTotal
my $out = shift @ARGV or die "No output name" 1 0 1
6 1 ▶open(IN, $in) or die "Cannot open input $in: $!";
Branch: 1 branch
BranchTrueFalseTotal
open IN, $in or die "Cannot open input ${in}: $!" 1 0 1
7 1 ▶open(OUT, "> $out") or die "Cannot create $out: $!";
Branch: 1 branch
BranchTrueFalseTotal
open OUT, "> $out" or die "Cannot create ${out}: $!" 1 0 1
8 1 binmode OUT;
9 1 print OUT <<'EOS';
10 # AUTOMATICALLY GENERATED BY regops.perl
11 package Imager::Regops;
12 use 5.006;
13 use strict;
14 require Exporter;
15 our @ISA = qw(Exporter);
16 our @EXPORT_OK = qw(%Attr $MaxOperands $PackCode);
17 our $VERSION = "1.000";
18  
19 EOS
20 1 my @ops;
21 my %attr;
22 1 my $opcode = 0;
23 1 my $max_opr = 0;
24 1 my $reg_pack;
25 1 ▶while (<IN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline IN)) 89 1 90
26 89 ▶ if (/^\s*rbc_(\w+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*rbc_(\w+)/) 53 36 89
27 53 my $op = $1;
28 53 push(@ops, uc "RBC_$op");
29 # each line has a comment with the registers used - find the maximum
30 # I could probably do this as one line, but let's not
31 53 my @parms = /\b([rp][a-z])\b/g;
32 53 ▶ $max_opr = @parms if @parms > $max_opr;
Branch: 1 branch
BranchTrueFalseTotal
if @parms > $max_opr 2 51 53
33 53 my $types = join("", map {substr($_,0,1)} @parms);
34 53 my ($result) = /->\s*([rp])/;
35 53 ▶ $attr{$op} = { parms=>scalar @parms,
Branch: 1 branch
BranchTrueFalseTotal
/\w+\(/ ? : 27 26 53
36 types=>$types,
37 func=>/\w+\(/?1:0,
38 opcode=>$opcode,
39 result=>$result
40 };
41 53 print OUT "use constant RBC_\U$op\E => $opcode;\n";
42 53 ++$opcode;
43 }
44 89 ▶ if (/^\#define RM_WORD_PACK \"(.)\"/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\#define RM_WORD_PACK \"(.)\"/) 1 88 89
45 1 $reg_pack = $1;
46 }
47 }
48 1 print OUT "\nour \@EXPORT = qw(@ops);\n\n";
49 # previously we used Data::Dumper, with Sortkeys()
50 # to make sure the generated code only changed when the data
51 # changed. Unfortunately Sortkeys isn't supported in some versions of
52 # perl we try to support, so we now generate this manually
53 1 print OUT "our %Attr =\n (\n";
54 1 for my $opname (sort keys %attr) {
55 53 my $op = $attr{$opname};
56 53 print OUT " '$opname' =>\n {\n";
57 53 for my $attrname (sort keys %$op) {
58 265 my $attr = $op->{$attrname};
59 265 print OUT " '$attrname' => ";
60 265 ▶ if (defined $attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr) { } 260 5 265
61 260 ▶ if ($attr =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ /^\d+$/) { } 159 101 260
62 159 print OUT $attr;
63 }
64 else {
65 101 print OUT "'$attr'";
66 }
67 }
68 else {
69 5 print OUT "undef";
70 }
71  
72 265 print OUT ",\n";
73 }
74 53 print OUT " },\n";
75 }
76 1 print OUT " );\n";
77 1 print OUT "our \$MaxOperands = $max_opr;\n";
78 1 print OUT qq/our \$PackCode = "$reg_pack";\n/;
79 1 print OUT <<'EOS';
80 1;
81  
82 __END__
« hlines.c ↑ Summary conv.im »