Revert "Merge branch 'master' of https://github.com/mono/mono"
[mono.git] / mono / mini / genmdesc.pl
index 2444d9be18c263e0904e1ab2b7260d196a3c7731..8c13a6171dd947081cc78d7eb28b58ab8a8618b3 100644 (file)
@@ -13,6 +13,8 @@ sub INST_SRC2  () {return 2;}
 sub INST_SRC3  () {return 3;}
 sub INST_LEN   () {return 4;}
 sub INST_CLOB  () {return 5;}
+# making INST_NACL the same as INST_MAX is not a mistake,
+# INST_NACL writes over INST_LEN, it's not its own field
 sub INST_NACL  () {return 6;}
 sub INST_MAX   () {return 6;}
 
@@ -23,6 +25,8 @@ my %table =();
 my %template_table =();
 my @opcodes = ();
 
+my $nacl = 0;
+
 sub parse_file
 {
        my ($define, $file) = @_;
@@ -75,7 +79,7 @@ sub load_opcodes
        if ($arch =~ "__i386__") {
                $arch_define = "TARGET_X86";
        }
-       if ($arch =~ " __x86_64__") {
+       if ($arch =~ "__x86_64__") {
                $arch_define = "TARGET_AMD64";
        }
        if ($arch =~ "__arm__") {
@@ -167,21 +171,22 @@ sub build_spec {
        my $res = "";
        my $n = 0;
        for (my $i = 0; $i < @vals; ++$i) {
+               next if $i == INST_NACL;
                if (defined $vals [$i]) {
                        if ($i == INST_LEN) {
                                $n = $vals [$i];
-                               if (defined $vals [INST_NACL]){
-                                   $n += $vals [INST_NACL];
+                               if ((defined $vals [INST_NACL]) and $nacl == 1){
+                                   $n = $vals [INST_NACL];
                                }
                                $res .= sprintf ("\\x%x\" \"", + $n);
-                       } elsif ($i != INST_NACL) {
+                       } else {
                                if ($vals [$i] =~ /^[a-zA-Z0-9]$/) {
                                        $res .= $vals [$i];
                                } else {
                                        $res .= sprintf ("\\x%x\" \"", $vals [$i]);
                                }
                        }
-               } elsif ($i != INST_NACL) {
+               } else {
                        $res .= "\\x0\" \"";
                }
        }
@@ -221,12 +226,17 @@ sub build_table {
 }
 
 sub usage {
-       die "genmdesc.pl arch srcdir output name desc [desc2 ...]\n";
+       die "genmdesc.pl arch srcdir [--nacl] output name desc [desc2 ...]\n";
 }
 
 my $arch = shift || usage ();
 my $srcdir = shift || usage ();
 my $output = shift || usage ();
+if ($output eq "--nacl")
+{
+  $nacl = 1;  
+  $output = shift || usage();
+}
 my $name = shift || usage ();
 usage () unless @ARGV;
 my @files = @ARGV;