replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Unused subroutines and functions
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Unused subroutines and functions

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
KennyT



Joined: 02 Aug 2005
Posts: 320

PostPosted: Tue Jun 21, 2011 2:38 pm    Post subject: Unused subroutines and functions Reply with quote

Hi,

A quick question.

Over the years our application has acquired routines that I'm sure are no longer being used, but daren't just delete them! Is there a link switch that can list any un-called functions?

K
Back to top
View user's profile Send private message Visit poster's website
brucebowler
Guest





PostPosted: Tue Jun 21, 2011 3:23 pm    Post subject: Reply with quote

A couple of thoughts....

There are "call-tree" generators out there on the web. I'm sure some are free and some cost. You could try and use one of those and see what happens...

Second thought (that might work,or not) is to put all of the subroutines/functions into a library and then look at the linker map to see what's linked in. That, of course, relies on my assumption that the linker doesn't include items in the library that aren't called.

Third thought (hey, I never said I could count :-). Create a new project, add in only the main program. Compile/link see what it complains is missing. Add those, and repeat, until no complaints...

I didn't say any of them would be easy and foolproof.

Bruce
Back to top
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Tue Jun 21, 2011 3:51 pm    Post subject: Reply with quote

Kenny,

If you suspect a particular routine may not be called anywhere, then you could use the DOS command FIND to search through all your source code files for the name of the routine. This will list the subroutine itself plus any calls if they exist.

Cheers,
John
_________________
John Horspool
Roshaz Software Ltd.
Gloucestershire
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8255
Location: Salford, UK

PostPosted: Tue Jun 21, 2011 4:46 pm    Post subject: Reply with quote

What you need is the opposite of the SLINK switch /lure but I cannot find anything like it.

Plato has a "Find in Files" command that may be useful.
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2415
Location: Yateley, Hants, UK

PostPosted: Tue Jun 21, 2011 4:50 pm    Post subject: Reply with quote

I have a suspicion that SLINK doesn't link any routines that aren't called, so even if they appear in your source code, they don't make it (as dead code) into the EXE. So, if you can bear the (often negligible) overhead of recompiling them, then everything comes right in the end.

John's suggestion is a good one. You can also search with a text editor. The problem is that sometimes the call is there, but it is never actively pursued, e.g.

Code:
      IF (KEYBOARD_MODE .EQ. 1) THEN
      CALL BRUCE_BOWLER_CODE
      ENDIF


does lead to the routine being linked, even if KEYBOARD_MODE is set to something other than 1, because that was an option you abandoned 6 years ago!

Eddie
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2621
Location: Sydney

PostPosted: Wed Jun 22, 2011 1:08 am    Post subject: Reply with quote

Bruce has an idea, You could convert most of your code into a library and then use "le code.lib" in slink. This would then only load the routines that are called. You could then import the .map file into excel and sort it to locate routines that are called.
Note:
1) It use to be that if one routine was called from a .obj file, then all routines in the .obj file were loaded. To overcome this I created a seperate .for file for each routine then used SLINK to create the library, using "addobj routinexx.obj" for each seperate routine. I'm not sure if this is still the case with the latest version of SLINK. I've kept the same script approach for a long time.
2) if you use "lo code.obj", all the routines in code.obj will be loaded, so once you force load an obsolete routine, then all routines it calls will also be loaded.

We realy need a call tree generator like FORCHK use to do for F77, providing a list of all routines that called each routine. SLINK should be able to provide this report.

Eddie's suggestion that SLINK does not load unused routines certainly was not the case with older versions of SLINK. I have not tested this recently, but I would suspect it is not that smart. SLINK could/should be a lot smarter!

John
Back to top
View user's profile Send private message
KennyT



Joined: 02 Aug 2005
Posts: 320

PostPosted: Wed Jun 22, 2011 9:04 am    Post subject: Reply with quote

Thanks for all the suggestions. Thought of most of them myself already - I'd even tried some of them (but got bored)!

Perhaps I'll write something to do it at one level (ie grep for all the SUBROUTINE/FUNCTIONs, output the list to a file, then search through all my source for each item and count how many times each one occurs...) but that wouldn't capture a routine that was called from an un-called routine, so may only be of limited use...

K
Back to top
View user's profile Send private message Visit poster's website
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Thu Aug 11, 2011 7:40 am    Post subject: Reply with quote

We use a tool for this. I think that you should be able to download a trial.
I think that the Lahey compiler has a build in function like this - perhaps something to think about for Plato Very Happy
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Thu Aug 11, 2011 12:09 pm    Post subject: Reply with quote

I have my own tool for doing this (written in Fortran Smile ). It just looks for all occurances of MODULE, SUBROUTINE, FUNCTION across multiple files, extracts the names and checks there's at least one use somewhere. (USE, CALL or Function name).

I would be happy to post this here for people to use. (will do it when I'm near to my main machine).

David.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group