3 # Read regs.dat and output regs.h and regs.c (included in names.c)
13 return ($v =~ /^0/) ?
oct $v : $v+0;
20 if ( $line !~ /^\s*(\S+)\s*(\S+)\s*(\S+)\s*([0-9]+)$/i ) {
21 die "regs.dat:$nline: invalid input\n";
26 $x86regno = toint
($4);
28 if ($reg =~ /^(.*[^0-9])([0-9]+)\-([0-9]+)(|[^0-9].*)$/) {
36 undef $reg_prefix, $reg_suffix;
40 $regs{$reg} = $aclass;
41 $regvals{$reg} = $x86regno;
43 foreach $dclass (split(/,/, $dclasses)) {
44 if ( !defined($disclass{$dclass}) ) {
45 $disclass{$dclass} = [];
48 $disclass{$dclass}->[$x86regno] = $reg;
49 push @
{$drclass{$reg}}, $dclass;
52 # Compute the next register, if any
53 if (defined($reg_prefix)) {
56 $reg = sprintf("%s%u%s", $reg_prefix, $reg_nr, $reg_suffix);
58 # Not a dashed sequence
64 ($fmt, $file) = @ARGV;
69 open(REGS
, "< ${file}") or die "$0: Cannot open $file\n";
70 while ( defined($line = <REGS
>) ) {
74 $line =~ s/\s*(\#.*|)$//;
76 next if ( $line eq '' );
84 print "/* automatically generated from $file - do not edit */\n\n";
85 print "#ifndef NASM_REGS_H\n";
86 print "#define NASM_REGS_H\n\n";
89 printf "#define EXPR_REG_START %d\n\n", $expr_regs;
90 print "enum reg_enum {\n";
91 # Unfortunately the code uses both 0 and -1 as "no register" in
93 print " R_zero = 0,\n";
94 print " R_none = -1,\n";
95 $attach = ' = EXPR_REG_START'; # EXPR_REG_START == 1
96 foreach $reg ( sort(keys(%regs)) ) {
97 print " R_\U${reg}\E${attach},\n";
101 print " REG_ENUM_LIMIT\n";
103 printf "#define EXPR_REG_END %d\n\n", $expr_regs-1;
104 foreach $reg ( sort(keys(%regs)) ) {
105 printf "#define %-15s %2d\n", "REG_NUM_\U${reg}", $regvals{$reg};
107 print "\n\n#endif /* NASM_REGS_H */\n";
108 } elsif ( $fmt eq 'c' ) {
110 print "/* automatically generated from $file - do not edit */\n\n";
111 print "#include \"tables.h\"\n\n";
112 print "const char * const nasm_reg_names[] = "; $ch = '{';
113 # This one has no dummy entry for 0
114 foreach $reg ( sort(keys(%regs)) ) {
115 print "$ch\n \"${reg}\"";
119 } elsif ( $fmt eq 'fc' ) {
121 print "/* automatically generated from $file - do not edit */\n\n";
122 print "#include \"tables.h\"\n";
123 print "#include \"nasm.h\"\n\n";
124 print "const int32_t nasm_reg_flags[] = {\n";
125 printf " 0,\n"; # Dummy entry for 0
126 foreach $reg ( sort(keys(%regs)) ) {
127 # Print the class of the register
128 printf " %-15s /* %-5s */\n",
129 $regs{$reg}.',', $reg;
132 } elsif ( $fmt eq 'vc' ) {
134 print "/* automatically generated from $file - do not edit */\n\n";
135 print "#include \"tables.h\"\n\n";
136 print "const int nasm_regvals[] = {\n";
137 print " -1,\n"; # Dummy entry for 0
138 foreach $reg ( sort(keys(%regs)) ) {
139 # Print the x86 value of the register
140 printf " %2d, /* %-5s */\n", $regvals{$reg}, $reg;
143 } elsif ( $fmt eq 'dc' ) {
145 print "/* automatically generated from $file - do not edit */\n\n";
146 print "#include \"regdis.h\"\n\n";
147 foreach $class ( sort(keys(%disclass)) ) {
148 printf "const enum reg_enum nasm_rd_%-8s[%2d] = {",
149 $class, scalar @
{$disclass{$class}};
150 @foo = @
{$disclass{$class}};
152 for ( $i = 0 ; $i < scalar(@foo) ; $i++ ) {
153 if (defined($foo[$i])) {
154 push(@bar, "R_\U$foo[$i]\E");
156 die "$0: No register name for class $class, value $i\n";
159 print join(',', @bar), "};\n";
161 } elsif ( $fmt eq 'dh' ) {
163 print "/* automatically generated from $file - do not edit */\n\n";
164 print "#ifndef NASM_REGDIS_H\n";
165 print "#define NASM_REGDIS_H\n\n";
166 print "#include \"regs.h\"\n\n";
167 foreach $class ( sort(keys(%disclass)) ) {
168 printf "extern const enum reg_enum nasm_rd_%-8s[%2d];\n",
169 $class, scalar @
{$disclass{$class}};
171 print "\n#endif /* NASM_REGDIS_H */\n";
172 } elsif ( $fmt eq 'yaml' ) {
175 my @names = sort keys %regs;
179 for my $name (@names){
181 AssemblerClass
=> $regs{$name},
182 DisassemblerClasses
=> $drclass{$name},
183 x86RegisterNumber
=> $regvals{$name},
188 print YAML
::XS
::Dump
(\
%data), "\n";
189 } elsif ( $fmt eq 'order' ) {
191 say for sort keys %regs;
193 die "$0: Unknown output format\n";