4 # Read regs.dat and output regs.h and regs.c (included in names.c)
13 if ( $line !~ /^\s*(\S+)\s*(\S+)\s*(\S+)\s*([0-7])\s*$/ ) {
14 die "regs.dat:$nline: invalid input\n";
21 $regs{$reg} = $aclass;
22 $regvals{$reg} = $regval;
24 if ( !defined($disclass{$dclass}) ) {
25 $disclass{$dclass} = [(undef) x
8];
28 $disclass{$dclass}->[$regval] = $reg;
31 ($fmt, $file) = @ARGV;
36 open(REGS
, "< ${file}") or die "$0: Cannot open $file\n";
37 while ( defined($line = <REGS
>) ) {
41 $line =~ s/\s*(\#.*|)$//;
43 next if ( $line eq '' );
45 if ( $line =~ /\*/ ) {
46 for ( $i = 0 ; $i < 8 ; $i++ ) {
47 ($xline = $line) =~ s/\*/$i/g;
58 print "/* automatically generated from $file - do not edit */\n";
59 print "enum reg_enum {\n";
60 $attach = ' = EXPR_REG_START'; # EXPR_REG_START == 1
61 foreach $reg ( sort(keys(%regs)) ) {
62 print " R_\U${reg}\E${attach},\n";
63 $attach = ''; $ch = ',';
65 print " REG_ENUM_LIMIT\n";
67 } elsif ( $fmt eq 'c' ) {
69 print "/* automatically generated from $file - do not edit */\n";
70 print "static const char *reg_names[] = "; $ch = '{';
71 # This one has no dummy entry for 0
72 foreach $reg ( sort(keys(%regs)) ) {
73 print "$ch\n \"${reg}\"";
77 } elsif ( $fmt eq 'fc' ) {
79 print "/* automatically generated from $file - do not edit */\n";
80 print "static const long reg_flags[] = {\n";
81 print " 0"; # Dummy entry for 0
82 foreach $reg ( sort(keys(%regs)) ) {
83 print ",\n ", $regs{$reg}; # Print the class of the register
86 } elsif ( $fmt eq 'vc' ) {
88 print "/* automatically generated from $file - do not edit */\n";
89 print "static const int regvals[] = {\n";
90 print " -1"; # Dummy entry for 0
91 foreach $reg ( sort(keys(%regs)) ) {
92 print ",\n ", $regvals{$reg}; # Print the regval of the register
95 } elsif ( $fmt eq 'dc' ) {
97 print "/* automatically generated from $file - do not edit */\n";
98 foreach $class ( sort(keys(%disclass)) ) {
99 printf "static const int %-8s[] = {", $class;
100 @foo = @
{$disclass{$class}};
101 for ( $i = 0 ; $i < scalar(@foo) ; $i++ ) {
102 $foo[$i] = defined($foo[$i]) ?
"R_\U$foo[$i]\E" : '0';
104 print join(',', @foo), "};\n";
107 die "$0: Unknown output format\n";