3 # Read regs.dat and output regs.h and regs.c (included in names.c)
11 return ($v =~ /^0/) ?
oct $v : $v+0;
18 if ( $line !~ /^\s*(\S+)\s*(\S+)\s*(\S+)\s*([0-9]+)$/i ) {
19 die "regs.dat:$nline: invalid input\n";
24 $x86regno = toint
($4);
26 if ($reg =~ /^(.*[^0-9])([0-9]+)\-([0-9]+)(|[^0-9].*)$/) {
34 undef $reg_prefix, $reg_suffix;
38 $regs{$reg} = $aclass;
39 $regvals{$reg} = $x86regno;
41 foreach $dclass (split(/,/, $dclasses)) {
42 if ( !defined($disclass{$dclass}) ) {
43 $disclass{$dclass} = [];
46 $disclass{$dclass}->[$x86regno] = $reg;
49 # Compute the next register, if any
50 if (defined($reg_prefix)) {
53 $reg = sprintf("%s%u%s", $reg_prefix, $reg_nr, $reg_suffix);
55 # Not a dashed sequence
61 ($fmt, $file) = @ARGV;
66 open(REGS
, "< ${file}") or die "$0: Cannot open $file\n";
67 while ( defined($line = <REGS
>) ) {
71 $line =~ s/\s*(\#.*|)$//;
73 next if ( $line eq '' );
81 print "/* automatically generated from $file - do not edit */\n\n";
83 printf "#define EXPR_REG_START %d\n", $expr_regs;
84 print "enum reg_enum {\n";
85 $attach = ' = EXPR_REG_START'; # EXPR_REG_START == 1
86 foreach $reg ( sort(keys(%regs)) ) {
87 print " R_\U${reg}\E${attach},\n";
91 print " REG_ENUM_LIMIT,\n";
92 # Unfortunately the code uses both 0 and -1 as "no register" in
94 print " R_zero = 0,\n";
97 printf "#define EXPR_REG_END %d\n", $expr_regs-1;
98 foreach $reg ( sort(keys(%regs)) ) {
99 printf "#define %-15s %2d\n", "REG_NUM_\U${reg}", $regvals{$reg};
102 } elsif ( $fmt eq 'c' ) {
104 print "/* automatically generated from $file - do not edit */\n\n";
105 print "#include \"compiler.h\"\n\n";
106 print "static const char * const reg_names[] = "; $ch = '{';
107 # This one has no dummy entry for 0
108 foreach $reg ( sort(keys(%regs)) ) {
109 print "$ch\n \"${reg}\"";
113 } elsif ( $fmt eq 'fc' ) {
115 print "/* automatically generated from $file - do not edit */\n";
116 print "static const int32_t reg_flags[] = {\n";
117 print " 0"; # Dummy entry for 0
118 foreach $reg ( sort(keys(%regs)) ) {
119 print ",\n ", $regs{$reg}; # Print the class of the register
122 } elsif ( $fmt eq 'vc' ) {
124 print "/* automatically generated from $file - do not edit */\n";
125 print "static const int regvals[] = {\n";
126 print " -1"; # Dummy entry for 0
127 foreach $reg ( sort(keys(%regs)) ) {
128 printf ",\n %2d", $regvals{$reg}; # Print the regval of the register
131 } elsif ( $fmt eq 'dc' ) {
133 print "/* automatically generated from $file - do not edit */\n";
134 foreach $class ( sort(keys(%disclass)) ) {
135 printf "static const enum reg_enum rd_%-8s[] = {", $class;
136 @foo = @
{$disclass{$class}};
138 for ( $i = 0 ; $i < scalar(@foo) ; $i++ ) {
139 if (defined($foo[$i])) {
140 push(@bar, "R_\U$foo[$i]\E");
142 die "$0: No register name for class $class, value $i\n";
145 print join(',', @bar), "};\n";
148 die "$0: Unknown output format\n";