-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathptx_exp.pl
More file actions
62 lines (57 loc) · 1.31 KB
/
Copy pathptx_exp.pl
File metadata and controls
62 lines (57 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!perl -w
use strict;
use warnings;
use Data::Mapped;
my $md = Data::Mapped->new('ptx/stab.bin');
die("cannot map") unless defined $md;
# stat
my $ops = 0;
my $num_ops = 0;
my $bad = 0;
my $bad_num = 0;
my($fh, $str, $off);
# read ptx_protos.txt
my %crc;
open($fh, '<', 'ptx_protos.txt') or die("cannot open ptx_protos.txt");
while( $str = <$fh> ) {
chomp $str;
next if ( $str !~ /^\|\d+\s+[a-f0-9]+\s+([a-f0-9]+)\s+(\S+)\|/i );
$crc{ hex($1) } = $2;
}
close $fh;
my %cache;
open($fh, '<', 'ptx_expand.txt') or die("cannot open ptx_expand.txt");
while( $str = <$fh> ) {
chomp $str;
if ( $str =~ /^ (.*)$/ ) {
my $off = hex($1);
my $macro = $md->at($off);
if ( defined $macro ) {
printf(">> %X: %s\n", $off, $macro);
$cache{$off}++;
} else {
++$bad;
}
} else {
printf("--- %s", $str);
if ( $str =~ /\b([0-9]+)$/ ) {
my $num = int($1);
++$num_ops;
if ( exists $crc{$num} ) {
printf(" %s\n", $crc{$num});
} else {
printf(" %X\n", $num);
++$bad_num;
}
} else {
printf("\n");
}
++$ops;
}
}
close $fh;
# dump stats
printf("%d ops, %d uniq offsets\n", $ops, scalar keys %cache);
printf("%d num ops\n", $num_ops) if $num_ops;
printf("%d bad num ops\n", $bad_num) if $bad_num;
printf("%d bad\n", $bad) if $bad;