Class BasicBlock<InsnType extends IInstruction>
- Type Parameters:
InsnType
-
- All Implemented Interfaces:
IBasicBlock<InsnType>
,Comparable<BasicBlock<InsnType>>
,Iterable<InsnType>
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionBasicBlock
(long base) Create a new empty basic block.BasicBlock
(long base, List<InsnType> insns, List<Long> dstOffsets, List<Long> irrdstOffsets, boolean unknownDst) Create a new basic block. -
Method Summary
Modifier and TypeMethodDescriptionvoid
DANGEROUS METHOD. Add an instruction into the block.void
DANGEROUS METHOD. Append an instruction to the block.void
addAll
(int index, Collection<InsnType> coll) DANGEROUS METHOD. Add instructions into the block.void
addAll
(Collection<InsnType> coll) DANGEROUS METHOD. Append instructions to the block.int
Get the total number of input edges to this block.int
boolean
canThrow()
int
get
(int index) Get the instruction at the specified index.get2
(int index) Get the instruction at the specified index, in an addressable form.long[]
Get a list of the addresses of each instruction in the block.long
getAddressOfInstruction
(int index) Retrieve a read-only iterable of regular and irregular input blocks.Get regular and irregular output blocks.Retrieve a read-only iterable of regular and irregular output blocks.long
getBase()
Address of first instruction in the block.Same asgetBranchingInstruction2(true, true)
.getBranchingInstruction2
(boolean includeBreaking, boolean includeCalling) Retrieve the branching instruction, if any.May return null if the custom object does not exist.long
Address following the last instruction of the block (ie, last exclusive address).long
Address of first instruction in the block.int
getIndexOfInstruction
(long address) int
Locate an instruction in the block.getInputBlock
(int index) Get a regular input block.Get the regular input blocks.Retrieve a read-only list of input blocks (regular).getInstruction
(long address) Get the instruction located at the exact address.Get a copy of the list of instructions that make up this basic block.getIrregularInputBlock
(int index) Get an irregular input block.Retrieve a read-only list of irregular input blocks.getIrregularOutputBlock
(int index) Get an irregular output block.Get irregular output blocks.Retrieve a read-only list of irregular output blocks.getLast()
Get the last instruction of the block.getLast2()
Get the last instruction of the block, in an addressable form.long
Address of last instruction in the block.getOutputBlock
(int index) Get a regular output block.Get the regular output blocks.Retrieve a read-only list of output blocks (regular).int
boolean
int
insize()
Get the number of regular input edges to this block.int
Get the number of irregular input edges to this block.int
boolean
isEmpty()
Determine if the block has 0 instruction.boolean
Check if the block has a single regular out-edge which points to itself.boolean
Check if the block has at least one regular out-edge pointing to itself.iterator()
int
outsize()
boolean
remove
(int index) Remove an instruction from the block as well as associated chains.boolean
removeData
(String name) DANGEROUS METHOD. Replace an instruction.void
Custom data is reset when a DFA is invalidated.void
setUnknownDst
(boolean unknownDst) shallowCopy
(boolean copyBlockReferences) Shallow duplication of a basic block.int
size()
Get the number of instructions in the block.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Method Details
-
shallowCopy
Shallow duplication of a basic block. USE THE RESULTING BLOCK WITH CAUTION. - Instructions references are copied
- Block references (edges) are optionally copied (the blocks are not)
- DFA data is not copied- Parameters:
copyBlockReferences
-- Returns:
- a new block
-
getBase
public long getBase()Description copied from interface:IBasicBlock
Address of first instruction in the block.- Specified by:
getBase
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getFirstAddress
public long getFirstAddress()Description copied from interface:IBasicBlock
Address of first instruction in the block.- Specified by:
getFirstAddress
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getLastAddress
public long getLastAddress()Description copied from interface:IBasicBlock
Address of last instruction in the block.- Specified by:
getLastAddress
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getEndAddress
public long getEndAddress()Description copied from interface:IBasicBlock
Address following the last instruction of the block (ie, last exclusive address).- Specified by:
getEndAddress
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getAddressOfInstruction
public long getAddressOfInstruction(int index) - Specified by:
getAddressOfInstruction
in interfaceIBasicBlock<InsnType extends IInstruction>
-
getAddresses
public long[] getAddresses()Get a list of the addresses of each instruction in the block.- Returns:
-
getIndexOfInstruction
public int getIndexOfInstruction(long address) - Specified by:
getIndexOfInstruction
in interfaceIBasicBlock<InsnType extends IInstruction>
- Parameters:
address
- instruction address- Returns:
- -1 if there is no instruction starting at the provided address
-
getIndexOfInstruction
Locate an instruction in the block. Comparison is done by identity.- Parameters:
insn
-- Returns:
- the instruction index, -1 if not found
-
canThrow
public boolean canThrow()- Specified by:
canThrow
in interfaceIBasicBlock<InsnType extends IInstruction>
-
size
public int size()Description copied from interface:IBasicBlock
Get the number of instructions in the block.- Specified by:
size
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
isEmpty
public boolean isEmpty()Description copied from interface:IBasicBlock
Determine if the block has 0 instruction.- Specified by:
isEmpty
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
get
Description copied from interface:IBasicBlock
Get the instruction at the specified index.- Specified by:
get
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
get2
Get the instruction at the specified index, in an addressable form.- Parameters:
index
-- Returns:
-
getLast
Get the last instruction of the block.Keep in mind that a branching instruction may NOT be the last instruction of a basic block if it supports delay-slots.
- Specified by:
getLast
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getSizeOfInstructions
public int getSizeOfInstructions()- Specified by:
getSizeOfInstructions
in interfaceIBasicBlock<InsnType extends IInstruction>
-
getLast2
Get the last instruction of the block, in an addressable form.Keep in mind that a branching instruction may NOT be the last instruction of a basic block if it supports delay-slots.
- Returns:
-
getInstruction
Description copied from interface:IBasicBlock
Get the instruction located at the exact address.- Specified by:
getInstruction
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getInstructions
Description copied from interface:IBasicBlock
Get a copy of the list of instructions that make up this basic block.- Specified by:
getInstructions
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getBranchingInstruction2
public AddressableInstruction<InsnType> getBranchingInstruction2(boolean includeBreaking, boolean includeCalling) Retrieve the branching instruction, if any. In the general case, it should not be assumed that the branching instruction must be the last instruction of a block. Example: on delay-slot architectures, a number of instructions may follow the branching instructions. They are included in the block. That means that the branching instruction, when there is one, may be the one/two/Nth-before-last.- Parameters:
includeBreaking
-includeCalling
-- Returns:
- the branching instruction+address, or null if none
-
getBranchingInstruction2
Same asgetBranchingInstruction2(true, true)
. -
remove
public boolean remove(int index) Remove an instruction from the block as well as associated chains. Usage is not recommended for public clients.This method may have the nasty side-effect of making the block empty. In that case, it returns true, and it is the caller's responsibility to refresh the CFG at their earliest convenience.
Another issue the client needs to take care of is the removal of the last instruction, which should only happen on very specific conditions, since the trailing instruction typically conditions the out-edges of the block.
- Parameters:
index
-- Returns:
- true if the CFG need refreshing
-
add
DANGEROUS METHOD. Append an instruction to the block.The instruction is appended to the block. The edges are not updated.
The caller is responsible for verifying the instruction (no null, no dup., etc.).
The caller is responsible for maintaining the consistency of the block and of the CFG.- Parameters:
insn
- the instruction to be appended
-
add
DANGEROUS METHOD. Add an instruction into the block.- Parameters:
index
-insn
-
-
addAll
DANGEROUS METHOD. Append instructions to the block.The instructions are appended to the block. The edges are not updated.
The caller is responsible for verifying the instructions (no null, no dup., etc.).
The caller is responsible for maintaining the consistency of the block and of the CFG.- Parameters:
coll
-
-
addAll
DANGEROUS METHOD. Add instructions into the block.- Parameters:
index
-coll
-
-
set
DANGEROUS METHOD. Replace an instruction. Sizes must match.Edges are not updated.
The caller is responsible for maintaining the consistency of the block and of the CFG.- Parameters:
index
-insn
- the instruction- Returns:
- the instruction that was replaced
-
setLast
-
insize
public int insize()Description copied from interface:IBasicBlock
Get the number of regular input edges to this block.- Specified by:
insize
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
irrinsize
public int irrinsize()Description copied from interface:IBasicBlock
Get the number of irregular input edges to this block.- Specified by:
irrinsize
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
allinsize
public int allinsize()Description copied from interface:IBasicBlock
Get the total number of input edges to this block.- Specified by:
allinsize
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getInputBlock
Description copied from interface:IBasicBlock
Get a regular input block.- Specified by:
getInputBlock
in interfaceIBasicBlock<InsnType extends IInstruction>
- Parameters:
index
- block index- Returns:
- a block
-
getInputBlocks
Description copied from interface:IBasicBlock
Get the regular input blocks.- Specified by:
getInputBlocks
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
- a copy of the list of regular input blocks
-
getIrregularInputBlock
Description copied from interface:IBasicBlock
Get an irregular input block.- Specified by:
getIrregularInputBlock
in interfaceIBasicBlock<InsnType extends IInstruction>
- Parameters:
index
- block index- Returns:
- a block
-
getIrregularInputBlocks
- Specified by:
getIrregularInputBlocks
in interfaceIBasicBlock<InsnType extends IInstruction>
-
getAllInputBlocks
- Specified by:
getAllInputBlocks
in interfaceIBasicBlock<InsnType extends IInstruction>
-
outsize
public int outsize()- Specified by:
outsize
in interfaceIBasicBlock<InsnType extends IInstruction>
-
irroutsize
public int irroutsize()- Specified by:
irroutsize
in interfaceIBasicBlock<InsnType extends IInstruction>
-
alloutsize
public int alloutsize()- Specified by:
alloutsize
in interfaceIBasicBlock<InsnType extends IInstruction>
-
getOutputBlock
Description copied from interface:IBasicBlock
Get a regular output block.- Specified by:
getOutputBlock
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getOutputBlocks
Description copied from interface:IBasicBlock
Get the regular output blocks.- Specified by:
getOutputBlocks
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
- a copy of the list of regular output blocks
-
getOutputOffsets
-
getIrregularOutputBlock
Description copied from interface:IBasicBlock
Get an irregular output block.- Specified by:
getIrregularOutputBlock
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getIrregularOutputBlocks
Description copied from interface:IBasicBlock
Get irregular output blocks.- Specified by:
getIrregularOutputBlocks
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
- a copy of the list of irregular output blocks
-
getIrregularOutputOffsets
-
getAllOutputBlocks
Description copied from interface:IBasicBlock
Get regular and irregular output blocks.- Specified by:
getAllOutputBlocks
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
- a copy of the list of all output blocks
-
getInputs
Retrieve a read-only list of input blocks (regular).NOTE: This method is faster than
getInputBlocks()
since it does not provide a copy of the list.- Specified by:
getInputs
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getInputOffsets
-
getIrregularInputs
Retrieve a read-only list of irregular input blocks.NOTE: This method is faster than
getIrregularInputBlocks()
since it does not provide a copy of the list.- Specified by:
getIrregularInputs
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getIrregularInputOffsets
-
getOutputs
Description copied from interface:IBasicBlock
Retrieve a read-only list of output blocks (regular).NOTE: This method is faster than
IBasicBlock.getOutputBlocks()
since it does not provide a copy of the list.- Specified by:
getOutputs
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getIrregularOutputs
Description copied from interface:IBasicBlock
Retrieve a read-only list of irregular output blocks.NOTE: This method is faster than
IBasicBlock.getIrregularOutputBlocks()
since it does not provide a copy of the list.- Specified by:
getIrregularOutputs
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getAllInputs
Description copied from interface:IBasicBlock
Retrieve a read-only iterable of regular and irregular input blocks.NOTE: This method is faster than
IBasicBlock.getAllInputBlocks()
since it does not provide a copy of the list.- Specified by:
getAllInputs
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
getAllOutputs
Description copied from interface:IBasicBlock
Retrieve a read-only iterable of regular and irregular output blocks.NOTE: This method is faster than
IBasicBlock.getAllOutputBlocks()
since it does not provide a copy of the list.- Specified by:
getAllOutputs
in interfaceIBasicBlock<InsnType extends IInstruction>
- Returns:
-
setUnknownDst
public void setUnknownDst(boolean unknownDst) -
hasUnknownDst
public boolean hasUnknownDst() -
isSelfReferencing
public boolean isSelfReferencing()Check if the block has at least one regular out-edge pointing to itself.- Returns:
-
isInfiniteLoop
public boolean isInfiniteLoop()Check if the block has a single regular out-edge which points to itself.- Returns:
-
toString
-
setData
Custom data is reset when a DFA is invalidated. -
getData
May return null if the custom object does not exist. -
removeData
-
iterator
- Specified by:
iterator
in interfaceIterable<InsnType extends IInstruction>
-
addressableInstructions
-
compareTo
- Specified by:
compareTo
in interfaceComparable<InsnType extends IInstruction>
-