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 my $arch_define = $arch;
41 if ($arch =~ "__i386__") {
42 $arch_define = "TARGET_X86";
44 if ($arch =~ " __x86_64__") {
45 $arch_define = "TARGET_AMD64";
47 if ($arch =~ "__arm__") {
48 $arch_define = "TARGET_ARM";
51 $cpp .= " -D$arch_define $srcdir/mini-ops.h|";
52 #print "Running: $cpp\n";
53 open (OPS
, $cpp) || die "Cannot execute cpp: $!";
55 next unless /MINI_OP3?\s*\(\s*(\S+?)\s*,\s*"(.*?)"/;
56 my ($sym, $name) = ($1, $2);
57 push @opcodes, [$sym, $name];
58 $table{$name} = {num
=> $i, name
=> $name};
69 open (DESC
, $name) || die "Cannot open $name: $!";
77 my @values = split (/\s+/);
78 next unless ($values [0] =~ /(\S+?):/);
80 my $desc = $table {$name};
82 die "Invalid opcode $name at line $line\n" unless defined $desc;
83 die "Duplicated opcode $name at line $line\n" if $desc->{"desc"};
85 $desc->{"comment"} = $comment;
88 #print "values for $name: " . join (' ', @values) . " num: " . int(@values), "\n";
89 for my $val (@values) {
90 if ($val =~ /(\S+):(.*)/) {
91 $desc->{"spec"}->{$1} = $2;
102 foreach (@spec_names) {
103 my $val = $spec->{$_};
110 #print "vals: " . join (' ', @vals) . "\n";
112 for (my $i = 0; $i < @vals; ++$i) {
113 if (defined $vals [$i]) {
114 if ($i == INST_LEN
) {
115 $res .= sprintf ("\\x%x\" \"", +$vals [$i]);
117 if ($vals [$i] =~ /^[a-zA-Z0-9]$/) {
120 $res .= sprintf ("\\x%x\" \"", $vals [$i]);
131 my ($fname, $name) = @_;
134 my $idx_array = "const guint16 ${name}_idx [] = {\n";
136 open (OUT
, ">$fname") || die "Cannot open file $fname: $!";
137 print OUT
"/* File automatically generated by genmdesc, don't change */\n\n";
138 print OUT
"const char $name [] = {\n";
139 print OUT
"\t\"" . ("\\x0" x INST_MAX
) . "\"\t/* null entry */\n";
142 for ($i = 0; $i < @opcodes; ++$i) {
143 my $name = $opcodes [$i]->[1];
144 my $desc = $table {$name};
145 my $spec = $desc->{"spec"};
148 print OUT build_spec
($spec);
149 print OUT
"\"\t/* $name */\n";
150 my $pos = $idx * INST_MAX
;
151 $idx_array .= "\t$pos,\t/* $name */\n";
154 $idx_array .= "\t0,\t/* $name */\n";
158 print OUT
"$idx_array};\n\n";
163 die "genmdesc.pl arch srcdir output name desc [desc2 ...]\n";
166 my $arch = shift || usage
();
167 my $srcdir = shift || usage
();
168 my $output = shift || usage
();
169 my $name = shift || usage
();
170 usage
() unless @ARGV;
173 load_opcodes
($srcdir, $arch);
174 foreach my $file (@files) {
177 build_table
($output, $name);