Unused labels in CA65?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
heardtheword
Posts: 20
Joined: Mon Feb 08, 2016 1:22 pm
Contact:

Unused labels in CA65?

Post by heardtheword »

Is there a way to find labels that are not used in CA65? I'm trying to find code that may not be used, like dead code elimination in higher level languages. This would also help find ram storage that isn't being used.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Unused labels in CA65?

Post by tepples »

I made a call graph tool as part of a code review of Thwaite in preparation for expanding the game past 16K PRG. You pass in a folder full of code, and it finds everywhere each symbol is used in order to make pretty boxes.

Call graph visualizer (using Python and GraphViz) and sample output
User avatar
heardtheword
Posts: 20
Joined: Mon Feb 08, 2016 1:22 pm
Contact:

Re: Unused labels in CA65?

Post by heardtheword »

Nifty! I may have to incorporate this into my build process.

Thanks!
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Unused labels in CA65?

Post by rainwarrior »

If you separate your code into multiple modules (think: 1 function defined in each .s file), and then combine them into a library, the ld65 linker is capable of identifying unused functions and automatically omitting them from the build.

The convenience of this is mitigated by having to create so many separate files, but it's available, at least. It's quite useful when linking with the CRT libraries.
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: Unused labels in CA65?

Post by thefox »

rainwarrior wrote:The convenience of this is mitigated by having to create so many separate files, but it's available, at least. It's quite useful when linking with the CRT libraries.
One trick that can be used to avoid having to create many files is to do something like this (example in C, but should be adaptable to assembly).

Code: Select all

// my_funcs.c

#if defined FUNC_FOO

int foo(void) {
  return 123;
}

#elif defined FUNC_BAR

int bar(int xxx) {
  return xxx+1;
}

#endif
Then you'd simply compile the same file multiple times, defining FUNC_FOO or FUNC_BAR from the command line to decide which function should end up in the object file. Never did this myself, but I've seen it done elsewhere for libraries.

BTW, IIRC ld65 will only drop unused object files if they come from a library. If the object file is explicitly specified in the command line it will always be included.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Post Reply