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   6009 use strict;
  1         3  
  1         42  
3 1     1   711 use Data::Dumper;
  1         12660  
  1         3231  
4 1 50       201178 my $in = shift or die "No input name";
5 1 50       4 my $out = shift or die "No output name";
6 1 50       56 open(IN, $in) or die "Cannot open input $in: $!";
7 1 50       189 open(OUT, "> $out") or die "Cannot create $out: $!";
8 1         5 binmode OUT;
9 1         34 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         6 my @ops;
21             my %attr;
22 1         2 my $opcode = 0;
23 1         3 my $max_opr = 0;
24 1         2 my $reg_pack;
25 1         52 while () {
26 89 100       281 if (/^\s*rbc_(\w+)/) {
27 53         89 my $op = $1;
28 53         111 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         246 my @parms = /\b([rp][a-z])\b/g;
32 53 100       105 $max_opr = @parms if @parms > $max_opr;
33 53         82 my $types = join("", map {substr($_,0,1)} @parms);
  92         246  
34 53         147 my ($result) = /->\s*([rp])/;
35 53 100       327 $attr{$op} = { parms=>scalar @parms,
36             types=>$types,
37             func=>/\w+\(/?1:0,
38             opcode=>$opcode,
39             result=>$result
40             };
41 53         131 print OUT "use constant RBC_\U$op\E => $opcode;\n";
42 53         88 ++$opcode;
43             }
44 89 100       337 if (/^\#define RM_WORD_PACK \"(.)\"/) {
45 1         4 $reg_pack = $1;
46             }
47             }
48 1         13 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         2 print OUT "our %Attr =\n (\n";
54 1         42 for my $opname (sort keys %attr) {
55 53         73 my $op = $attr{$opname};
56 53         160 print OUT " '$opname' =>\n {\n";
57 53         176 for my $attrname (sort keys %$op) {
58 265         434 my $attr = $op->{$attrname};
59 265         380 print OUT " '$attrname' => ";
60 265 100       432 if (defined $attr) {
61 260 100       581 if ($attr =~ /^\d+$/) {
62 159         233 print OUT $attr;
63             }
64             else {
65 101         174 print OUT "'$attr'";
66             }
67             }
68             else {
69 5         8 print OUT "undef";
70             }
71              
72 265         421 print OUT ",\n";
73             }
74 53         116 print OUT " },\n";
75             }
76 1         7 print OUT " );\n";
77 1         14 print OUT "our \$MaxOperands = $max_opr;\n";
78 1         4 print OUT qq/our \$PackCode = "$reg_pack";\n/;
79 1         7 print OUT <<'EOS';
80             1;
81              
82             __END__