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   3510 use strict;
  1         1  
  1         31  
3 1     1   451 use Data::Dumper;
  1         6735  
  1         1714  
4 1 50       115307 my $in = shift or die "No input name";
5 1 50       4 my $out = shift or die "No output name";
6 1 50       44 open(IN, $in) or die "Cannot open input $in: $!";
7 1 50       153 open(OUT, "> $out") or die "Cannot create $out: $!";
8 1         4 binmode OUT;
9 1         17 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         1 my $max_opr = 0;
24 1         1 my $reg_pack;
25 1         25 while () {
26 89 100       151 if (/^\s*rbc_(\w+)/) {
27 53         54 my $op = $1;
28 53         65 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         145 my @parms = /\b([rp][a-z])\b/g;
32 53 100       66 $max_opr = @parms if @parms > $max_opr;
33 53         44 my $types = join("", map {substr($_,0,1)} @parms);
  92         145  
34 53         87 my ($result) = /->\s*([rp])/;
35 53 100       254 $attr{$op} = { parms=>scalar @parms,
36             types=>$types,
37             func=>/\w+\(/?1:0,
38             opcode=>$opcode,
39             result=>$result
40             };
41 53         88 print OUT "use constant RBC_\U$op\E => $opcode;\n";
42 53         69 ++$opcode;
43             }
44 89 100       194 if (/^\#define RM_WORD_PACK \"(.)\"/) {
45 1         3 $reg_pack = $1;
46             }
47             }
48 1         7 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         21 for my $opname (sort keys %attr) {
55 53         71 my $op = $attr{$opname};
56 53         120 print OUT " '$opname' =>\n {\n";
57 53         97 for my $attrname (sort keys %$op) {
58 265         209 my $attr = $op->{$attrname};
59 265         181 print OUT " '$attrname' => ";
60 265 100       200 if (defined $attr) {
61 260 100       265 if ($attr =~ /^\d+$/) {
62 159         120 print OUT $attr;
63             }
64             else {
65 101         75 print OUT "'$attr'";
66             }
67             }
68             else {
69 5         10 print OUT "undef";
70             }
71              
72 265         219 print OUT ",\n";
73             }
74 53         56 print OUT " },\n";
75             }
76 1         3 print OUT " );\n";
77 1         10 print OUT "our \$MaxOperands = $max_opr;\n";
78 1         2 print OUT qq/our \$PackCode = "$reg_pack";\n/;
79 1         2 print OUT <<'EOS';
80             1;
81              
82             __END__