]> git.imager.perl.org - imager.git/blame - regops.perl
move t1lib font support to a separate module
[imager.git] / regops.perl
CommitLineData
02d1d628
AMH
1#!perl -w
2use strict;
3use Data::Dumper;
4my $in = shift or die "No input name";
5my $out = shift or die "No output name";
6open(IN, $in) or die "Cannot open input $in: $!";
7open(OUT, "> $out") or die "Cannot create $out: $!";
8print OUT <<'EOS';
9# AUTOMATICALLY GENERATED BY regops.perl
10package Imager::Regops;
11use strict;
12require Exporter;
13use vars qw(@ISA @EXPORT @EXPORT_OK %Attr $MaxOperands $PackCode);
14@ISA = qw(Exporter);
15@EXPORT_OK = qw(%Attr $MaxOperands $PackCode);
16
17EOS
18my @ops;
19my %attr;
20my $opcode = 0;
21my $max_opr = 0;
22my $reg_pack;
23while (<IN>) {
24 if (/^\s*rbc_(\w+)/) {
25 my $op = $1;
26 push(@ops, uc "RBC_$op");
27 # each line has a comment with the registers used - find the maximum
28 # I could probably do this as one line, but let's not
29 my @parms = /\b([rp][a-z])\b/g;
30 $max_opr = @parms if @parms > $max_opr;
31 my $types = join("", map {substr($_,0,1)} @parms);
32 my ($result) = /->\s*([rp])/;
33 $attr{$op} = { parms=>scalar @parms,
34 types=>$types,
35 func=>/\w+\(/?1:0,
36 opcode=>$opcode,
37 result=>$result
38 };
39 print OUT "use constant RBC_\U$op\E => $opcode;\n";
40 ++$opcode;
41 }
42 if (/^\#define RM_WORD_PACK \"(.)\"/) {
43 $reg_pack = $1;
44 }
45}
46print OUT "\n\@EXPORT = qw(@ops);\n\n";
61c9a3b2
TC
47# previously we used Data::Dumper, with Sortkeys()
48# to make sure the generated code only changed when the data
49# changed. Unfortunately Sortkeys isn't supported in some versions of
50# perl we try to support, so we now generate this manually
51print OUT "%Attr =\n (\n";
52for my $opname (sort keys %attr) {
53 my $op = $attr{$opname};
54 print OUT " '$opname' =>\n {\n";
55 for my $attrname (sort keys %$op) {
56 my $attr = $op->{$attrname};
57 print OUT " '$attrname' => ";
58 if (defined $attr) {
59 if ($attr =~ /^\d+$/) {
60 print OUT $attr;
61 }
62 else {
63 print OUT "'$attr'";
64 }
65 }
66 else {
67 print OUT "undef";
68 }
69
70 print OUT ",\n";
71 }
72 print OUT " },\n";
73}
74print OUT " );\n";
02d1d628
AMH
75print OUT "\$MaxOperands = $max_opr;\n";
76print OUT qq/\$PackCode = "$reg_pack";\n/;
77print OUT <<'EOS';
781;
79
80__END__
81
82=head1 NAME
83
5715f7c3 84Imager::Regops - generated information about the register based virtual machine
02d1d628
AMH
85
86=head1 SYNOPSIS
87
88 use Imager::Regops;
89 $Imager::Regops::Attr{$opname}->{opcode} # opcode for given operator
90 $Imager::Regops::Attr{$opname}->{parms} # number of parameters
91 $Imager::Regops::Attr{$opname}->{types} # types of parameters
92 $Imager::Regops::Attr{$opname}->{func} # operator is a function
93 $Imager::Regops::Attr{$opname}->{result} # r for numeric, p for pixel result
94 $Imager::Regops::MaxOperands; # maximum number of operands
95
96=head1 DESCRIPTION
97
5715f7c3 98This module is generated automatically from F<regmach.h> so we don't need to
02d1d628
AMH
99maintain the same information in at least one extra place.
100
101At least that's the idea.
102
103=head1 AUTHOR
104
105Tony Cook, tony@develop-help.com
106
107=head1 SEE ALSO
108
8f22b8d8 109perl(1), Imager(3), http://imager.perl.org/
02d1d628
AMH
110
111=cut
112
113EOS
114close(OUT) or die "Cannot close $out: $!";
115close IN;