scale.score
Class Note

java.lang.Object
  extended by scale.common.Root
      extended by scale.score.Note
All Implemented Interfaces:
AnnotationInterface, DisplayNode
Direct Known Subclasses:
Chord, Expr

public abstract class Note
extends Root

This class is the base class for the CFG class hierarchy.

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

Score has two kinds of nodes:

Expressions represent the expected notion of expression (e.g., a + b). Chords represent executable statements in a program. These two kinds of nodes are realized as derived classes of this class.

The CFG does not use the special/region node subhierarchy. The CFG uses "cfg" edges instead of control edges. We build a CDG on top of an existing CFG.

Chords have an unknown number of incoming cfg edges (aka, data flow edges) and a fixed number of outgoing CFG edges. Chords also have a fixed number of incoming data edges but no outgoing data edges. Exprs have a fixed number of incoming data edges and one outgoing data edge.

Our represntation maintains bi-directional edges. For every graph edge which points to this node, this node also has a pointer back to the source of the graph edge. Hence, a CFG has twice as many edges as the conceptual graph which it is implementing.

From a very high-level view, nodes support a fully general graph. But in reality, different types of nodes have different restrictions on their incoming and outgoing edges.


Constructor Summary
protected Note()
          Constructor for a CFG node instance.
 
Method Summary
abstract  void changeInDataEdge(Expr oldExpr, Expr newExpr)
          This method changes an incoming data edge to point to a new expression.
abstract  int executionCostEstimate()
          Return a relative cost estimate for executing this node.
 Chord getChord()
          Return the Chord instance containing this Note.
 Note getEssentialUse()
          Return this Note instance unless it is a non-essential expression.
abstract  Expr getInDataEdge(int i)
          Return the specified in-coming data edge.
abstract  Expr[] getInDataEdgeArray()
          Use this method when you may be modifying an in-coming data edge while iterating over the edges.
abstract  int numInDataEdges()
          Return number of in-coming data edges.
static void setAnnotationLevel(int level)
          Set the depth to which a node displays it's annotations.
static void setReportLevel(int level)
          Set the depth to which a node displays its children.
 java.lang.String toString()
           
 void validate()
          Check this node for validity.
abstract  void visit(Predicate p)
          Process a node by calling its associated routine.
 
Methods inherited from class scale.common.Root
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayColorHint, getDisplayLabel, getDisplayName, getDisplayShapeHint, getDisplayString, getNodeCount, getNodeID, hasAnnotation, hasEqualAnnotation, hashCode, removeAnnotation, removeAnnotations, toStringAnnotations, toStringClass, toStringSpecial, trace, trace, trace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Note

protected Note()
Constructor for a CFG node instance.

Method Detail

getInDataEdgeArray

public abstract Expr[] getInDataEdgeArray()
Use this method when you may be modifying an in-coming data edge while iterating over the edges.

Returns:
an array of in-coming data edges.

getInDataEdge

public abstract Expr getInDataEdge(int i)
Return the specified in-coming data edge.


numInDataEdges

public abstract int numInDataEdges()
Return number of in-coming data edges.


changeInDataEdge

public abstract void changeInDataEdge(Expr oldExpr,
                                      Expr newExpr)
This method changes an incoming data edge to point to a new expression.

This method ensures that the node previously pointing to this one is updated properly, as well as, the node which will now point to this node.

Expr and Chord nodes have a fixed number of incoming edges with specific meaning applied to each. Hence, the edge being replaced is indicated by position.

Parameters:
oldExpr - is the expression to be replaced
newExpr - is the new expression

visit

public abstract void visit(Predicate p)
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(Note n)
   {
     ABC a = (ABC) n;
     ...
   }
 
Thus, the class that implements Predicate can call
   n.visit(this);
 
where n is a Note 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.

See Also:
Predicate

setReportLevel

public static void setReportLevel(int level)
Set the depth to which a node displays its children.


setAnnotationLevel

public static void setAnnotationLevel(int level)
Set the depth to which a node displays it's annotations.


toString

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

getChord

public final Chord getChord()
Return the Chord instance containing this Note.


validate

public void validate()
Check this node for validity. This method throws an error if the node is not linked properly.


getEssentialUse

public Note getEssentialUse()
Return this Note instance unless it is a non-essential expression. For Chord this method returns this. For a DualExpr or an address cast (e.g., ConversionExpr) this method returns the out data edge.


executionCostEstimate

public abstract int executionCostEstimate()
Return a relative cost estimate for executing this node.