4 # Read regs.dat and output regs.h and regs.c (included in names.c)
13 if ( $line !~ /^\s*(\S+)\s*(\S+)\s*(\S+)\s*([0-9]+)\s*$/ ) {
14 die "regs.dat:$nline: invalid input\n";
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;
36 open(REGS
, "< ${file}") or die "$0: Cannot open $file\n";
37 while ( defined($line = <REGS
>) ) {
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;
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";
67 foreach $reg ( sort(keys(%regs)) ) {
68 print "#define REG_NUM_\U${reg} $regvals{$reg}\n";
71 } elsif ( $fmt eq 'c' ) {
73 print "/* automatically generated from $file - do not edit */\n";
74 print "static const int8_t *reg_names[] = "; $ch = '{';
75 # This one has no dummy entry for 0
76 foreach $reg ( sort(keys(%regs)) ) {
77 print "$ch\n \"${reg}\"";
81 } elsif ( $fmt eq 'fc' ) {
83 print "/* automatically generated from $file - do not edit */\n";
84 print "static const int32_t reg_flags[] = {\n";
85 print " 0"; # Dummy entry for 0
86 foreach $reg ( sort(keys(%regs)) ) {
87 print ",\n ", $regs{$reg}; # Print the class of the register
90 } elsif ( $fmt eq 'vc' ) {
92 print "/* automatically generated from $file - do not edit */\n";
93 print "static const int regvals[] = {\n";
94 print " -1"; # Dummy entry for 0
95 foreach $reg ( sort(keys(%regs)) ) {
96 print ",\n ", $regvals{$reg}; # Print the regval of the register
99 } elsif ( $fmt eq 'dc' ) {
101 print "/* automatically generated from $file - do not edit */\n";
102 foreach $class ( sort(keys(%disclass)) ) {
103 printf "static const int %-8s[] = {", $class;
104 @foo = @
{$disclass{$class}};
105 for ( $i = 0 ; $i < scalar(@foo) ; $i++ ) {
106 $foo[$i] = defined($foo[$i]) ?
"R_\U$foo[$i]\E" : '0';
108 print join(',', @foo), "};\n";
111 die "$0: Unknown output format\n";