Mercurial > pygar
view scripts/bsv-trace.pl @ 54:9b4f237e77e1 pygar svn.55
[svn r55] input a bit more parameterized
author | punk |
---|---|
date | Sun, 09 May 2010 12:24:35 -0400 |
parents | 90197e3375e2 |
children |
line wrap: on
line source
1 #!/usr/bin/perl -w2 #==========================================================================3 # bsc-trace.pl4 #5 # Author : Christopher Batten (cbatten@mit.edu)6 # Date : April 12, 20057 #8 (our $usageMsg = <<'ENDMSG') =~ s/^\#//gm;9 #10 # Simple script which converts bsv "one-per-line" trace output into11 # a more compact and readable column format.12 #13 ENDMSG15 use strict "vars";16 use warnings;17 no warnings("once");18 use Getopt::Long;19 use File::Basename;21 #--------------------------------------------------------------------------22 # Command line processing23 #--------------------------------------------------------------------------25 our %opts;27 sub usage()28 {30 print "\n";31 print " Usage: bsc-trace.pl <format-file> [trace-file]\n";32 print "\n";33 print " Options:\n";34 print " --help print this message\n";35 print " <format-str> format string\n";36 print " [trace-file] output trace from BSV simulation (default is STDIN)\n";37 print "$usageMsg";39 exit();40 }42 sub processCommandLine()43 {45 $opts{"help"} = 0;47 Getopt::Long::GetOptions( \%opts, 'help|?' ) or usage();49 ($opts{"format"} = shift(@ARGV)) or usage();50 ($opts{"trace-file"} = shift(@ARGV)) or ($opts{"trace-file"} = "-");51 $opts{"help"} and usage();53 }55 #--------------------------------------------------------------------------56 # Main57 #--------------------------------------------------------------------------59 sub main()60 {62 processCommandLine();63 require $opts{"format"};65 my $cycle = 0;66 my %traceHash;68 my $traceFile = $opts{"trace-file"};69 open( FIN, "<$traceFile" ) or die("Could not open BSV trace file ($traceFile)!");71 print " processor-state [ icache ] [ dcache ] [ mem-arb ] executed-instruction\n";73 my $labelLine = $settings::labelString;74 foreach my $tag ( keys %settings::headers){75 my $theLabel = $settings::headers{$tag};76 $labelLine =~ s/{$tag}/$theLabel/;77 }78 print " $labelLine\n";80 while ( my $line = <FIN> ) {82 if ( $line =~ /^ => Cycle =\s+(\d+)$/ ) {84 my $tempTraceLine = $settings::traceString;85 foreach my $tag ( keys %settings::fields ) {87 my $theTraceString = $traceHash{$tag};88 my $theEmptyString = $settings::fields{$tag};90 # Substitute the trace field in ...91 if ( defined($theTraceString) ) {93 # If the trace string is shorter than the empty string then94 # add some spaces at the end so things line up ...95 my $theTraceStringLen = length($theTraceString);96 my $theEmptyStringLen = length($theEmptyString);97 if ( $theTraceStringLen < $theEmptyStringLen ) {98 $theTraceString .= (" "x ($theEmptyStringLen-$theTraceStringLen));99 }101 $tempTraceLine =~ s/{$tag}/$theTraceString/;103 }105 # Substitute the empty field in ...106 else {107 $tempTraceLine =~ s/{$tag}/$theEmptyString/;108 }110 }112 print " CYC: ".sprintf("%4d",$cycle)." $tempTraceLine\n";114 $cycle = $1;115 %traceHash = ();116 }117 elsif ( $line =~ /^ => (\S+) (.*)$/ ) {118 $traceHash{$1} = $2;119 }120 else {121 print $line;122 }124 }125 close( FIN );127 }129 main();