Sync calcrom fixes

This commit is contained in:
GriffinR 2022-11-27 17:33:09 -05:00
parent e5260c9aa1
commit dc24fde7f6
1 changed files with 12 additions and 8 deletions

View File

@ -1,5 +1,11 @@
#!/usr/bin/perl
# Usage:
# calcrom.pl <mapfile> [--data]
#
# mapfile: path to .map file output by LD
# data: set to output % breakdown of data
use IPC::Cmd qw[ run ];
use Getopt::Long;
@ -65,12 +71,13 @@ my $base_cmd = "nm $elffname | awk '{print \$3}' | grep '^[^_].\\{4\\}' | uniq";
# This looks for Unknown_, Unknown_, or sub_, followed by an address. Note that
# it matches even if stuff precedes the unknown, like sUnknown/gUnknown.
my $undoc_cmd = "grep '[Uu]nknown_[0-9a-fA-F]\\{5,7\\}\\|sub_[0-9a-fA-F]\\{5,7\\}'";
my $undoc_regex = "'[Uu]nknown_[0-9a-fA-F]\\{5,7\\}\\|sub_[0-9a-fA-F]\\{5,7\\}'";
# This looks for every symbol with an address at the end of it. Some things are
# given a name based on their type / location, but still have an unknown purpose.
# For example, FooMap_EventScript_FFFFFFF.
my $partial_doc_cmd = "grep '_[0-28][0-9a-fA-F]\\{5,7\\}'";
# The above may be double counted here, and will need to be filtered out.
my $partial_doc_regex = "'_[0-28][0-9a-fA-F]\\{5,7\\}'";
my $count_cmd = "wc -l";
@ -87,7 +94,7 @@ my $total_syms_as_string;
my $undocumented_as_string;
(run (
command => "$base_cmd | $undoc_cmd | $count_cmd",
command => "$base_cmd | grep $undoc_regex | $count_cmd",
buffer => \$undocumented_as_string,
timeout => 60
))
@ -95,7 +102,7 @@ my $undocumented_as_string;
my $partial_documented_as_string;
(run (
command => "$base_cmd | $partial_doc_cmd | $count_cmd",
command => "$base_cmd | grep $partial_doc_regex | grep -v $undoc_regex | $count_cmd",
buffer => \$partial_documented_as_string,
timeout => 60
))
@ -112,7 +119,7 @@ my $undocumented = $undocumented_as_string + 0;
$partial_documented_as_string =~ s/^\s+|\s+$//g;
my $partial_documented = $partial_documented_as_string + 0;
(($partial_documented != 0) or (($partial_documented == 0) and ($partial_documented_as_string eq "0")))
or die "ERROR: Cannot convert string to num: '$partial_documented_as_string'";
or die "ERROR: Cannot convert string to num: '$partial_documented_as_string'";
$total_syms_as_string =~ s/^\s+|\s+$//g;
my $total_syms = $total_syms_as_string + 0;
@ -126,9 +133,6 @@ my $total = $src + $asm;
my $srcPct = sprintf("%.4f", 100 * $src / $total);
my $asmPct = sprintf("%.4f", 100 * $asm / $total);
# partial_documented is double-counting the unknown_* and sub_* symbols.
$partial_documented = $partial_documented - $undocumented;
my $documented = $total_syms - ($undocumented + $partial_documented);
my $docPct = sprintf("%.4f", 100 * $documented / $total_syms);
my $partialPct = sprintf("%.4f", 100 * $partial_documented / $total_syms);