3 # perl replacement of genmdesc.c for use when cross-compiling
8 # must keep in sync with mini.h
9 my @spec_names = qw(dest src1 src2 src3 len clob);
10 sub INST_DEST () {return 0;}
11 sub INST_SRC1 () {return 1;}
12 sub INST_SRC2 () {return 2;}
13 sub INST_SRC3 () {return 3;}
14 sub INST_LEN () {return 4;}
15 sub INST_CLOB () {return 5;}
16 sub INST_MAX () {return 6;}
18 # this must include all the #defines used in mini-ops.h
19 my @defines = qw (__i386__ __x86_64__ __ppc__ __powerpc__ __arm__
20 __sparc__ sparc __s390__ s390 __ia64__ __alpha__ __mips__);
26 my ($srcdir, $arch) = @_;
27 my $opcodes_def = "$srcdir/../cil/opcode.def";
31 my $cpp = $ENV{"CPP"};
32 $cpp = "cpp" unless defined $cpp;
36 $arch_found = 1 if $arch eq $_;
38 die "$arch arch is not supported.\n" unless $arch_found;
40 $cpp .= " -D$arch $srcdir/mini-ops.h|";
41 #print "Running: $cpp\n";
42 open (OPS, $cpp) || die "Cannot execute cpp: $!";
44 next unless /MINI_OP\s*\(\s*(\S+?)\s*,\s*"(.*?)"/;
45 my ($sym, $name) = ($1, $2);
46 push @opcodes, [$sym, $name];
47 $table{$name} = {num => $i, name => $name};
58 open (DESC, $name) || die "Cannot open $name: $!";
66 my @values = split (/\s+/);
67 next unless ($values [0] =~ /(\S+?):/);
69 my $desc = $table {$name};
71 die "Invalid opcode $name at line $line\n" unless defined $desc;
72 die "Duplicated opcode $name at line $line\n" if $desc->{"desc"};
74 $desc->{"comment"} = $comment;
77 #print "values for $name: " . join (' ', @values) . " num: " . int(@values), "\n";
78 for my $val (@values) {
79 if ($val =~ /(\S+):(.*)/) {
80 $desc->{"spec"}->{$1} = $2;
91 foreach (@spec_names) {
92 my $val = $spec->{$_};
99 #print "vals: " . join (' ', @vals) . "\n";
101 for (my $i = 0; $i < @vals; ++$i) {
102 if (defined $vals [$i]) {
103 if ($i == INST_LEN) {
104 $res .= sprintf ("\\x%x\" \"", +$vals [$i]);
106 if ($vals [$i] =~ /^[a-zA-Z0-9]$/) {
109 $res .= sprintf ("\\x%x\" \"", $vals [$i]);
120 my ($fname, $name) = @_;
123 my $idx_array = "const guint16 ${name}_idx [] = {\n";
125 open (OUT, ">$fname") || die "Cannot open file $fname: $!";
126 print OUT "/* File automatically generated by genmdesc, don't change */\n\n";
127 print OUT "const char $name [] = {\n";
128 print OUT "\t\"" . ("\\x0" x INST_MAX) . "\"\t/* null entry */\n";
131 for ($i = 0; $i < @opcodes; ++$i) {
132 my $name = $opcodes [$i]->[1];
133 my $desc = $table {$name};
134 my $spec = $desc->{"spec"};
137 print OUT build_spec ($spec);
138 print OUT "\"\t/* $name */\n";
139 my $pos = $idx * INST_MAX;
140 $idx_array .= "\t$pos,\t/* $name */\n";
143 $idx_array .= "\t0,\t/* $name */\n";
147 print OUT "$idx_array};\n\n";
152 die "genmdesc.pl arch srcdir desc output name\n";
155 my $arch = shift || usage ();
156 my $srcdir = shift || usage ();
157 my $file = shift || usage ();
158 my $output = shift || usage ();
159 my $name = shift || usage ();
161 load_opcodes ($srcdir, $arch);
163 build_table ($output, $name);