Update dependencies
[nasm/avx512.git] / regs.pl
bloba4fe9aa1ab9d00af1f1ee938caa9369f3a555c9d
1 #!/usr/bin/perl
2 # $Id$
4 # Read regs.dat and output regs.h and regs.c (included in names.c)
7 $nline = 0;
9 sub process_line($) {
10 my($line) = @_;
11 my @v;
13 if ( $line !~ /^\s*(\S+)\s*(\S+)\s*(\S+)\s*([0-7])\s*$/ ) {
14 die "regs.dat:$nline: invalid input\n";
16 $reg = $1;
17 $aclass = $2;
18 $dclass = $3;
19 $regval = $4;
21 $regs{$reg} = $aclass;
22 $regvals{$reg} = $regval;
24 if ( !defined($disclass{$dclass}) ) {
25 $disclass{$dclass} = [(undef) x 8];
28 $disclass{$dclass}->[$regval] = $reg;
31 ($fmt, $file) = @ARGV;
33 %regs = ();
34 %regvals = ();
35 %disclass = ();
36 open(REGS, "< ${file}") or die "$0: Cannot open $file\n";
37 while ( defined($line = <REGS>) ) {
38 $nline++;
40 chomp $line;
41 $line =~ s/\s*(\#.*|)$//;
43 next if ( $line eq '' );
45 if ( $line =~ /\*/ ) {
46 for ( $i = 0 ; $i < 8 ; $i++ ) {
47 ($xline = $line) =~ s/\*/$i/g;
48 process_line($xline);
50 } else {
51 process_line($line);
54 close(REGS);
56 if ( $fmt eq 'h' ) {
57 # Output regs.h
58 print "/* automatically generated from $file - do not edit */\n";
59 print "enum reg_enum {\n";
60 $attach = ' = EXPR_REG_START'; # EXPR_REG_START == 1
61 foreach $reg ( sort(keys(%regs)) ) {
62 print " R_\U${reg}\E${attach},\n";
63 $attach = ''; $ch = ',';
65 print " REG_ENUM_LIMIT\n";
66 print "};\n";
67 } elsif ( $fmt eq 'c' ) {
68 # Output regs.c
69 print "/* automatically generated from $file - do not edit */\n";
70 print "static const char *reg_names[] = "; $ch = '{';
71 # This one has no dummy entry for 0
72 foreach $reg ( sort(keys(%regs)) ) {
73 print "$ch\n \"${reg}\"";
74 $ch = ',';
76 print "\n};\n";
77 } elsif ( $fmt eq 'fc' ) {
78 # Output regflags.c
79 print "/* automatically generated from $file - do not edit */\n";
80 print "static const long reg_flags[] = {\n";
81 print " 0"; # Dummy entry for 0
82 foreach $reg ( sort(keys(%regs)) ) {
83 print ",\n ", $regs{$reg}; # Print the class of the register
85 print "\n};\n";
86 } elsif ( $fmt eq 'vc' ) {
87 # Output regvals.c
88 print "/* automatically generated from $file - do not edit */\n";
89 print "static const int regvals[] = {\n";
90 print " -1"; # Dummy entry for 0
91 foreach $reg ( sort(keys(%regs)) ) {
92 print ",\n ", $regvals{$reg}; # Print the regval of the register
94 print "\n};\n";
95 } elsif ( $fmt eq 'dc' ) {
96 # Output regdis.c
97 print "/* automatically generated from $file - do not edit */\n";
98 foreach $class ( sort(keys(%disclass)) ) {
99 printf "static const int %-8s[] = {", $class;
100 @foo = @{$disclass{$class}};
101 for ( $i = 0 ; $i < scalar(@foo) ; $i++ ) {
102 $foo[$i] = defined($foo[$i]) ? "R_\U$foo[$i]\E" : '0';
104 print join(',', @foo), "};\n";
106 } else {
107 die "$0: Unknown output format\n";