From dc24fde7f6fa092f342dbbb7557d6fdbf6af3784 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 27 Nov 2022 17:33:09 -0500 Subject: [PATCH] Sync calcrom fixes --- .github/calcrom/calcrom.pl | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/calcrom/calcrom.pl b/.github/calcrom/calcrom.pl index 9fbd95994..cb8c5723e 100755 --- a/.github/calcrom/calcrom.pl +++ b/.github/calcrom/calcrom.pl @@ -1,5 +1,11 @@ #!/usr/bin/perl +# Usage: +# calcrom.pl [--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);