|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcfg.BasicBlock
public class BasicBlock
A class representing a basic block, which is an individual node in the control flow graph. Each basic block is made up of a label (for control transfers targetting this basic block) and a list of Three-Address Code (TAC) instructions. For basic blocks that are not reached via a control transfer, the label is null.
| Constructor Summary | |
|---|---|
BasicBlock(int startLineNum,
int loopCnt,
int ifCnt)
BasicBlock constructor |
|
| Method Summary | |
|---|---|
void |
addComment(java.lang.String comment)
Add a comment to basic block (for debugging) (this can be called multiple times for multi-line comments) |
void |
addInEdge(BasicBlock b)
Add an incoming edge from another control flow block Also adds outgoing edge from parameter to this block |
void |
addInst(TACInst inst)
Append instruction into basic block Throws exception if attempting to place an instruction after an IF (which should terminate block) |
void |
addInst(TACInst inst,
int n)
Add instruction into specified place in the basic block Shifts instructions at specified position to the right one Throws exception if n is greater than the size or attempt to place an instruction after an IF (which should terminate block) |
void |
addOutEdge(BasicBlock b)
Add an outgoing edge to another control flow block Also adds incoming edge from this block to parameter |
void |
check()
Check block for errors throws an exception if block is malformed |
boolean |
containsInEdge(BasicBlock bb)
Does this block contain another block as an in edge? |
boolean |
containsOutEdge(BasicBlock bb)
Does this block contain another block as an out edge? |
java.lang.String |
getComments()
Get comments for instruction |
java.lang.String |
getFullString()
Returns string representation of entire basic block |
int |
getID()
Get the identifier of this basic block |
int |
getIfCnt()
Get the if count for this block, i.e., number of if statements this block is contained in (note: predicate considered part of the if statement) |
int |
getLoopCnt()
Get the loop count for this block, i.e., number of loops this block is contained in (note: predicate considered part of the loop) |
BasicBlock |
getNthInEdge(int n)
Get nth incoming edge (basic block) |
TACInst |
getNthInst(int n)
Get the nth instruction Note: throws an exception if there aren't at least n+1 instructions |
BasicBlock |
getNthOutEdge(int n)
Get nth outgoing edge (basic block) |
int |
getNumInEdges()
Get number of incoming edges |
int |
getNumInsn()
Get the number of instructions at this basic block |
int |
getNumOutEdges()
Get number of outgoing edges |
java.util.Iterator<BasicBlock> |
getOrderedBlocks()
Get ordered list of blocks -- should only be called for starting blocks, otherwise exception is thrown |
int |
getStartLineNum()
Get the starting source line number of this basic block |
int |
indexOf(TACInst inst)
Get the index of some instruction |
void |
print()
Prints basic block -- for debugging |
void |
printAll()
Prints basic block and all connected basic blocks -- for debugging Must be called using entrance block as reference object |
void |
removeAllInEdges()
Remove all incoming edges from other control flow blocks Also removes outgoing edges from source basic blocks |
void |
removeAllOutEdges()
Remove all outgoing edges to other control flow blocks Also removes incoming edges in source basic blocks |
void |
removeComments()
Remove comments from an instruction |
void |
removeInEdge(BasicBlock b)
Remove an incoming edge to another control flow block Also removes outgoing edge from parameter to this block |
void |
removeNthInst(int n)
Remove the nth instruction Note: throws an exception if there aren't at least n+1 instructions |
void |
removeOutEdge(BasicBlock b)
Remove an outgoing edge to another control flow block Also removes incoming edge from parameter to this block |
void |
setIfCnt(int ifCnt)
Set the if count for this block, i.e., number of if statements this block is contained in (note: predicate considered part of the if) |
void |
setLoopCnt(int loopCnt)
Set the loop count for this block, i.e., number of loops this block is contained in (note: predicate considered part of the loop) |
void |
setNthInst(int n,
TACInst inst)
Set the nth instruction -- replaces the previous nth instruction with the specified instruction Note: throws an exception if there aren't at least n+1 instructions |
java.lang.String |
toString()
Returns string identifier for basic block |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public BasicBlock(int startLineNum,
int loopCnt,
int ifCnt)
startLineNum - starting source line number of this block
(for debugging -- does not have to be exact)loopCnt - loop count (# loops block is contained in --
note: predicate considered part of loop)ifCnt - if count (# if statements block is contained in --
note: predicate considered part of if statement)| Method Detail |
|---|
public int getID()
public int getStartLineNum()
public void addInst(TACInst inst)
inst - three-address code (TAC) instruction
public void addInst(TACInst inst,
int n)
inst - three-address code (TAC) instructionn - position to placepublic int getNumInsn()
public int indexOf(TACInst inst)
inst - instruction to find the index of
public TACInst getNthInst(int n)
n - index of instruction to get
public void setNthInst(int n,
TACInst inst)
n - index of instruction to getinst - replacement instructionpublic void removeNthInst(int n)
n - index of instruction to removepublic void addInEdge(BasicBlock b)
b - incoming basic blockpublic void addOutEdge(BasicBlock b)
b - outgoing basic blockpublic void removeInEdge(BasicBlock b)
b - incoming basic blockpublic void removeOutEdge(BasicBlock b)
b - outgoing basic blockpublic void removeAllInEdges()
public void removeAllOutEdges()
public BasicBlock getNthInEdge(int n)
n - index of incoming edge to get
public BasicBlock getNthOutEdge(int n)
n - index of outgoing edge to get
public int getNumInEdges()
public int getNumOutEdges()
public boolean containsInEdge(BasicBlock bb)
bb - block to check if contains
public boolean containsOutEdge(BasicBlock bb)
bb - block to check if contains
public int getLoopCnt()
public void setLoopCnt(int loopCnt)
loopCnt - new loop countpublic int getIfCnt()
public void setIfCnt(int ifCnt)
ifCnt - new if countpublic void check()
public java.lang.String getComments()
public void addComment(java.lang.String comment)
comment - comment to addpublic void removeComments()
public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String getFullString()
public void print()
public java.util.Iterator<BasicBlock> getOrderedBlocks()
public void printAll()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||