Package EDU.purdue.cs.bloat.cfg
Class Subroutine
- java.lang.Object
-
- EDU.purdue.cs.bloat.cfg.Subroutine
-
public class Subroutine extends java.lang.ObjectSubroutine represents a subroutine (target of a jsr instruction) in java bytecode. Subroutines are used to implement the finally part of a try-catch-finally block.Each Subroutine belongs in a control flow graph, has an entry and exit block, and has a local variable that contains its return address. Additionally, it maintains a list of paths from blocks in which the subroutine is called to block that is executed after the subroutine returns.
Note that it is assumed that each subroutine ends with a ret. While this is true for bytecode generated by javac, it is not required.
- See Also:
AddressStoreStmt,Block
-
-
Constructor Summary
Constructors Constructor Description Subroutine(FlowGraph graph)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPath(Block callerBlock, Block returnBlock)Adds a path from the block before a Subroutine is called to a block after the subroutine is called.Blockentry()Returns the first Block in the subroutine.Blockexit()Returns the last Block in the subroutine.FlowGraphgraph()Returns the CFG that contains this subroutine.intnumPaths()Returns the number of places that this subroutine is called.java.util.Collectionpaths()Returns the paths (a Collection of two-element arrays of Blocks) that represent the Blocks that end in a call to this subroutine and the block that begin with the return address from this subroutine.BlockpathSource(Block block)Returns the "caller block" for a given "return block".BlockpathTarget(Block block)Returns the "return block" for a given "caller block".voidprint(java.io.PrintStream out)Prints a textual representation of this Subroutine.voidremoveAllPaths()Removes all caller-return paths.voidremovePath(Block callerBlock, Block returnBlock)Removes a path between a caller Block and a return Block.voidremovePathsContaining(Block block)Removes all paths involving block regardless of whether it is a calling (source) block or a returning (target) block.LocalVariablereturnAddress()Returns the local variable containing the return address of this subroutine.voidsetEntry(Block entry)Sets the entry Block for this Subroutine.voidsetExit(Block exit)Sets the exit Block for this Subroutine.voidsetReturnAddress(LocalVariable returnAddress)Sets the address (stored in a LocalVariable) to which this subroutine will return once it is finished.java.lang.StringtoString()
-
-
-
Constructor Detail
-
Subroutine
public Subroutine(FlowGraph graph)
Constructor.- Parameters:
graph- The CFG containing the block.
-
-
Method Detail
-
returnAddress
public LocalVariable returnAddress()
Returns the local variable containing the return address of this subroutine.
-
setReturnAddress
public void setReturnAddress(LocalVariable returnAddress)
Sets the address (stored in a LocalVariable) to which this subroutine will return once it is finished.- Parameters:
returnAddress- Local variable that stores the address to which the subroutine returns when it is completed.- See Also:
Tree.visit_astore(EDU.purdue.cs.bloat.editor.Instruction)
-
numPaths
public int numPaths()
Returns the number of places that this subroutine is called.
-
paths
public java.util.Collection paths()
Returns the paths (a Collection of two-element arrays of Blocks) that represent the Blocks that end in a call to this subroutine and the block that begin with the return address from this subroutine.
-
graph
public FlowGraph graph()
Returns the CFG that contains this subroutine.
-
removePathsContaining
public void removePathsContaining(Block block)
Removes all paths involving block regardless of whether it is a calling (source) block or a returning (target) block.
-
removePath
public void removePath(Block callerBlock, Block returnBlock)
Removes a path between a caller Block and a return Block.
-
removeAllPaths
public void removeAllPaths()
Removes all caller-return paths.
-
addPath
public void addPath(Block callerBlock, Block returnBlock)
Adds a path from the block before a Subroutine is called to a block after the subroutine is called. If the callerBlock is already associated with a returnBlock, the old returnBlock is replaced.- Parameters:
callerBlock- The block in which the subroutine is called. This Block ends with a jsr to this subroutine.returnBlock- The block to which the subroutine returns. This Block begins at the return address of this subroutine.
-
pathTarget
public Block pathTarget(Block block)
Returns the "return block" for a given "caller block".
-
pathSource
public Block pathSource(Block block)
Returns the "caller block" for a given "return block".
-
setEntry
public void setEntry(Block entry)
Sets the entry Block for this Subroutine.
-
setExit
public void setExit(Block exit)
Sets the exit Block for this Subroutine.
-
entry
public Block entry()
Returns the first Block in the subroutine.
-
exit
public Block exit()
Returns the last Block in the subroutine.
-
print
public void print(java.io.PrintStream out)
Prints a textual representation of this Subroutine.- Parameters:
out- The PrintStream to which to print.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-