4 my $in = shift or die "No input name";
5 my $out = shift or die "No output name";
6 open(IN, $in) or die "Cannot open input $in: $!";
7 open(OUT, "> $out") or die "Cannot create $out: $!";
10 # AUTOMATICALLY GENERATED BY regops.perl
11 package Imager::Regops;
15 our @ISA = qw(Exporter);
16 our @EXPORT_OK = qw(%Attr $MaxOperands $PackCode);
17 our $VERSION = "1.000";
26 if (/^\s*rbc_(\w+)/) {
28 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 my @parms = /\b([rp][a-z])\b/g;
32 $max_opr = @parms if @parms > $max_opr;
33 my $types = join("", map {substr($_,0,1)} @parms);
34 my ($result) = /->\s*([rp])/;
35 $attr{$op} = { parms=>scalar @parms,
41 print OUT "use constant RBC_\U$op\E => $opcode;\n";
44 if (/^\#define RM_WORD_PACK \"(.)\"/) {
48 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 print OUT "our %Attr =\n (\n";
54 for my $opname (sort keys %attr) {
55 my $op = $attr{$opname};
56 print OUT " '$opname' =>\n {\n";
57 for my $attrname (sort keys %$op) {
58 my $attr = $op->{$attrname};
59 print OUT " '$attrname' => ";
61 if ($attr =~ /^\d+$/) {
77 print OUT "our \$MaxOperands = $max_opr;\n";
78 print OUT qq/our \$PackCode = "$reg_pack";\n/;
86 Imager::Regops - generated information about the register based virtual machine
91 $Imager::Regops::Attr{$opname}->{opcode} # opcode for given operator
92 $Imager::Regops::Attr{$opname}->{parms} # number of parameters
93 $Imager::Regops::Attr{$opname}->{types} # types of parameters
94 $Imager::Regops::Attr{$opname}->{func} # operator is a function
95 $Imager::Regops::Attr{$opname}->{result} # r for numeric, p for pixel result
96 $Imager::Regops::MaxOperands; # maximum number of operands
100 This module is generated automatically from F<regmach.h> so we don't need to
101 maintain the same information in at least one extra place.
103 At least that's the idea.
107 Tony Cook, tony@develop-help.com
111 perl(1), Imager(3), http://imager.perl.org/
116 close(OUT) or die "Cannot close $out: $!";