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\n", $expr_regs;
84 print "enum reg_enum {\n";
85 # Unfortunately the code uses both 0 and -1 as "no register" in
87 print " R_zero = 0,\n";
88 print " R_none = -1,\n";
89 $attach = ' = EXPR_REG_START'; # EXPR_REG_START == 1
90 foreach $reg ( sort(keys(%regs)) ) {
91 print " R_\U${reg}\E${attach},\n";
95 print " REG_ENUM_LIMIT\n";
97 printf "#define EXPR_REG_END %d\n\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 \"tables.h\"\n\n";
106 print "const char * const nasm_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\n";
116 print "#include \"tables.h\"\n";
117 print "#include \"nasm.h\"\n\n";
118 print "const int32_t nasm_reg_flags[] = {\n";
119 printf " 0,\n"; # Dummy entry for 0
120 foreach $reg ( sort(keys(%regs)) ) {
121 # Print the class of the register
122 printf " %-15s /* %-5s */\n",
123 $regs{$reg}.',', $reg;
126 } elsif ( $fmt eq 'vc' ) {
128 print "/* automatically generated from $file - do not edit */\n\n";
129 print "#include \"tables.h\"\n\n";
130 print "const int nasm_regvals[] = {\n";
131 print " -1,\n"; # Dummy entry for 0
132 foreach $reg ( sort(keys(%regs)) ) {
133 # Print the x86 value of the register
134 printf " %2d, /* %-5s */\n", $regvals{$reg}, $reg;
137 } elsif ( $fmt eq 'dc' ) {
139 print "/* automatically generated from $file - do not edit */\n\n";
140 print "#include \"regs.h\"\n";
141 print "#include \"regdis.h\"\n\n";
142 foreach $class ( sort(keys(%disclass)) ) {
143 printf "const enum reg_enum nasm_rd_%-8s[%2d] = {",
144 $class, scalar @{$disclass{$class}};
145 @foo = @{$disclass{$class}};
147 for ( $i = 0 ; $i < scalar(@foo) ; $i++ ) {
148 if (defined($foo[$i])) {
149 push(@bar, "R_\U$foo[$i]\E");
151 die "$0: No register name for class $class, value $i\n";
154 print join(',', @bar), "};\n";
156 } elsif ( $fmt eq 'dh' ) {
158 print "/* automatically generated from $file - do not edit */\n";
159 foreach $class ( sort(keys(%disclass)) ) {
160 printf "extern const enum reg_enum nasm_rd_%-8s[%2d];\n",
161 $class, scalar @{$disclass{$class}};
164 die "$0: Unknown output format\n";