comparison 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
comparison
equal deleted inserted replaced
22:0cfbb1e2de22 23:90197e3375e2
1 #!/usr/bin/perl -w
2 #==========================================================================
3 # bsc-trace.pl
4 #
5 # Author : Christopher Batten (cbatten@mit.edu)
6 # Date : April 12, 2005
7 #
8 (our $usageMsg = <<'ENDMSG') =~ s/^\#//gm;
9 #
10 # Simple script which converts bsv "one-per-line" trace output into
11 # a more compact and readable column format.
12 #
13 ENDMSG
14
15 use strict "vars";
16 use warnings;
17 no warnings("once");
18 use Getopt::Long;
19 use File::Basename;
20
21 #--------------------------------------------------------------------------
22 # Command line processing
23 #--------------------------------------------------------------------------
24
25 our %opts;
26
27 sub usage()
28 {
29
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";
38
39 exit();
40 }
41
42 sub processCommandLine()
43 {
44
45 $opts{"help"} = 0;
46
47 Getopt::Long::GetOptions( \%opts, 'help|?' ) or usage();
48
49 ($opts{"format"} = shift(@ARGV)) or usage();
50 ($opts{"trace-file"} = shift(@ARGV)) or ($opts{"trace-file"} = "-");
51 $opts{"help"} and usage();
52
53 }
54
55 #--------------------------------------------------------------------------
56 # Main
57 #--------------------------------------------------------------------------
58
59 sub main()
60 {
61
62 processCommandLine();
63 require $opts{"format"};
64
65 my $cycle = 0;
66 my %traceHash;
67
68 my $traceFile = $opts{"trace-file"};
69 open( FIN, "<$traceFile" ) or die("Could not open BSV trace file ($traceFile)!");
70
71 print " processor-state [ icache ] [ dcache ] [ mem-arb ] executed-instruction\n";
72
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";
79
80 while ( my $line = <FIN> ) {
81
82 if ( $line =~ /^ => Cycle =\s+(\d+)$/ ) {
83
84 my $tempTraceLine = $settings::traceString;
85 foreach my $tag ( keys %settings::fields ) {
86
87 my $theTraceString = $traceHash{$tag};
88 my $theEmptyString = $settings::fields{$tag};
89
90 # Substitute the trace field in ...
91 if ( defined($theTraceString) ) {
92
93 # If the trace string is shorter than the empty string then
94 # 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 }
100
101 $tempTraceLine =~ s/{$tag}/$theTraceString/;
102
103 }
104
105 # Substitute the empty field in ...
106 else {
107 $tempTraceLine =~ s/{$tag}/$theEmptyString/;
108 }
109
110 }
111
112 print " CYC: ".sprintf("%4d",$cycle)." $tempTraceLine\n";
113
114 $cycle = $1;
115 %traceHash = ();
116 }
117 elsif ( $line =~ /^ => (\S+) (.*)$/ ) {
118 $traceHash{$1} = $2;
119 }
120 else {
121 print $line;
122 }
123
124 }
125 close( FIN );
126
127 }
128
129 main();