Package com.tonic.analysis.ssa.cfg
Class IRBlock
- java.lang.Object
-
- com.tonic.analysis.ssa.cfg.IRBlock
-
public class IRBlock extends Object
A basic block in the SSA CFG, holding phi instructions ahead of its regular instructions.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddExceptionHandler(ExceptionHandler handler)Adds an exception handler to this block.voidaddInstruction(IRInstruction instruction)Adds an instruction to the end of this block.voidaddPhi(PhiInstruction phi)Adds a phi instruction to this block.voidaddPhiInstruction(PhiInstruction phi)Alias for addPhi to match common naming convention.voidaddPredecessor(IRBlock pred)Adds a predecessor block directly (for use in block duplication).voidaddSuccessor(IRBlock successor)Adds a successor block with a normal edge.voidaddSuccessor(IRBlock successor, EdgeType edgeType)Adds a successor block with the specified edge type.booleanequals(Object o)Identity byid.List<IRInstruction>getAllInstructions()Gets all instructions including phi instructions.intgetBytecodeOffset()EdgeTypegetEdgeType(IRBlock successor)Gets the edge type to a successor block.List<ExceptionHandler>getExceptionHandlers()intgetId()List<IRInstruction>getInstructions()IRMethodgetMethod()StringgetName()List<PhiInstruction>getPhiInstructions()Set<IRBlock>getPredecessors()Map<IRBlock,EdgeType>getSuccessorEdgeTypes()Set<IRBlock>getSuccessors()IRInstructiongetTerminator()Gets the terminator instruction of this block.inthashCode()booleanhasTerminator()Checks if this block has a terminator instruction.voidinsertInstruction(int index, IRInstruction instruction)Inserts an instruction at the specified index.booleanisEmpty()Checks if this block is empty.booleanisEntry()Checks if this is the entry block.booleanisExit()Checks if this is an exit block.voidremoveInstruction(IRInstruction instruction)Removes an instruction from this block.voidremovePhi(PhiInstruction phi)Removes a phi instruction from this block.voidremovePredecessor(IRBlock pred)Removes a predecessor block directly.voidremoveSuccessor(IRBlock successor)Removes a successor block and updates predecessor relationships.static voidresetIdCounter()Resets the ID counter for basic blocks.voidsetBytecodeOffset(int bytecodeOffset)voidsetMethod(IRMethod method)voidsetName(String name)voidsetTerminator(IRInstruction terminator)Sets the terminator instruction for this block.StringtoString()
-
-
-
Constructor Detail
-
IRBlock
public IRBlock()
Creates a new basic block with an auto-generated name.
-
IRBlock
public IRBlock(String name)
Creates a new basic block with the given name.- Parameters:
name- the block name
-
-
Method Detail
-
getId
public int getId()
- Returns:
- the id
-
getName
public String getName()
- Returns:
- the name
-
setName
public void setName(String name)
- Parameters:
name- the block name
-
getMethod
public IRMethod getMethod()
- Returns:
- the method
-
setMethod
public void setMethod(IRMethod method)
- Parameters:
method- the method this block belongs to
-
getPhiInstructions
public List<PhiInstruction> getPhiInstructions()
- Returns:
- the phi instructions
-
getInstructions
public List<IRInstruction> getInstructions()
- Returns:
- the instructions
-
getSuccessorEdgeTypes
public Map<IRBlock,EdgeType> getSuccessorEdgeTypes()
- Returns:
- the successor edge types
-
getExceptionHandlers
public List<ExceptionHandler> getExceptionHandlers()
- Returns:
- the exception handlers
-
getBytecodeOffset
public int getBytecodeOffset()
- Returns:
- the bytecode offset
-
setBytecodeOffset
public void setBytecodeOffset(int bytecodeOffset)
- Parameters:
bytecodeOffset- the original bytecode offset of the block start, or -1 if unknown
-
addPhi
public void addPhi(PhiInstruction phi)
Adds a phi instruction to this block.- Parameters:
phi- the phi instruction to add
-
addPhiInstruction
public void addPhiInstruction(PhiInstruction phi)
Alias for addPhi to match common naming convention.- Parameters:
phi- the phi instruction to add
-
removePhi
public void removePhi(PhiInstruction phi)
Removes a phi instruction from this block.- Parameters:
phi- the phi instruction to remove
-
addInstruction
public void addInstruction(IRInstruction instruction)
Adds an instruction to the end of this block.- Parameters:
instruction- the instruction to add
-
insertInstruction
public void insertInstruction(int index, IRInstruction instruction)Inserts an instruction at the specified index.- Parameters:
index- the position to insert atinstruction- the instruction to insert
-
removeInstruction
public void removeInstruction(IRInstruction instruction)
Removes an instruction from this block.- Parameters:
instruction- the instruction to remove
-
addSuccessor
public void addSuccessor(IRBlock successor)
Adds a successor block with a normal edge.- Parameters:
successor- the successor block
-
addSuccessor
public void addSuccessor(IRBlock successor, EdgeType edgeType)
Adds a successor block with the specified edge type.- Parameters:
successor- the successor blockedgeType- the type of edge
-
removeSuccessor
public void removeSuccessor(IRBlock successor)
Removes a successor block and updates predecessor relationships.- Parameters:
successor- the successor block to remove
-
getEdgeType
public EdgeType getEdgeType(IRBlock successor)
Gets the edge type to a successor block.- Parameters:
successor- the successor block- Returns:
- the edge type
-
addExceptionHandler
public void addExceptionHandler(ExceptionHandler handler)
Adds an exception handler to this block.- Parameters:
handler- the exception handler
-
getTerminator
public IRInstruction getTerminator()
Gets the terminator instruction of this block.- Returns:
- the terminator instruction, or null if none
-
setTerminator
public void setTerminator(IRInstruction terminator)
Sets the terminator instruction for this block.- Parameters:
terminator- the terminator instruction to set
-
addPredecessor
public void addPredecessor(IRBlock pred)
Adds a predecessor block directly (for use in block duplication).- Parameters:
pred- the predecessor block
-
removePredecessor
public void removePredecessor(IRBlock pred)
Removes a predecessor block directly.- Parameters:
pred- the predecessor block to remove
-
hasTerminator
public boolean hasTerminator()
Checks if this block has a terminator instruction.- Returns:
- true if block has a terminator, false otherwise
-
getAllInstructions
public List<IRInstruction> getAllInstructions()
Gets all instructions including phi instructions.- Returns:
- combined list of phi and regular instructions
-
isEmpty
public boolean isEmpty()
Checks if this block is empty.- Returns:
- true if no instructions, false otherwise
-
isEntry
public boolean isEntry()
Checks if this is the entry block.- Returns:
- true if this is the method's entry block, false otherwise
-
isExit
public boolean isExit()
Checks if this is an exit block.- Returns:
- true if block has no successors, false otherwise
-
resetIdCounter
public static void resetIdCounter()
Resets the ID counter for basic blocks.
-
-