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]+)\s*(\S*)/i ) {
52 die "regs.dat:$nline: invalid input\n";
57 $x86regno = toint
($4);
59 if ($reg =~ /^(.*[^0-9])([0-9]+)\-([0-9]+)(|[^0-9].*)$/) {
72 $regs{$reg} = $aclass;
73 $regvals{$reg} = $x86regno;
75 foreach $dclass (split(/,/, $dclasses)) {
76 if ( !defined($disclass{$dclass}) ) {
77 $disclass{$dclass} = [];
80 $disclass{$dclass}->[$x86regno] = $reg;
83 # Compute the next register, if any
84 if (defined($reg_prefix)) {
87 $reg = sprintf("%s%u%s", $reg_prefix, $reg_nr, $reg_suffix);
89 # Not a dashed sequence
95 ($fmt, $file) = @ARGV;
100 open(REGS
, '<', $file) or die "$0: Cannot open $file\n";
101 while ( defined($line = <REGS
>) ) {
105 $line =~ s/\s*(\#.*|)$//;
107 next if ( $line eq '' );
115 print "/* automatically generated from $file - do not edit */\n\n";
116 print "#ifndef NASM_REGS_H\n";
117 print "#define NASM_REGS_H\n\n";
120 printf "#define EXPR_REG_START %d\n\n", $expr_regs;
121 print "enum reg_enum {\n";
122 # Unfortunately the code uses both 0 and -1 as "no register" in
123 # different places...
124 print " R_zero = 0,\n";
125 print " R_none = -1,\n";
126 $attach = ' = EXPR_REG_START'; # EXPR_REG_START == 1
127 foreach $reg ( sort(keys(%regs)) ) {
128 print " R_\U${reg}\E${attach},\n";
132 print " REG_ENUM_LIMIT\n";
134 printf "#define EXPR_REG_END %d\n\n", $expr_regs-1;
135 foreach $reg ( sort(keys(%regs)) ) {
136 printf "#define %-15s %2d\n", "REG_NUM_\U${reg}", $regvals{$reg};
138 print "\n\n#endif /* NASM_REGS_H */\n";
139 } elsif ( $fmt eq 'c' ) {
141 print "/* automatically generated from $file - do not edit */\n\n";
142 print "#include \"tables.h\"\n\n";
143 print "const char * const nasm_reg_names[] = "; $ch = '{';
144 # This one has no dummy entry for 0
145 foreach $reg ( sort(keys(%regs)) ) {
146 print "$ch\n \"${reg}\"";
150 } elsif ( $fmt eq 'fc' ) {
152 print "/* automatically generated from $file - do not edit */\n\n";
153 print "#include \"tables.h\"\n";
154 print "#include \"nasm.h\"\n\n";
155 print "const opflags_t nasm_reg_flags[] = {\n";
156 printf " 0,\n"; # Dummy entry for 0
157 foreach $reg ( sort(keys(%regs)) ) {
158 # Print the class of the register
159 printf " %-15s /* %-5s */\n",
160 $regs{$reg}.',', $reg;
163 } elsif ( $fmt eq 'vc' ) {
165 print "/* automatically generated from $file - do not edit */\n\n";
166 print "#include \"tables.h\"\n\n";
167 print "const int nasm_regvals[] = {\n";
168 print " -1,\n"; # Dummy entry for 0
169 foreach $reg ( sort(keys(%regs)) ) {
170 # Print the x86 value of the register
171 printf " %2d, /* %-5s */\n", $regvals{$reg}, $reg;
174 } elsif ( $fmt eq 'dc' ) {
176 print "/* automatically generated from $file - do not edit */\n\n";
177 print "#include \"regdis.h\"\n\n";
178 foreach $class ( sort(keys(%disclass)) ) {
179 printf "const enum reg_enum nasm_rd_%-8s[%2d] = {",
180 $class, scalar @
{$disclass{$class}};
181 @foo = @
{$disclass{$class}};
183 for ( $i = 0 ; $i < scalar(@foo) ; $i++ ) {
184 if (defined($foo[$i])) {
185 push(@bar, "R_\U$foo[$i]\E");
187 die "$0: No register name for class $class, value $i\n";
190 print join(',', @bar), "};\n";
192 } elsif ( $fmt eq 'dh' ) {
194 print "/* automatically generated from $file - do not edit */\n\n";
195 print "#ifndef NASM_REGDIS_H\n";
196 print "#define NASM_REGDIS_H\n\n";
197 print "#include \"regs.h\"\n\n";
198 foreach $class ( sort(keys(%disclass)) ) {
199 printf "extern const enum reg_enum nasm_rd_%-8s[%2d];\n",
200 $class, scalar @
{$disclass{$class}};
202 print "\n#endif /* NASM_REGDIS_H */\n";
204 die "$0: Unknown output format\n";