scale.clef.decl
Class RoutineDecl

java.lang.Object
  extended by scale.common.Root
      extended by scale.clef.Node
          extended by scale.clef.decl.Declaration
              extended by scale.clef.decl.RoutineDecl
All Implemented Interfaces:
java.lang.Comparable, AnnotationInterface, DisplayNode
Direct Known Subclasses:
ProcedureDecl

public abstract class RoutineDecl
extends Declaration

This is the base class representing all routine declarations.

$Id: RoutineDecl.java,v 1.86 2007-10-04 19:58:04 burrill Exp $

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


Field Summary
static int NOTPURE
          The function may have side effects, may reference any global variables of this program, and may modify any locations referenced by an argument.
static int PURE
          The function is completely "pure".
static int PUREARGS
          The function does not modify any locations referenced by an argument.
static int PUREGV
          The function does not reference any global variables of this program.
static int PUREGVA
          The function does not reference any global variables of this program or modify any locations referenced by an argument.
static int PURESE
          The function does not have side effects.
static int PURESGV
          The function does not have side effects or use global variables.
 
Constructor Summary
protected RoutineDecl(java.lang.String name, ProcedureType type)
           
protected RoutineDecl(java.lang.String name, ProcedureType type, Statement body)
          Create a routine with the specified name and type.
 
Method Summary
 void addCallee(RoutineDecl callee)
          Add a link in the call graph to the callee.
 void addCaller(RoutineDecl caller)
          Specify a caller of this call node.
 void addCandidate(Type type)
          Add a potential (indirect) call.
 void addCost(int cost)
          Add to the cost associated with this call node.
 VariableDecl addProfiling(int profileOptions)
          Add the profiling information to this call node.
 void attachScribbleCFG(Scribble scribble)
          Attach the Scribble CFG to the call node.
 boolean calls(RoutineDecl target, HashSet<RoutineDecl> done)
          Returns true if this call node routine calls the specified routine or calls a subroutine that results in a call to the specified routine.
 boolean cantInline()
          Return true if this routine cannot be inlined for whatever reason.
 void clearAST()
          Remove all Clef AST stuff.
 int getAddressRegister()
          Return the register the code generator assigned to the address of this variable.
 Statement getBody()
          Return the Clef AST for this routine or null.
 int getBuiltIn()
          Return builtin function index.
 RoutineDecl getCallee(int i)
          Return the specified callee.
 Type getCalleeCandidate(int i)
          Return the return type of the specified caller.
 RoutineDecl getCaller(int i)
          Return the specified caller.
 CallGraph getCallGraph()
          Return the CallGraph that contains this RoutineDecl.
 Node getChild(int i)
          Return the specified AST child of this node.
 int getCost()
          Return the cost associated with this call node.
 Displacement getDisplacement()
          Return the code generator displacement associated with this call node.
 DColor getDisplayColorHint()
          Return a String specifying the color to use for coloring this node in a graphical display.
 VariableDecl getFtnResultVar()
          Return the declared function result variable (if any).
 int getProfCallCnt()
          Return the number of times this call occurred during execution.
 int getPurityLevel()
          Return the level of purity of the routine.
 java.lang.String getRoutineName()
          Return the name of the routine that the call node represents.
 Scribble getScribbleCFG()
          Return the Scribble graph associated with this node.
 ProcedureType getSignature()
          Return this routine's type
 int getSourceLineNumber()
          Return the source line number associated with this node or -1 if not known.
 boolean inlineSpecified()
          Return true if the programmer specified to inline this routine.
 boolean isBuiltIn()
          Return true if calls to this function are a candidates for being converted to in-line code.
 boolean isMain()
          Return true if the declaration is the main procedure.
 boolean isPure()
          Return true if this declaration has a purity level of PUREGV.
 boolean isRecursive()
          Returns true if this call node routine calls itself or calls a subroutine that results in a call to itself.
 boolean isReferenced()
          Return true if the declaration is referenced somewhere in the Clef AST or has a body.
 boolean isRoutineDecl()
          Return true if RoutineDecl instance.
 boolean isSpecification()
          Return true if this is a specification of the routine and not the actual routine.
 int numCalleeCandidates()
          Return the number of routines that call this routine.
 int numCallees()
          Return the number of routines called by this routine.
 int numCallers()
          Return the number of routines that call this routine.
 int numChildren()
          Return the number of AST children of this node.
 void printCallees()
           
 RoutineDecl returnRoutineDecl()
          Return a RoutineDecl instance or null.
 void setAddressRegister(int reg)
          Specify the register the code generator assigned to the address of this variable.
 void setBody(Statement body)
          Specify the Clef AST for this routine or null if none.
 void setBuiltIn(int index)
          Specify the builtin function index.
 void setCantInline()
          Specifiy that this routine cannot be inlined.
 void setCost(int cost)
          Specify the cost associated with this call node.
 void setDisplacement(Displacement disp)
          Specify the code generator displacement associated with this call node.
 void setFtnResultVar(VariableDecl ftnResultVar)
          Declare the function result variable.
 void setInlineSpecified()
          Specifiy that the programmer wants this routine inlined.
 void setMain()
          Indicates that this procedure is the main procedure.
 void setNoinlineSpecified()
          Specifiy that the programmer wants this routine to not be inlined.
 void setProfCallCnt(int count)
          Specify the number of times this call occurred during execution.
 void setPurityLevel(int level)
           
 void setReferenced()
          Specify that the routine is referenced somewhere in the Clef AST.
 void setSignature(ProcedureType s)
          Specify this routine's type
 void setSourceLineNumber(int lineNumber)
          Set the source line number associated with this node or -1 if not known.
 void setUsesAlloca()
          Specify that the routine uses __builtin_alloca().
 void setUsesSetjmp()
          Specify that the routine uses va_start.
 void setUsesVaStart()
          Specify that the routine uses va_start.
 void specifyCallGraph(CallGraph cg)
          Specify the call graph that contains this routine.
 java.lang.String toStringSpecial()
          This method allows sub-classes to provide class specific stuff to the string.
 boolean usesAlloca()
          Return true if the routine uses __builtin_alloca().
 boolean usesSetjmp()
          Return true if the routine uses va_start().
 boolean usesVaStart()
          Return true if the routine uses va_start().
 void visit(Predicate p)
          Process a node by calling its associated routine.
 
Methods inherited from class scale.clef.decl.Declaration
accessibility, addressTaken, compareTo, copy, getActualType, getAlias, getConstantValue, getCoreType, getDecl, getDisplayLabel, getDisplayShapeHint, getMode, getName, getPointedToCore, getStorageLoc, getTag, getType, getValueRegister, hashCode, hasHiddenAliases, inMemory, isCaseLabelDecl, isCommonBaseVariable, isConst, isEnumElementDecl, isEquivalenceDecl, isExceptionDecl, isFieldDecl, isFileDecl, isFormalDecl, isForwardProcedureDecl, isFtnResultVar, isGlobal, isLabelDecl, isProcedureDecl, isRenamed, isRenamedVariableDecl, isStmtFtnDecl, isTemporary, isTypeDecl, isTypeName, isUnknownFormals, isValueDecl, isVariableDecl, isVirtual, isWeak, residency, returnCaseLabelDecl, returnEnumElementDecl, returnEquivalenceDecl, returnExceptionDecl, returnFieldDecl, returnFileDecl, returnFormalDecl, returnForwardProcedureDecl, returnLabelDecl, returnProcedureDecl, returnRenamedVariableDecl, returnStmtFtnDecl, returnTypeDecl, returnTypeName, returnUnknownFormals, returnValueDecl, returnVariableDecl, setAccessibility, setAddressTaken, setAlias, setName, setResidency, setStorageLoc, setTag, setType, setValueRegister, setVisibility, setWeak, valueRegMode, visibility
 
Methods inherited from class scale.clef.Node
setAnnotationLevel, setReportLevel, toString, toString, toStringChildren
 
Methods inherited from class scale.common.Root
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayName, getDisplayString, getNodeCount, getNodeID, hasAnnotation, hasEqualAnnotation, removeAnnotation, removeAnnotations, toStringAnnotations, toStringClass, trace, trace, trace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PURE

public static final int PURE
The function is completely "pure".

See Also:
Constant Field Values

PURESGV

public static final int PURESGV
The function does not have side effects or use global variables.

See Also:
Constant Field Values

PURESE

public static final int PURESE
The function does not have side effects.

See Also:
Constant Field Values

PUREGVA

public static final int PUREGVA
The function does not reference any global variables of this program or modify any locations referenced by an argument.

See Also:
Constant Field Values

PUREGV

public static final int PUREGV
The function does not reference any global variables of this program.

See Also:
Constant Field Values

PUREARGS

public static final int PUREARGS
The function does not modify any locations referenced by an argument.

See Also:
Constant Field Values

NOTPURE

public static final int NOTPURE
The function

See Also:
Constant Field Values
Constructor Detail

RoutineDecl

protected RoutineDecl(java.lang.String name,
                      ProcedureType type,
                      Statement body)
Create a routine with the specified name and type.

Parameters:
name - is the method name
type - is the method type
body - is the method body

RoutineDecl

protected RoutineDecl(java.lang.String name,
                      ProcedureType type)
Method Detail

specifyCallGraph

public final void specifyCallGraph(CallGraph cg)
Specify the call graph that contains this routine.


isReferenced

public final boolean isReferenced()
Return true if the declaration is referenced somewhere in the Clef AST or has a body.

Overrides:
isReferenced in class Declaration
See Also:
VariableDecl, RoutineDecl

setReferenced

public final void setReferenced()
Specify that the routine is referenced somewhere in the Clef AST.

Overrides:
setReferenced in class Declaration
See Also:
VariableDecl, RoutineDecl

usesVaStart

public final boolean usesVaStart()
Return true if the routine uses va_start().


setUsesVaStart

public final void setUsesVaStart()
Specify that the routine uses va_start.


usesSetjmp

public final boolean usesSetjmp()
Return true if the routine uses va_start().


setUsesSetjmp

public final void setUsesSetjmp()
Specify that the routine uses va_start.


usesAlloca

public final boolean usesAlloca()
Return true if the routine uses __builtin_alloca().


setUsesAlloca

public final void setUsesAlloca()
Specify that the routine uses __builtin_alloca().


isMain

public final boolean isMain()
Return true if the declaration is the main procedure.


setMain

public final void setMain()
Indicates that this procedure is the main procedure. This marks the main procedure in the C sense.


inlineSpecified

public final boolean inlineSpecified()
Return true if the programmer specified to inline this routine.


setInlineSpecified

public final void setInlineSpecified()
Specifiy that the programmer wants this routine inlined.


setNoinlineSpecified

public final void setNoinlineSpecified()
Specifiy that the programmer wants this routine to not be inlined.


cantInline

public final boolean cantInline()
Return true if this routine cannot be inlined for whatever reason.


setCantInline

public final void setCantInline()
Specifiy that this routine cannot be inlined.


getPurityLevel

public int getPurityLevel()
Return the level of purity of the routine. The level is a byte where each bit in the byte represents some "pureness".
bitmeaning
4 does not have any side effects
2 does not reference any global variables of the program (it may modify file buffers and other OS things)
1 the routine does not modify any of its arguments or what they point to


setPurityLevel

public void setPurityLevel(int level)

isPure

public boolean isPure()
Return true if this declaration has a purity level of PUREGV.

Overrides:
isPure in class Declaration

getFtnResultVar

public VariableDecl getFtnResultVar()
Return the declared function result variable (if any).


setProfCallCnt

public final void setProfCallCnt(int count)
Specify the number of times this call occurred during execution.


getProfCallCnt

public final int getProfCallCnt()
Return the number of times this call occurred during execution.


setBuiltIn

public final void setBuiltIn(int index)
Specify the builtin function index. A value of zero indicates that calls to this function are not a candidates for being converted to in-line code. This only applies to compilations that specify -gcc.


getBuiltIn

public final int getBuiltIn()
Return builtin function index. A value of zero indicates that calls to this function are not a candidates for being converted to in-line code. This only applies to compilations that specify -gcc.


isBuiltIn

public final boolean isBuiltIn()
Return true if calls to this function are a candidates for being converted to in-line code. This only applies to compilations that specify -gcc.


setFtnResultVar

public void setFtnResultVar(VariableDecl ftnResultVar)
Declare the function result variable.


toStringSpecial

public java.lang.String toStringSpecial()
Description copied from class: Node
This method allows sub-classes to provide class specific stuff to the string.

Overrides:
toStringSpecial in class Declaration

getCallGraph

public CallGraph getCallGraph()
Return the CallGraph that contains this RoutineDecl.


addProfiling

public VariableDecl addProfiling(int profileOptions)
Add the profiling information to this call node.

Parameters:
profileOptions - specifies which profiling instrumentation to insert
Returns:
the variable definition for the profiling information or null if none

numCallees

public int numCallees()
Return the number of routines called by this routine.


getCallee

public RoutineDecl getCallee(int i)
Return the specified callee.


numCallers

public int numCallers()
Return the number of routines that call this routine.


getCaller

public RoutineDecl getCaller(int i)
Return the specified caller.


numCalleeCandidates

public int numCalleeCandidates()
Return the number of routines that call this routine.


getCalleeCandidate

public Type getCalleeCandidate(int i)
Return the return type of the specified caller.


getRoutineName

public final java.lang.String getRoutineName()
Return the name of the routine that the call node represents.


addCallee

public void addCallee(RoutineDecl callee)
Add a link in the call graph to the callee.

Parameters:
callee - the call node that represents the routine we're calling

addCaller

public void addCaller(RoutineDecl caller)
Specify a caller of this call node.


addCandidate

public void addCandidate(Type type)
Add a potential (indirect) call.

Parameters:
type - is the return type of the routine called.

printCallees

public void printCallees()

attachScribbleCFG

public void attachScribbleCFG(Scribble scribble)
Attach the Scribble CFG to the call node. Note - this will delete the Clef AST associated with the routine and the list of candidate indirect calls.

Parameters:
scribble - is the Scribble CFG

clearAST

public void clearAST()
Remove all Clef AST stuff.


getScribbleCFG

public Scribble getScribbleCFG()
Return the Scribble graph associated with this node.


getDisplacement

public Displacement getDisplacement()
Return the code generator displacement associated with this call node.

Overrides:
getDisplacement in class Declaration

setDisplacement

public void setDisplacement(Displacement disp)
Specify the code generator displacement associated with this call node.

Overrides:
setDisplacement in class Declaration

getAddressRegister

public int getAddressRegister()
Return the register the code generator assigned to the address of this variable.

Overrides:
getAddressRegister in class Declaration

setAddressRegister

public void setAddressRegister(int reg)
Specify the register the code generator assigned to the address of this variable.

Overrides:
setAddressRegister in class Declaration

getCost

public int getCost()
Return the cost associated with this call node.


setCost

public void setCost(int cost)
Specify the cost associated with this call node.


addCost

public void addCost(int cost)
Add to the cost associated with this call node.


visit

public void visit(Predicate p)
Description copied from class: Node
Process a node by calling its associated routine. See the "visitor" design pattern in Design Patterns: Elements of Reusable Object-Oriented Software by E. Gamma, et al, Addison Wesley, ISBN 0-201-63361-2.

Each class has a visit(Predicate p) method. For example, in class ABC:

   public void visit(Predicate p)
   {
     p.visitABC(this);
   }
 
and the class that implements Predicate has a method
   public void visitABC(Node n)
   {
     ABC a = (ABC) n;
     ...
   }
 
Thus, the class that implements Predicate can call
   n.visit(this);
 
where n is a Node sub-class without determining which specific sub-class n is. The visit pattern basically avoids implementing a large switch statement or defining different methods in each class for some purpose.

Overrides:
visit in class Declaration
See Also:
Predicate

getSignature

public ProcedureType getSignature()
Return this routine's type


setSignature

public void setSignature(ProcedureType s)
Specify this routine's type


isSpecification

public final boolean isSpecification()
Return true if this is a specification of the routine and not the actual routine.


setBody

public final void setBody(Statement body)
Specify the Clef AST for this routine or null if none.


getBody

public final Statement getBody()
Return the Clef AST for this routine or null.


getChild

public Node getChild(int i)
Return the specified AST child of this node.

Overrides:
getChild in class Node

numChildren

public int numChildren()
Return the number of AST children of this node.

Overrides:
numChildren in class Node

getDisplayColorHint

public DColor getDisplayColorHint()
Return a String specifying the color to use for coloring this node in a graphical display. This method should be over-ridden as it simplay returns the color red.

Specified by:
getDisplayColorHint in interface DisplayNode
Overrides:
getDisplayColorHint in class Declaration
See Also:
DColor

calls

public boolean calls(RoutineDecl target,
                     HashSet<RoutineDecl> done)
Returns true if this call node routine calls the specified routine or calls a subroutine that results in a call to the specified routine.

Parameters:
target - is the specified routine
done - is used to avoid infinite recursion and conbinatorial explosion

isRecursive

public boolean isRecursive()
Returns true if this call node routine calls itself or calls a subroutine that results in a call to itself.


getSourceLineNumber

public final int getSourceLineNumber()
Return the source line number associated with this node or -1 if not known.

Overrides:
getSourceLineNumber in class Node

setSourceLineNumber

public final void setSourceLineNumber(int lineNumber)
Set the source line number associated with this node or -1 if not known.

Overrides:
setSourceLineNumber in class Node

isRoutineDecl

public final boolean isRoutineDecl()
Description copied from class: Declaration
Return true if RoutineDecl instance.

Overrides:
isRoutineDecl in class Declaration

returnRoutineDecl

public final RoutineDecl returnRoutineDecl()
Description copied from class: Declaration
Return a RoutineDecl instance or null.

Overrides:
returnRoutineDecl in class Declaration