# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Nathan Binkert
+# Steve Reinhardt
# Diff two streams.
#
# "filename" is a pipe (|). Thus to compare the instruction traces
# from two versions of m5 (m5a and m5b), you can do this:
#
-# rundiff 'm5a --trace:flags=InstExec |' 'm5b --trace:flags=InstExec |'
+# rundiff 'm5a --traceflags=InstExec |' 'm5b --traceflags=InstExec |'
#
use strict;
-
+use FileHandle;
use Getopt::Std;
#
open($fh1, $file1) or die "Can't open $file1";
open($fh2, $file2) or die "Can't open $file2";
+# print files to output so we know which is which
+print "-$file1\n";
+print "+$file2\n";
+
# buffer of matching lines for pre-diff context
my @precontext = ();
# number of post-diff matching lines remaining to print
# Set $postcontext to print the next $postcontext_lines matching lines.
$postcontext = $postcontext_lines;
+
+ # Normally we flush after the postcontext lines are printed, but if
+ # the user has decreed that there aren't any we need to flush now
+ if ($postcontext == 0) {
+ STDOUT->flush();
+ }
}
DISCARD_A => \&discard1,
DISCARD_B => \&discard2 });
- die "Lost sync!" if (!$match_found);
+ if (!$match_found) {
+ printdiff(scalar(@lines1), scalar(@lines2));
+ die "Lost sync!";
+ }
# Since we shouldn't get here unless the first lines of the
# buffers are different, then we must discard some lines off
# treated as common; if that bugs you, use Algorithm::Diff.
if ($lines1[$n1] eq $lines2[$n2] && $lines1[$n1+1] eq $lines2[$n2+1]) {
printdiff($n1, $n2);
+ return 1;
}
+
+ return 0;
}
sub simple_diff
return if checkmatch($cnt, $n);
}
}
+
+ printdiff(scalar(@lines1), scalar(@lines2));
die "Lost sync!";
}
# figure out what to do with this line
if ($postcontext > 0) {
# we're in the post-context of a diff: print it
- $postcontext--;
print ' ', $l1;
$lineno1++;
$lineno2++;
+ if (--$postcontext == 0) {
+ STDOUT->flush();
+ }
}
else {
# we're in the middle of a matching region... save this