Update stats tool

This commit is contained in:
Joshua Bell 2018-02-26 19:59:33 -08:00
parent 366d092d91
commit 60062360ca
3 changed files with 38 additions and 36 deletions

View File

@ -161,7 +161,7 @@ L7207: .byte $29
entry 0, $66D8
L7232: .byte $29
L7233: entry 0, $72CD
entry 0, $72CD
entry 0, $736C
entry 0, $65F0
entry 0, $6693

View File

@ -1,31 +1,57 @@
#!/usr/bin/env perl
# stats.pl < source.s -- dump stats
# stats.pl unscoped < source.s -- list Lxxxx symbols not within 2 scopes
# stats.pl single < source.s -- list Lxxxx symbols with no references
use strict;
use warnings;
my %terms;
my $command = shift(@ARGV) // "";
my %defs;
my %refs;
my %unscoped;
my $depth = 0;
while (<STDIN>) {
++$depth if m/\.proc/ || m/\.scope/;
--$depth if m/\.endproc/ || m/\.endscope/;
foreach my $term (split /\b/, $_) {
if (m/^(L[0-9A-F]{4}):(.*)/) {
my $def = $1;
$_ = $2;
$defs{$def} = ($defs{$def} // 0) + 1;
$unscoped{$def} = 1 if $depth < 2;
}
foreach my $term (split /(?<!::)\b/, $_) {
if ($term =~ /^L[0-9A-F]{4}$/) {
$terms{$term} = 0 unless defined $terms{$term};
$terms{$term} += 1;
$unscoped{$term} = 1 if $depth < 2;
$refs{$term} = 0 unless defined $refs{$term};
$refs{$term} += 1;
}
}
}
my $single = 0;
foreach my $key (keys %terms) {
++$single if $terms{$key} == 1;
my $unrefed = 0;
foreach my $def (keys %defs) {
++$unrefed unless defined $refs{$def};
}
my $terms = scalar(keys %terms);
my $defs = scalar(keys %defs);
my $unscoped = scalar(keys %unscoped);
my $scoped = $terms - $unscoped;
my $scoped = $defs - $unscoped;
print "unscoped: $unscoped scoped: $scoped single: $single\n";
if ($command eq "unscoped") {
foreach my $def (sort keys %unscoped) {
print "$def\n";
}
} elsif ($command eq "unrefed") {
foreach my $def (sort keys %defs) {
print "$def\n" unless defined $refs{$def};
}
} elsif ($command eq "") {
print "unscoped: $unscoped scoped: $scoped unrefed: $unrefed\n";
} else {
die "Unknown command: $command\n";
}

View File

@ -1,24 +0,0 @@
#!/usr/bin/env perl
use strict;
use warnings;
my %terms;
my %unscoped;
my $depth = 0;
while (<STDIN>) {
++$depth if m/\.proc/ || m/\.scope/;
--$depth if m/\.endproc/ || m/\.endscope/;
foreach my $term (split /\b/, $_) {
if ($term =~ /^L[0-9A-F]{4}$/) {
$terms{$term} = 0 unless defined $terms{$term};
$terms{$term} += 1;
$unscoped{$term} = 1 if $depth < 2;
}
}
}
foreach my $term (sort keys %unscoped) {
print "$term\n";
}