Merging r261306:
[oota-llvm.git] / utils / codegen-diff
index 35a6c0040308606ee3c372292e00c4913042728b..2c3ac4c6dfa8352e1109a2743edfb7e25f084359 100755 (executable)
@@ -1,9 +1,13 @@
 #!/usr/bin/perl
 
+use Getopt::Std;
+$DEBUG = 0;
+
 sub parse_objdump_file {
   my ($filename) = @_;
   my @result;
   open (INPUT, $filename) or die "$filename: $!\n";
+  print "opened objdump output file $filename\n" if $DEBUG;
   while (<INPUT>) {
     if (/\s*([0-9a-f]*):\t(([0-9a-f]{2} )+) *\t(.*)$/) {
       my ($addr, $bytes, $instr) = ($1, $2, $4);
@@ -11,6 +15,7 @@ sub parse_objdump_file {
       $bytes =~ s/\s*(.*\S)\s*/$1/; # trim any remaining whitespace
       $instr =~ s/\s*(.*\S)\s*/$1/;
       push (@result, {'addr' => $addr, 'bytes' => $bytes, 'instr' => $instr});
+      print "addr=$addr bytes='$bytes' instr='$instr'\n" if $DEBUG;
     }
   }
   close INPUT;
@@ -22,6 +27,7 @@ sub parse_gdb_file {
   my @result;
   my $got_addr;
   open (INPUT, $filename) or die "$filename: $!\n";
+  print "opened gdb output file $filename\n" if $DEBUG;
   while (<INPUT>) {
     if (/^(0x[0-9a-f]*):\t([^\t]*)\t[^:]*:\t((0x[0-9a-f]{2}\s*)+)\s*$/) {
       my ($addr, $bytes, $instr) = ($1, $3, $2);
@@ -30,6 +36,7 @@ sub parse_gdb_file {
       $bytes =~ s/\s*(.*\S)\s*/$1/;  # trim any remaining whitespace
       $instr =~ s/\s*(.*\S)\s*/$1/;
       push (@result, {'addr' => $addr, 'bytes' => $bytes, 'instr' => $instr});
+      print "addr=$addr bytes='$bytes' instr='$instr'\n" if $DEBUG;
     } elsif (/^(0x[0-9a-f]*):\t$/) { # deal with gdb's line breaker
       $got_addr = $1;
     } elsif ($got_addr && /^    ([^\t]*)\t[^:]*:\t((0x[0-9a-f]{2}\s*)+)\s*$/) {
@@ -39,6 +46,7 @@ sub parse_gdb_file {
       $bytes =~ s/\s*(.*\S)\s*/$1/;  # trim any remaining whitespace
       $instr =~ s/\s*(.*\S)\s*/$1/;
       push (@result, {'addr' => $addr, 'bytes' => $bytes, 'instr' => $instr});
+      print "addr=$addr bytes='$bytes' instr='$instr'\n" if $DEBUG;
       undef $got_addr;
     }
   }
@@ -55,12 +63,14 @@ sub binary_diffs {
     my $d1 = $file1[$i];
     my $d2 = $file2[$i];
     if ($d1->{'bytes'} ne $d2->{'bytes'}) {
+      next if (($d1->{'instr'} eq $d2->{'instr'}) && $opt_d);
       printf "0x%08x:\t%30s \t%s\n", 0+$d1->{'addr'}, $d1->{'bytes'}, $d1->{'instr'};
       printf "0x%08x:\t%30s \t%s\n\n", 0+$d2->{'addr'}, $d2->{'bytes'}, $d2->{'instr'};
     }
   }
 }
 
+&getopts('d');
 $objdump_file = $ARGV[0];
 $gdb_file = $ARGV[1];
 binary_diffs ($objdump_file, $gdb_file);
@@ -74,7 +84,7 @@ codegen-diff
 
 =head1 SYNOPSIS
 
-codegen-diff I<OBJDUMP-OUTPUT-FILE> I<GDB-DISASSEMBLY-FILE>
+codegen-diff [-d] I<OBJDUMP-OUTPUT-FILE> I<GDB-DISASSEMBLY-FILE>
 
 =head1 DESCRIPTION
 
@@ -97,6 +107,19 @@ Finally, you run B<codegen-diff>, as indicated in the Synopsis section of
 this manpage. It will print out a two-line stanza for each mismatched
 instruction, with the  B<llc> version first, and the  B<lli> version second.
 
+=head1 OPTIONS
+
+=over 4
+
+=item -d
+
+Don't show instructions where the bytes are different but they
+disassemble to the same thing. This puts a lot of trust in the
+disassembler, but it might help you highlight the more egregious cases
+of misassembly.
+
+=back
+
 =head1 AUTHOR
 
 B<codegen-diff> was written by Brian Gaeke.