diff scripts/bsv-trace.pl @ 23:90197e3375e2 pygar svn.24

[svn r24] added testing, but something is wrong with our c++ file.
author rlm
date Wed, 28 Apr 2010 08:19:09 -0400
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/bsv-trace.pl	Wed Apr 28 08:19:09 2010 -0400
     1.3 @@ -0,0 +1,129 @@
     1.4 +#!/usr/bin/perl -w
     1.5 +#==========================================================================
     1.6 +# bsc-trace.pl
     1.7 +#
     1.8 +# Author : Christopher Batten (cbatten@mit.edu)
     1.9 +# Date   : April 12, 2005
    1.10 +#
    1.11 +(our $usageMsg = <<'ENDMSG') =~ s/^\#//gm;
    1.12 +#
    1.13 +# Simple script which converts bsv "one-per-line" trace output into
    1.14 +# a more compact and readable column format.
    1.15 +#
    1.16 +ENDMSG
    1.17 +
    1.18 +use strict "vars";
    1.19 +use warnings;
    1.20 +no  warnings("once");
    1.21 +use Getopt::Long;
    1.22 +use File::Basename;
    1.23 +
    1.24 +#--------------------------------------------------------------------------
    1.25 +# Command line processing
    1.26 +#--------------------------------------------------------------------------
    1.27 +
    1.28 +our %opts;
    1.29 +
    1.30 +sub usage()
    1.31 +{
    1.32 +
    1.33 +  print "\n";
    1.34 +  print " Usage: bsc-trace.pl <format-file> [trace-file]\n";
    1.35 +  print "\n";
    1.36 +  print " Options:\n";
    1.37 +  print "  --help        print this message\n";
    1.38 +  print "  <format-str>  format string\n";
    1.39 +  print "  [trace-file]  output trace from BSV simulation (default is STDIN)\n";
    1.40 +  print "$usageMsg";
    1.41 +
    1.42 +  exit();
    1.43 +}
    1.44 +
    1.45 +sub processCommandLine()
    1.46 +{
    1.47 +
    1.48 +  $opts{"help"}        = 0;
    1.49 +
    1.50 +  Getopt::Long::GetOptions( \%opts, 'help|?' ) or usage();
    1.51 +
    1.52 +  ($opts{"format"}     = shift(@ARGV)) or usage();
    1.53 +  ($opts{"trace-file"} = shift(@ARGV)) or ($opts{"trace-file"} = "-");
    1.54 +  $opts{"help"} and usage();
    1.55 +
    1.56 +}
    1.57 +
    1.58 +#--------------------------------------------------------------------------
    1.59 +# Main
    1.60 +#--------------------------------------------------------------------------
    1.61 +
    1.62 +sub main()
    1.63 +{
    1.64 +
    1.65 +  processCommandLine();
    1.66 +  require $opts{"format"};
    1.67 +
    1.68 +  my $cycle = 0;
    1.69 +  my %traceHash;
    1.70 +
    1.71 +  my $traceFile = $opts{"trace-file"};
    1.72 +  open( FIN, "<$traceFile" ) or die("Could not open BSV trace file ($traceFile)!");
    1.73 +
    1.74 +  print  "           processor-state [     icache            ]  [     dcache            ]  [    mem-arb   ]  executed-instruction\n";
    1.75 +
    1.76 +  my $labelLine = $settings::labelString;
    1.77 +  foreach my $tag ( keys %settings::headers){
    1.78 +      my $theLabel = $settings::headers{$tag};      
    1.79 +      $labelLine =~ s/{$tag}/$theLabel/;
    1.80 +  }
    1.81 +  print "            $labelLine\n";
    1.82 +  
    1.83 +  while ( my $line = <FIN> ) {
    1.84 +  
    1.85 +    if ( $line =~ /^ => Cycle =\s+(\d+)$/ ) {
    1.86 +
    1.87 +      my $tempTraceLine = $settings::traceString;
    1.88 +      foreach my $tag ( keys %settings::fields ) {
    1.89 +
    1.90 +        my $theTraceString = $traceHash{$tag};
    1.91 +        my $theEmptyString = $settings::fields{$tag};
    1.92 +
    1.93 +        # Substitute the trace field in ...
    1.94 +        if ( defined($theTraceString) ) {
    1.95 +
    1.96 +          # If the trace string is shorter than the empty string then
    1.97 +          # add some spaces at the end so things line up ...
    1.98 +          my $theTraceStringLen = length($theTraceString);
    1.99 +          my $theEmptyStringLen = length($theEmptyString);
   1.100 +          if ( $theTraceStringLen < $theEmptyStringLen ) {
   1.101 +            $theTraceString .= (" "x ($theEmptyStringLen-$theTraceStringLen));
   1.102 +          }
   1.103 +
   1.104 +          $tempTraceLine =~ s/{$tag}/$theTraceString/;
   1.105 +
   1.106 +        }
   1.107 +
   1.108 +        # Substitute the empty field in ...
   1.109 +        else {
   1.110 +          $tempTraceLine =~ s/{$tag}/$theEmptyString/;
   1.111 +        }
   1.112 +
   1.113 +      }
   1.114 +
   1.115 +      print " CYC: ".sprintf("%4d",$cycle)."  $tempTraceLine\n";
   1.116 +
   1.117 +      $cycle = $1;
   1.118 +      %traceHash = ();
   1.119 +    }
   1.120 +    elsif ( $line =~ /^ => (\S+) (.*)$/ ) {
   1.121 +      $traceHash{$1} = $2;
   1.122 +    }
   1.123 +    else {
   1.124 +      print $line;
   1.125 +    }
   1.126 +
   1.127 +  }
   1.128 +  close( FIN );
   1.129 +  
   1.130 +}
   1.131 +
   1.132 +main();