mirror of
https://github.com/pret/pmd-red.git
synced 2026-04-26 00:15:48 -05:00
Improve calcrom, add incbin counting, fix a few existing issues (#7)
This commit is contained in:
parent
b11c1642ac
commit
0f877a3561
|
|
@ -59,15 +59,18 @@ my $base_cmd = "nm $elffname | awk '{print \$3}' | grep '^[^_].\\{4\\}' | uniq";
|
|||
|
||||
# This looks for Unknown_, Unknown_, or sub_, followed by just numbers. Note that
|
||||
# it matches even if stuff precedes the unknown, like sUnknown/gUnknown.
|
||||
my $undoc_cmd = "grep '[Uu]nknown_[0-9a-fA-F]*\\|sub_[0-9a-fA-F]*'";
|
||||
# 'sub_' anchors to the start so it does not consider symbols like 'nullsub_12' undocumented.
|
||||
my $undoc_cmd = "grep -E '[Uu]nknown_[0-9a-fA-F]*|^sub_[0-9a-fA-F]*'";
|
||||
|
||||
# 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,6\\}'";
|
||||
my $partial_doc_cmd = "grep '_[0-38-9][0-9a-fA-F]\\{5,6\\}'";
|
||||
|
||||
my $count_cmd = "wc -l";
|
||||
|
||||
my $incbin_cmd = "find \"\$(dirname $elffname)\" \\( -name '*.s' -o -name '*.inc' \\) -exec cat {} ';' | grep -oE '^\\s*\\.incbin\\s*\"[^\"]+\"\s*,\\s*(0x)?[0-9a-fA-F]+\\s*,\\s*(0x)?[0-9a-fA-F]+' -";
|
||||
|
||||
# It sucks that we have to run this three times, but I can't figure out how to get
|
||||
# stdin working for subcommands in perl while still having a timeout. It's decently
|
||||
# fast anyway.
|
||||
|
|
@ -95,6 +98,22 @@ my $partial_documented_as_string;
|
|||
))
|
||||
or die "ERROR: Error while filtering for partial symbols: $?";
|
||||
|
||||
my $incbin_count_as_string;
|
||||
(run (
|
||||
command => "$incbin_cmd | $count_cmd",
|
||||
buffer => \$incbin_count_as_string,
|
||||
timeout => 60
|
||||
))
|
||||
or die "ERROR: Error while counting incbins: $?";
|
||||
|
||||
my $incbin_bytes_as_string;
|
||||
(run (
|
||||
command => "(echo -n 'ibase=16;' ; $incbin_cmd | sed -E 's/.*,\\s*0x([0-9a-fA-F]+)/\\1/' | tr '\\n' '+'; echo '0' ) | bc",
|
||||
buffer => \$incbin_bytes_as_string,
|
||||
timeout => 60
|
||||
))
|
||||
or die "ERROR: Error while calculating incbin totals: $?";
|
||||
|
||||
# Performing addition on a string converts it to a number. Any string that fails
|
||||
# to convert to a number becomes 0. So if our converted number is 0, but our string
|
||||
# is nonzero, then the conversion was an error.
|
||||
|
|
@ -113,6 +132,15 @@ my $total_syms = $total_syms_as_string + 0;
|
|||
($total_syms != 0)
|
||||
or die "ERROR: No symbols found.";
|
||||
|
||||
my $incbin_count = $incbin_count_as_string + 0;
|
||||
(($incbin_count != 0) and ($incbin_count_as_string ne "0"))
|
||||
or die "ERROR: Cannot convert string to num: '$incbin_count_as_string'";
|
||||
|
||||
my $incbin_bytes = $incbin_bytes_as_string + 0;
|
||||
(($incbin_bytes != 0) and ($incbin_bytes_as_string ne "0"))
|
||||
or die "ERROR: Cannot convert string to num: '$incbin_bytes_as_string'";
|
||||
|
||||
|
||||
my $total = $src + $asm;
|
||||
my $srcPct = sprintf("%.4f", 100 * $src / $total);
|
||||
my $asmPct = sprintf("%.4f", 100 * $asm / $total);
|
||||
|
|
@ -154,6 +182,8 @@ my $dataTotal = $srcdata + $data;
|
|||
my $srcDataPct = sprintf("%.4f", 100 * $srcdata / $dataTotal);
|
||||
my $dataPct = sprintf("%.4f", 100 * $data / $dataTotal);
|
||||
|
||||
my $incPct = sprintf("%.4f", 100 * $incbin_bytes / $dataTotal);
|
||||
|
||||
if ($data == 0)
|
||||
{
|
||||
print "Data porting to C is 100% complete\n"
|
||||
|
|
@ -164,3 +194,11 @@ else
|
|||
print "$srcdata bytes of data in src ($srcDataPct%)\n";
|
||||
print "$data bytes of data in data ($dataPct%)\n";
|
||||
}
|
||||
|
||||
print "\n";
|
||||
|
||||
if ($incbin_count == 0) {
|
||||
print "All incbins have been eliminated\n"
|
||||
} else {
|
||||
print "$incbin_bytes bytes of data in $incbin_count incbins ($incPct%)\n"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@
|
|||
.include "sound/music_player_table.inc"
|
||||
.include "sound/song_table.inc"
|
||||
|
||||
.incbin "baserom.gba", 0x1E8841C
|
||||
.incbin "baserom.gba", 0x1E8841C, 0x177BE4
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user