-
Notifications
You must be signed in to change notification settings - Fork 7
/
calcrom.pl
37 lines (33 loc) · 872 Bytes
/
calcrom.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/perl
(@ARGV == 1)
or die "ERROR: no map file specified.\n";
open(my $file, $ARGV[0])
or die "ERROR: could not open file '$ARGV[0]'.\n";
my $src = 0;
my $asm = 0;
while (my $line = <$file>)
{
if ($line =~ /^ \.(\w+)\s+0x[0-9a-f]+\s+(0x[0-9a-f]+) (\w+)\/.+\.o/)
{
my $section = $1;
my $size = hex($2);
my $dir = $3;
if ($section =~ /text/)
{
if ($dir eq 'src')
{
$src += $size;
}
elsif ($dir eq 'asm')
{
$asm += $size;
}
}
}
}
my $total = $src + $asm;
my $srcPct = sprintf("%.4f", 100 * $src / $total);
my $asmPct = sprintf("%.4f", 100 * $asm / $total);
print "$total total bytes of code\n";
print "$src bytes of code in src ($srcPct%)\n";
print "$asm bytes of code in asm ($asmPct%)\n";