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";
75 print "enum reg_enum {\n";
76 $attach = ' = EXPR_REG_START'; # EXPR_REG_START == 1
77 foreach $reg ( sort(keys(%regs)) ) {
78 print " R_\U${reg}\E${attach},\n";
79 $attach = ''; $ch = ',';
81 print " REG_ENUM_LIMIT\n";
83 foreach $reg ( sort(keys(%regs)) ) {
84 printf "#define %-15s %2d\n", "REG_NUM_\U${reg}", $regvals{$reg};
87 } elsif ( $fmt eq 'c' ) {
89 print "/* automatically generated from $file - do not edit */\n";
90 print "static const char *reg_names[] = "; $ch = '{';
91 # This one has no dummy entry for 0
92 foreach $reg ( sort(keys(%regs)) ) {
93 print "$ch\n \"${reg}\"";
97 } elsif ( $fmt eq 'fc' ) {
99 print "/* automatically generated from $file - do not edit */\n";
100 print "static const int32_t reg_flags[] = {\n";
101 print " 0"; # Dummy entry for 0
102 foreach $reg ( sort(keys(%regs)) ) {
103 print ",\n ", $regs{$reg}; # Print the class of the register
106 } elsif ( $fmt eq 'vc' ) {
108 print "/* automatically generated from $file - do not edit */\n";
109 print "static const int regvals[] = {\n";
110 print " -1"; # Dummy entry for 0
111 foreach $reg ( sort(keys(%regs)) ) {
112 printf ",\n %2d", $regvals{$reg}; # Print the regval of the register
115 } elsif ( $fmt eq 'dc' ) {
117 print "/* automatically generated from $file - do not edit */\n";
118 foreach $class ( sort(keys(%disclass)) ) {
119 printf "static const int rd_%-8s[] = {", $class;
120 @foo = @{$disclass{$class}};
122 for ( $i = 0 ; $i < scalar(@foo) ; $i++ ) {
123 if (defined($foo[$i])) {
124 push(@bar, "R_\U$foo[$i]\E");
126 die "$0: No register name for class $class, value $i\n";
129 print join(',', @bar), "};\n";
132 die "$0: Unknown output format\n";