source: xtideuniversalbios/trunk/Tools/unused.pl@ 546

Last change on this file since 546 was 532, checked in by krille_n_@…, 12 years ago

Changes:

  • Changed unused.pl to remove a false positive when MODULE_STRINGS_COMPRESSED is not included ('loop PrependOrAppendSpaces' in DisplayFormat.asm).
  • XTIDECFG: Moved the contents of all text files under Help into Strings.asm to simplify editing and to avoid them being "out of sight and forgotten", essentially making it easier to keep strings up to date. Also made changes to some strings in the process (spelling mistakes etc).
  • Other minor fixes and optimizations to the BIOS.
File size: 2.5 KB
RevLine 
[194]1#
2# Looks for unused entry points, to aid in discovering dead code that can be removed
3#
4# Usage: unused.pl listing unused.asm
[526]5#
[194]6# where: listing is the normal listing from assembly
7# unused.asm is assembled with the -E nasm flag
8#
9# Annotations can be placed in the source to eliminate false positives:
[489]10# a) if a label can be fallen into, place "; fall through to <label>" above the label
[194]11# b) "; unused entrypoint ok" can be placed on the same line with the label
12# c) "; jump table entrypoint" can be placed on the same line with the label
13#
[376]14#
[526]15# XTIDE Universal BIOS and Associated Tools
16# Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]17#
18# This program is free software; you can redistribute it and/or modify
19# it under the terms of the GNU General Public License as published by
20# the Free Software Foundation; either version 2 of the License, or
21# (at your option) any later version.
[526]22#
[376]23# This program is distributed in the hope that it will be useful,
24# but WITHOUT ANY WARRANTY; without even the implied warranty of
25# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[526]26# GNU General Public License for more details.
[376]27# Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
28#
[194]29
30print "::".$ARGV[0]."::".$ARGV[1]."::\n";
31
32open( LST, "<", $ARGV[0] ) || die "cannot open listing: ".$ARGV[0];
33open( UNUSED, "<", $ARGV[1] ) || die "cannot open unused.asm: ".$ARGV[1];
34
35while(<LST>)
36{
37 if( /fall\s+(-?through\s+)?(to\s+)?([a-z0-9_]+)/i )
38 {
39 $ok{ $3 } = 1;
40 }
41 if( /unused\s+entrypoint\s+ok/i && /^\s*\d+\s+\<\d\>\s([a-z0-9_]+)\:/i )
42 {
43 $ok{ $1 } = 1;
44 }
45 if( /jump\s*table\s+entrypoint/i && /^\s*\d+\s+\<\d\>\s([a-z0-9_]+)\:/i )
46 {
47 $ok{ $1 } = 1;
48 }
49}
50
51while(<UNUSED>)
52{
[526]53 if( /^([a-z0-9_]+\:)?\s+db\s+(.*)$/i ||
54 /^([a-z0-9_]+\:)?\s+dw\s+(.*)$/i ||
[489]55 /^([a-z0-9_]+\:)?\s+mov\s+(.*)$/i ||
[526]56 /^([a-z0-9_]+\:)?\s+call\s+(.*)$/i ||
57 /^([a-z0-9_]+\:)?\s+push\s+(.*)$/i ||
[532]58 /^([a-z0-9_]+\:)?\s+loop\s+(.*)$/i ||
[489]59 /^([a-z0-9_]+\:)?\s+j[a-z]?[a-z]?[a-z]?[a-z]?[a-z]?\s+(.*)$/i ||
[194]60 /^([a-z0-9_]+)?\s+equ\s+(.*)$/i )
61 {
62 $rem = $2;
63 @words = split( /([a-z0-9_]+)/i, $_ );
64 for( $t = 0; $t <= $#words; $t++ )
65 {
66 $jumptable{ $words[$t] } = 1;
67 }
68 }
69 if( !(/^g_sz/) && /^([a-z0-9_]+)\:/i )
70 {
71 push( @definition, $1 );
72 }
73}
74
75$results = 0;
76for( $t = 0; $t <= $#definition; $t++ )
77{
78 $d = $definition[$t];
79 if( !$ok{$d} && !$jumptable{$d} )
80 {
81 print $definition[$t]."\n";
82 $results++;
83 }
84}
85
86print ">>>> Unused Count: ".$results."\n";
Note: See TracBrowser for help on using the repository browser.