2 ## --------------------------------------------------------------------------
4 ## Copyright 1996-2009 The NASM Authors - All Rights Reserved
5 ## See the file AUTHORS included with the NASM distribution for
6 ## the specific copyright holders.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted provided that the following
10 ## conditions are met:
12 ## * Redistributions of source code must retain the above copyright
13 ## notice, this list of conditions and the following disclaimer.
14 ## * Redistributions in binary form must reproduce the above
15 ## copyright notice, this list of conditions and the following
16 ## disclaimer in the documentation and/or other materials provided
17 ## with the distribution.
19 ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
20 ## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21 ## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 ## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 ## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 ## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ## --------------------------------------------------------------------------
36 # Read regs.dat and output regs.h and regs.c (included in names.c)
44 return ($v =~ /^0/) ? oct $v : $v+0;
51 if ( $line !~ /^\s*(\S+)\s*(\S+)\s*(\S+)\s*([0-9]+)$/i ) {
52 die "regs.dat:$nline: invalid input\n";
57 $x86regno = toint($4);
59 if ($reg =~ /^(.*[^0-9])([0-9]+)\-([0-9]+)(|[^0-9].*)$/) {
67 undef $reg_prefix, $reg_suffix;
71 $regs{$reg} = $aclass;
72 $regvals{$reg} = $x86regno;
74 foreach $dclass (split(/,/, $dclasses)) {
75 if ( !defined($disclass{$dclass}) ) {
76 $disclass{$dclass} = [];
79 $disclass{$dclass}->[$x86regno] = $reg;
82 # Compute the next register, if any
83 if (defined($reg_prefix)) {
86 $reg = sprintf("%s%u%s", $reg_prefix, $reg_nr, $reg_suffix);
88 # Not a dashed sequence
94 ($fmt, $file) = @ARGV;
99 open(REGS, "< ${file}") or die "$0: Cannot open $file\n";
100 while ( defined($line = <REGS>) ) {
104 $line =~ s/\s*(\#.*|)$//;
106 next if ( $line eq '' );
114 print "/* automatically generated from $file - do not edit */\n\n";
115 print "#ifndef NASM_REGS_H\n";
116 print "#define NASM_REGS_H\n\n";
119 printf "#define EXPR_REG_START %d\n\n", $expr_regs;
120 print "enum reg_enum {\n";
121 # Unfortunately the code uses both 0 and -1 as "no register" in
122 # different places...
123 print " R_zero = 0,\n";
124 print " R_none = -1,\n";
125 $attach = ' = EXPR_REG_START'; # EXPR_REG_START == 1
126 foreach $reg ( sort(keys(%regs)) ) {
127 print " R_\U${reg}\E${attach},\n";
131 print " REG_ENUM_LIMIT\n";
133 printf "#define EXPR_REG_END %d\n\n", $expr_regs-1;
134 foreach $reg ( sort(keys(%regs)) ) {
135 printf "#define %-15s %2d\n", "REG_NUM_\U${reg}", $regvals{$reg};
137 print "\n\n#endif /* NASM_REGS_H */\n";
138 } elsif ( $fmt eq 'c' ) {
140 print "/* automatically generated from $file - do not edit */\n\n";
141 print "#include \"tables.h\"\n\n";
142 print "const char * const nasm_reg_names[] = "; $ch = '{';
143 # This one has no dummy entry for 0
144 foreach $reg ( sort(keys(%regs)) ) {
145 print "$ch\n \"${reg}\"";
149 } elsif ( $fmt eq 'fc' ) {
151 print "/* automatically generated from $file - do not edit */\n\n";
152 print "#include \"tables.h\"\n";
153 print "#include \"nasm.h\"\n\n";
154 print "const int32_t nasm_reg_flags[] = {\n";
155 printf " 0,\n"; # Dummy entry for 0
156 foreach $reg ( sort(keys(%regs)) ) {
157 # Print the class of the register
158 printf " %-15s /* %-5s */\n",
159 $regs{$reg}.',', $reg;
162 } elsif ( $fmt eq 'vc' ) {
164 print "/* automatically generated from $file - do not edit */\n\n";
165 print "#include \"tables.h\"\n\n";
166 print "const int nasm_regvals[] = {\n";
167 print " -1,\n"; # Dummy entry for 0
168 foreach $reg ( sort(keys(%regs)) ) {
169 # Print the x86 value of the register
170 printf " %2d, /* %-5s */\n", $regvals{$reg}, $reg;
173 } elsif ( $fmt eq 'dc' ) {
175 print "/* automatically generated from $file - do not edit */\n\n";
176 print "#include \"regdis.h\"\n\n";
177 foreach $class ( sort(keys(%disclass)) ) {
178 printf "const enum reg_enum nasm_rd_%-8s[%2d] = {",
179 $class, scalar @{$disclass{$class}};
180 @foo = @{$disclass{$class}};
182 for ( $i = 0 ; $i < scalar(@foo) ; $i++ ) {
183 if (defined($foo[$i])) {
184 push(@bar, "R_\U$foo[$i]\E");
186 die "$0: No register name for class $class, value $i\n";
189 print join(',', @bar), "};\n";
191 } elsif ( $fmt eq 'dh' ) {
193 print "/* automatically generated from $file - do not edit */\n\n";
194 print "#ifndef NASM_REGDIS_H\n";
195 print "#define NASM_REGDIS_H\n\n";
196 print "#include \"regs.h\"\n\n";
197 foreach $class ( sort(keys(%disclass)) ) {
198 printf "extern const enum reg_enum nasm_rd_%-8s[%2d];\n",
199 $class, scalar @{$disclass{$class}};
201 print "\n#endif /* NASM_REGDIS_H */\n";
203 die "$0: Unknown output format\n";