4 # Read regs.dat and output regs.h and regs.c (included in names.c)
12 return ($v =~ /^0/) ?
oct $v : $v+0;
19 if ( $line !~ /^\s*(\S+)\s*(\S+)\s*(\S+)\s*([0-9]+)$/i ) {
20 die "regs.dat:$nline: invalid input\n";
25 $x86regno = toint
($4);
27 if ($reg =~ /^(.*[^0-9])([0-9]+)\-([0-9]+)$/) {
35 $regs{$reg} = $aclass;
36 $regvals{$reg} = $x86regno;
38 foreach $dclass (split(/,/, $dclasses)) {
39 if ( !defined($disclass{$dclass}) ) {
40 $disclass{$dclass} = [];
43 $disclass{$dclass}->[$x86regno] = $reg;
46 # Compute the next register, if any
48 if ($reg =~ /^(.*[^0-9])([0-9]+)$/) {
49 $reg = sprintf("%s%u", $1, $2+1);
54 ($fmt, $file) = @ARGV;
59 open(REGS
, "< ${file}") or die "$0: Cannot open $file\n";
60 while ( defined($line = <REGS
>) ) {
64 $line =~ s/\s*(\#.*|)$//;
66 next if ( $line eq '' );
74 print "/* automatically generated from $file - do not edit */\n";
76 printf "#define EXPR_REG_START %d\n", $expr_regs;
77 print "enum reg_enum {\n";
78 $attach = ' = EXPR_REG_START'; # EXPR_REG_START == 1
79 foreach $reg ( sort(keys(%regs)) ) {
80 print " R_\U${reg}\E${attach},\n";
81 $attach = ''; $ch = ',';
84 print " REG_ENUM_LIMIT\n";
86 printf "#define EXPR_REG_END %d\n", $expr_regs-1;
87 foreach $reg ( sort(keys(%regs)) ) {
88 printf "#define %-15s %2d\n", "REG_NUM_\U${reg}", $regvals{$reg};
91 } elsif ( $fmt eq 'c' ) {
93 print "/* automatically generated from $file - do not edit */\n";
94 print "static const char *reg_names[] = "; $ch = '{';
95 # This one has no dummy entry for 0
96 foreach $reg ( sort(keys(%regs)) ) {
97 print "$ch\n \"${reg}\"";
101 } elsif ( $fmt eq 'fc' ) {
103 print "/* automatically generated from $file - do not edit */\n";
104 print "static const int32_t reg_flags[] = {\n";
105 print " 0"; # Dummy entry for 0
106 foreach $reg ( sort(keys(%regs)) ) {
107 print ",\n ", $regs{$reg}; # Print the class of the register
110 } elsif ( $fmt eq 'vc' ) {
112 print "/* automatically generated from $file - do not edit */\n";
113 print "static const int regvals[] = {\n";
114 print " -1"; # Dummy entry for 0
115 foreach $reg ( sort(keys(%regs)) ) {
116 printf ",\n %2d", $regvals{$reg}; # Print the regval of the register
119 } elsif ( $fmt eq 'dc' ) {
121 print "/* automatically generated from $file - do not edit */\n";
122 foreach $class ( sort(keys(%disclass)) ) {
123 printf "static const int rd_%-8s[] = {", $class;
124 @foo = @
{$disclass{$class}};
126 for ( $i = 0 ; $i < scalar(@foo) ; $i++ ) {
127 if (defined($foo[$i])) {
128 push(@bar, "R_\U$foo[$i]\E");
130 die "$0: No register name for class $class, value $i\n";
133 print join(',', @bar), "};\n";
136 die "$0: Unknown output format\n";