File Coverage

regops.perl
Criterion Covered Total %
statement 51 51 100.0
branch 17 22 77.2
condition n/a
subroutine 2 2 100.0
pod n/a
total 70 75 93.3


line stmt bran cond sub pod time code
1             #!perl -w
2 1     1   5651 use strict;
  1         2  
  1         43  
3 1     1   706 use Data::Dumper;
  1         11931  
  1         2823  
4 1 50       198745 my $in = shift or die "No input name";
5 1 50       15 my $out = shift or die "No output name";
6 1 50       62 open(IN, $in) or die "Cannot open input $in: $!";
7 1 50       288 open(OUT, "> $out") or die "Cannot create $out: $!";
8 1         6 binmode OUT;
9 1         21 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         3 my @ops;
21             my %attr;
22 1         2 my $opcode = 0;
23 1         4 my $max_opr = 0;
24 1         2 my $reg_pack;
25 1         42 while () {
26 89 100       269 if (/^\s*rbc_(\w+)/) {
27 53         100 my $op = $1;
28 53         146 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         259 my @parms = /\b([rp][a-z])\b/g;
32 53 100       108 $max_opr = @parms if @parms > $max_opr;
33 53         85 my $types = join("", map {substr($_,0,1)} @parms);
  92         261  
34 53         175 my ($result) = /->\s*([rp])/;
35 53 100       433 $attr{$op} = { parms=>scalar @parms,
36             types=>$types,
37             func=>/\w+\(/?1:0,
38             opcode=>$opcode,
39             result=>$result
40             };
41 53         185 print OUT "use constant RBC_\U$op\E => $opcode;\n";
42 53         95 ++$opcode;
43             }
44 89 100       324 if (/^\#define RM_WORD_PACK \"(.)\"/) {
45 1         5 $reg_pack = $1;
46             }
47             }
48 1         15 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         3 print OUT "our %Attr =\n (\n";
54 1         45 for my $opname (sort keys %attr) {
55 53         89 my $op = $attr{$opname};
56 53         140 print OUT " '$opname' =>\n {\n";
57 53         209 for my $attrname (sort keys %$op) {
58 265         408 my $attr = $op->{$attrname};
59 265         391 print OUT " '$attrname' => ";
60 265 100       413 if (defined $attr) {
61 260 100       595 if ($attr =~ /^\d+$/) {
62 159         246 print OUT $attr;
63             }
64             else {
65 101         160 print OUT "'$attr'";
66             }
67             }
68             else {
69 5         9 print OUT "undef";
70             }
71              
72 265         435 print OUT ",\n";
73             }
74 53         111 print OUT " },\n";
75             }
76 1         8 print OUT " );\n";
77 1         27 print OUT "our \$MaxOperands = $max_opr;\n";
78 1         4 print OUT qq/our \$PackCode = "$reg_pack";\n/;
79 1         8 print OUT <<'EOS';
80             1;
81              
82             __END__