scale.callGraph
Class CallGraph

java.lang.Object
  extended by scale.callGraph.CallGraph

public final class CallGraph
extends java.lang.Object

This class holds all of the RoutineDecl instances for the routines in a single compilation unit.

$Id: CallGraph.java,v 1.126 2007-10-29 13:46:16 burrill Exp $

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

A class that represents the call graph of a program. This class is used to build the call graph and maintain a pointer to the root node (the main routine) of the program.

The class also maintains information about the routines and global variables in a program.

See Also:
RoutineDecl

Field Summary
static boolean alphabeticalOrder
          If true, return routines in alphabetical order.
 
Constructor Summary
CallGraph(java.lang.String name, Suite suite, SourceLanguage sourceLang)
          Create a call graph of call nodes.
 
Method Summary
 void addCallee(RoutineDecl caller, RoutineDecl rd)
          Add a call to the call graph.
 void addFunction(RoutineDecl p)
          Add the routine to the list of routines that are referenced.
 void addProfiling(Vector<java.lang.String> moduleNames, int profileOptions)
          Add the profiling instrumentation to every call node in the call graph.
 SymtabEntry addRootSymbol(Declaration decl)
          Add the declaration to the root symbol table scope.
 SymtabEntry addSymbol(Declaration decl)
          Add the declaration to the current symbol table scope.
 void addTopLevelDecl(Declaration decl)
          Add a top level declaration.
 java.util.Iterator<RoutineDecl> allRoutines()
          Return an Iterator of all the routines.
 RoutineDecl[] allRoutinesArray()
          Return an array of all the routines.
static void cleanup()
          Clean up for profiling statistics.
 void computeCallGraph()
          Compute the call graph.
 Node getAST()
          Return the root of the Clef abstract syntax tree (AST).
 RoutineDecl getMain()
          Return the main procedure if any.
 java.lang.String getName()
          Return the name associated with this call graph.
 SourceLanguage getSourceLanguage()
          Return the source language of the call graph.
 Suite getSuite()
          Return the Suite to which this CallGraph belongs.
 Symtab getSymbolTable()
          Return the symbol table for the clef tree.
 void graphCallTree(DisplayGraph da)
          Create a graphic display of the call graph.
 int hashCode()
          Use the file name of the source file.
 int numRoutines()
          Return the number of routines in this call graph.
 void optimizeAST()
          Apply optimizations to the AST.
 void printAllRoutines()
          Print to out the routines in this call graph.
 void processFunctionPointers()
          Associate indirect calls with their targets.
 void readProfInfo(Vector<java.lang.String> profilePaths, int profileOptions)
          Read in the profiling information for every call node in the call graph.
 void recordRoutine(RoutineDecl rd)
          Record the RoutineDecl.
 void removeClefAST()
          Remove the Clef AST to save space.
static void reportProfileProblem(java.lang.String text)
          Generate a message for a profile data problem and abort.
 void setAST(Node ast)
          Specify the root node of the AST.
 void setMain(RoutineDecl main)
          Specify the main procedure (if any) in the CallGraph.
 java.util.Iterator<Declaration> topLevelDecls()
          Return an Iterator of all the top level declarations except routines.
 java.util.Iterator<Declaration> topLevelDefDecls()
          Return an Iterator of all the top level declarations (except routines) that are defining definitions.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

alphabeticalOrder

public static boolean alphabeticalOrder
If true, return routines in alphabetical order.

Constructor Detail

CallGraph

public CallGraph(java.lang.String name,
                 Suite suite,
                 SourceLanguage sourceLang)
Create a call graph of call nodes.

Parameters:
name - the name of the Clef AST (i.e., the file name)
suite - is the collection of call graphs
sourceLang - specifies the source language used
Method Detail

hashCode

public int hashCode()
Use the file name of the source file.

Overrides:
hashCode in class java.lang.Object

optimizeAST

public final void optimizeAST()
Apply optimizations to the AST.


getSuite

public final Suite getSuite()
Return the Suite to which this CallGraph belongs.


getName

public final java.lang.String getName()
Return the name associated with this call graph.


getSourceLanguage

public final SourceLanguage getSourceLanguage()
Return the source language of the call graph.


getAST

public final Node getAST()
Return the root of the Clef abstract syntax tree (AST).


setAST

public final void setAST(Node ast)
Specify the root node of the AST.


computeCallGraph

public final void computeCallGraph()
Compute the call graph.


removeClefAST

public final void removeClefAST()
Remove the Clef AST to save space.


getSymbolTable

public final Symtab getSymbolTable()
Return the symbol table for the clef tree.


addFunction

public void addFunction(RoutineDecl p)
Add the routine to the list of routines that are referenced.


addCallee

public void addCallee(RoutineDecl caller,
                      RoutineDecl rd)
Add a call to the call graph. If a call node hasn't already been created, we create one. Also, we all the callee to the list of routines in the program (if it hasn't been added already).

Parameters:
caller - the call node representing the caller
rd - the declaration node representig the callee

addProfiling

public void addProfiling(Vector<java.lang.String> moduleNames,
                         int profileOptions)
Add the profiling instrumentation to every call node in the call graph.

Parameters:
moduleNames - is the list of all source modules in the program and must include the module containing "main"
profileOptions - specifies which profiling instrumentation to insert

reportProfileProblem

public static void reportProfileProblem(java.lang.String text)
Generate a message for a profile data problem and abort.


readProfInfo

public void readProfInfo(Vector<java.lang.String> profilePaths,
                         int profileOptions)
Read in the profiling information for every call node in the call graph.

Parameters:
profilePaths - is the list of directories to search for profile information and must include the module containing "main"
profileOptions - specifies which profiling instrumentation to insert

printAllRoutines

public void printAllRoutines()
Print to out the routines in this call graph.


processFunctionPointers

public void processFunctionPointers()
Associate indirect calls with their targets.


recordRoutine

public void recordRoutine(RoutineDecl rd)
Record the RoutineDecl.


getMain

public RoutineDecl getMain()
Return the main procedure if any.


setMain

public void setMain(RoutineDecl main)
Specify the main procedure (if any) in the CallGraph.


allRoutines

public java.util.Iterator<RoutineDecl> allRoutines()
Return an Iterator of all the routines.


allRoutinesArray

public RoutineDecl[] allRoutinesArray()
Return an array of all the routines.


numRoutines

public int numRoutines()
Return the number of routines in this call graph.


addTopLevelDecl

public void addTopLevelDecl(Declaration decl)
Add a top level declaration.


topLevelDecls

public java.util.Iterator<Declaration> topLevelDecls()
Return an Iterator of all the top level declarations except routines.


topLevelDefDecls

public java.util.Iterator<Declaration> topLevelDefDecls()
Return an Iterator of all the top level declarations (except routines) that are defining definitions. We use this to distinguish between defining and references declarations (ie., those with the extern keyword).


graphCallTree

public void graphCallTree(DisplayGraph da)
Create a graphic display of the call graph.

Parameters:
da - is the graph display

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

addSymbol

public SymtabEntry addSymbol(Declaration decl)
Add the declaration to the current symbol table scope.

Returns:
the symbol table entry

addRootSymbol

public SymtabEntry addRootSymbol(Declaration decl)
Add the declaration to the root symbol table scope.

Returns:
the symbol table entry

cleanup

public static void cleanup()
Clean up for profiling statistics.