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*([1-9][0-9]+|0[0-7]+|0x[0-9a-f]+)\s*([0-9]+)$/i ) {
20 die "regs.dat:$nline: invalid input\n";
26 $x86regno = toint
($5);
28 if ($reg =~ /[0-9]\+$/) {
36 $regs{$reg} = $aclass;
37 $regvals{$reg} = $regval;
39 foreach $dclass (split(/,/, $dclasses)) {
40 if ( !defined($disclass{$dclass}) ) {
41 $disclass{$dclass} = [];
44 $disclass{$dclass}->[$x86regno] = $reg;
47 # Compute the next register, if any
50 if ($reg =~ /^(|.*[^0-9])([0-9]+)$/) {
51 $reg = sprintf("%s%u", $1, $2+1);
56 ($fmt, $file) = @ARGV;
61 open(REGS
, "< ${file}") or die "$0: Cannot open $file\n";
62 while ( defined($line = <REGS
>) ) {
66 $line =~ s/\s*(\#.*|)$//;
68 next if ( $line eq '' );
76 print "/* automatically generated from $file - do not edit */\n";
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 = ',';
83 print " REG_ENUM_LIMIT\n";
85 foreach $reg ( sort(keys(%regs)) ) {
86 print "#define REG_NUM_\U${reg} $regvals{$reg}\n";
89 } elsif ( $fmt eq 'c' ) {
91 print "/* automatically generated from $file - do not edit */\n";
92 print "static const char *reg_names[] = "; $ch = '{';
93 # This one has no dummy entry for 0
94 foreach $reg ( sort(keys(%regs)) ) {
95 print "$ch\n \"${reg}\"";
99 } elsif ( $fmt eq 'fc' ) {
101 print "/* automatically generated from $file - do not edit */\n";
102 print "static const int32_t reg_flags[] = {\n";
103 print " 0"; # Dummy entry for 0
104 foreach $reg ( sort(keys(%regs)) ) {
105 print ",\n ", $regs{$reg}; # Print the class of the register
108 } elsif ( $fmt eq 'vc' ) {
110 print "/* automatically generated from $file - do not edit */\n";
111 print "static const int regvals[] = {\n";
112 print " -1"; # Dummy entry for 0
113 foreach $reg ( sort(keys(%regs)) ) {
114 printf ",\n 0%03o", $regvals{$reg}; # Print the regval of the register
117 } elsif ( $fmt eq 'dc' ) {
119 print "/* automatically generated from $file - do not edit */\n";
120 foreach $class ( sort(keys(%disclass)) ) {
121 printf "static const int rd_%-8s[] = {", $class;
122 @foo = @
{$disclass{$class}};
124 for ( $i = 0 ; $i < scalar(@foo) ; $i++ ) {
125 if (defined($foo[$i])) {
126 push(@bar, "R_\U$foo[$i]\E");
128 die "$0: No register name for class $class, value $i\n";
131 print join(',', @bar), "};\n";
134 die "$0: Unknown output format\n";