annotate scripts/bsv-trace.pl @ 73:0f86d486e38e pygar svn.74

[svn r74] added new programs to run on processor.
author punk
date Wed, 12 May 2010 02:01:01 -0400
parents 90197e3375e2
children
rev   line source
rlm@23 1 #!/usr/bin/perl -w
rlm@23 2 #==========================================================================
rlm@23 3 # bsc-trace.pl
rlm@23 4 #
rlm@23 5 # Author : Christopher Batten (cbatten@mit.edu)
rlm@23 6 # Date : April 12, 2005
rlm@23 7 #
rlm@23 8 (our $usageMsg = <<'ENDMSG') =~ s/^\#//gm;
rlm@23 9 #
rlm@23 10 # Simple script which converts bsv "one-per-line" trace output into
rlm@23 11 # a more compact and readable column format.
rlm@23 12 #
rlm@23 13 ENDMSG
rlm@23 14
rlm@23 15 use strict "vars";
rlm@23 16 use warnings;
rlm@23 17 no warnings("once");
rlm@23 18 use Getopt::Long;
rlm@23 19 use File::Basename;
rlm@23 20
rlm@23 21 #--------------------------------------------------------------------------
rlm@23 22 # Command line processing
rlm@23 23 #--------------------------------------------------------------------------
rlm@23 24
rlm@23 25 our %opts;
rlm@23 26
rlm@23 27 sub usage()
rlm@23 28 {
rlm@23 29
rlm@23 30 print "\n";
rlm@23 31 print " Usage: bsc-trace.pl <format-file> [trace-file]\n";
rlm@23 32 print "\n";
rlm@23 33 print " Options:\n";
rlm@23 34 print " --help print this message\n";
rlm@23 35 print " <format-str> format string\n";
rlm@23 36 print " [trace-file] output trace from BSV simulation (default is STDIN)\n";
rlm@23 37 print "$usageMsg";
rlm@23 38
rlm@23 39 exit();
rlm@23 40 }
rlm@23 41
rlm@23 42 sub processCommandLine()
rlm@23 43 {
rlm@23 44
rlm@23 45 $opts{"help"} = 0;
rlm@23 46
rlm@23 47 Getopt::Long::GetOptions( \%opts, 'help|?' ) or usage();
rlm@23 48
rlm@23 49 ($opts{"format"} = shift(@ARGV)) or usage();
rlm@23 50 ($opts{"trace-file"} = shift(@ARGV)) or ($opts{"trace-file"} = "-");
rlm@23 51 $opts{"help"} and usage();
rlm@23 52
rlm@23 53 }
rlm@23 54
rlm@23 55 #--------------------------------------------------------------------------
rlm@23 56 # Main
rlm@23 57 #--------------------------------------------------------------------------
rlm@23 58
rlm@23 59 sub main()
rlm@23 60 {
rlm@23 61
rlm@23 62 processCommandLine();
rlm@23 63 require $opts{"format"};
rlm@23 64
rlm@23 65 my $cycle = 0;
rlm@23 66 my %traceHash;
rlm@23 67
rlm@23 68 my $traceFile = $opts{"trace-file"};
rlm@23 69 open( FIN, "<$traceFile" ) or die("Could not open BSV trace file ($traceFile)!");
rlm@23 70
rlm@23 71 print " processor-state [ icache ] [ dcache ] [ mem-arb ] executed-instruction\n";
rlm@23 72
rlm@23 73 my $labelLine = $settings::labelString;
rlm@23 74 foreach my $tag ( keys %settings::headers){
rlm@23 75 my $theLabel = $settings::headers{$tag};
rlm@23 76 $labelLine =~ s/{$tag}/$theLabel/;
rlm@23 77 }
rlm@23 78 print " $labelLine\n";
rlm@23 79
rlm@23 80 while ( my $line = <FIN> ) {
rlm@23 81
rlm@23 82 if ( $line =~ /^ => Cycle =\s+(\d+)$/ ) {
rlm@23 83
rlm@23 84 my $tempTraceLine = $settings::traceString;
rlm@23 85 foreach my $tag ( keys %settings::fields ) {
rlm@23 86
rlm@23 87 my $theTraceString = $traceHash{$tag};
rlm@23 88 my $theEmptyString = $settings::fields{$tag};
rlm@23 89
rlm@23 90 # Substitute the trace field in ...
rlm@23 91 if ( defined($theTraceString) ) {
rlm@23 92
rlm@23 93 # If the trace string is shorter than the empty string then
rlm@23 94 # add some spaces at the end so things line up ...
rlm@23 95 my $theTraceStringLen = length($theTraceString);
rlm@23 96 my $theEmptyStringLen = length($theEmptyString);
rlm@23 97 if ( $theTraceStringLen < $theEmptyStringLen ) {
rlm@23 98 $theTraceString .= (" "x ($theEmptyStringLen-$theTraceStringLen));
rlm@23 99 }
rlm@23 100
rlm@23 101 $tempTraceLine =~ s/{$tag}/$theTraceString/;
rlm@23 102
rlm@23 103 }
rlm@23 104
rlm@23 105 # Substitute the empty field in ...
rlm@23 106 else {
rlm@23 107 $tempTraceLine =~ s/{$tag}/$theEmptyString/;
rlm@23 108 }
rlm@23 109
rlm@23 110 }
rlm@23 111
rlm@23 112 print " CYC: ".sprintf("%4d",$cycle)." $tempTraceLine\n";
rlm@23 113
rlm@23 114 $cycle = $1;
rlm@23 115 %traceHash = ();
rlm@23 116 }
rlm@23 117 elsif ( $line =~ /^ => (\S+) (.*)$/ ) {
rlm@23 118 $traceHash{$1} = $2;
rlm@23 119 }
rlm@23 120 else {
rlm@23 121 print $line;
rlm@23 122 }
rlm@23 123
rlm@23 124 }
rlm@23 125 close( FIN );
rlm@23 126
rlm@23 127 }
rlm@23 128
rlm@23 129 main();