2017-09-14 03:09:36 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
2018-02-27 03:59:33 +00:00
|
|
|
# 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
|
|
|
|
|
2017-09-14 03:09:36 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2018-02-27 03:59:33 +00:00
|
|
|
my $command = shift(@ARGV) // "";
|
|
|
|
|
|
|
|
my %defs;
|
|
|
|
my %refs;
|
2018-02-12 00:04:20 +00:00
|
|
|
my %unscoped;
|
|
|
|
my $depth = 0;
|
|
|
|
|
2017-09-14 03:09:36 +00:00
|
|
|
while (<STDIN>) {
|
2018-02-12 00:04:20 +00:00
|
|
|
++$depth if m/\.proc/ || m/\.scope/;
|
|
|
|
--$depth if m/\.endproc/ || m/\.endscope/;
|
2018-02-27 03:59:33 +00:00
|
|
|
|
|
|
|
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/, $_) {
|
2018-02-12 00:04:20 +00:00
|
|
|
if ($term =~ /^L[0-9A-F]{4}$/) {
|
2018-02-27 03:59:33 +00:00
|
|
|
$refs{$term} = 0 unless defined $refs{$term};
|
|
|
|
$refs{$term} += 1;
|
2018-02-12 00:04:20 +00:00
|
|
|
}
|
2017-09-14 03:09:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 03:59:33 +00:00
|
|
|
my $unrefed = 0;
|
|
|
|
foreach my $def (keys %defs) {
|
|
|
|
++$unrefed unless defined $refs{$def};
|
2018-02-12 00:04:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-27 03:59:33 +00:00
|
|
|
my $defs = scalar(keys %defs);
|
2018-02-12 00:04:20 +00:00
|
|
|
my $unscoped = scalar(keys %unscoped);
|
2018-02-27 03:59:33 +00:00
|
|
|
my $scoped = $defs - $unscoped;
|
2018-02-12 00:04:20 +00:00
|
|
|
|
2018-02-27 03:59:33 +00:00
|
|
|
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";
|
|
|
|
}
|