use of com.taobao.android.dx.rop.code.BasicBlockList in project atlas by alibaba.
the class StdCatchBuilder method getCatchTypes.
/** {@inheritDoc} */
public HashSet<Type> getCatchTypes() {
HashSet<Type> result = new HashSet<Type>(20);
BasicBlockList blocks = method.getBlocks();
int size = blocks.size();
for (int i = 0; i < size; i++) {
BasicBlock block = blocks.get(i);
TypeList catches = block.getLastInsn().getCatches();
int catchSize = catches.size();
for (int j = 0; j < catchSize; j++) {
result.add(catches.getType(j));
}
}
return result;
}
use of com.taobao.android.dx.rop.code.BasicBlockList in project atlas by alibaba.
the class BlockAddresses method setupArrays.
/**
* Sets up the address arrays.
*/
private void setupArrays(RopMethod method) {
BasicBlockList blocks = method.getBlocks();
int sz = blocks.size();
for (int i = 0; i < sz; i++) {
BasicBlock one = blocks.get(i);
int label = one.getLabel();
Insn insn = one.getInsns().get(0);
starts[label] = new CodeAddress(insn.getPosition());
SourcePosition pos = one.getLastInsn().getPosition();
lasts[label] = new CodeAddress(pos);
ends[label] = new CodeAddress(pos);
}
}
use of com.taobao.android.dx.rop.code.BasicBlockList in project atlas by alibaba.
the class SsaToRop method convertBasicBlocks.
/**
* @return rop-form basic block list
*/
private BasicBlockList convertBasicBlocks() {
ArrayList<SsaBasicBlock> blocks = ssaMeth.getBlocks();
// Exit block may be null.
SsaBasicBlock exitBlock = ssaMeth.getExitBlock();
ssaMeth.computeReachability();
int ropBlockCount = ssaMeth.getCountReachableBlocks();
// Don't count the exit block, if it exists and is reachable.
ropBlockCount -= (exitBlock != null && exitBlock.isReachable()) ? 1 : 0;
BasicBlockList result = new BasicBlockList(ropBlockCount);
// Convert all the reachable blocks except the exit block.
int ropBlockIndex = 0;
for (SsaBasicBlock b : blocks) {
if (b.isReachable() && b != exitBlock) {
result.set(ropBlockIndex++, convertBasicBlock(b));
}
}
// The exit block, which is discarded, must do nothing.
if (exitBlock != null && exitBlock.getInsns().size() != 0) {
throw new RuntimeException("Exit block must have no insns when leaving SSA form");
}
return result;
}
use of com.taobao.android.dx.rop.code.BasicBlockList in project atlas by alibaba.
the class SsaBasicBlock method newFromRop.
/**
* Creates a new SSA basic block from a ROP form basic block.
*
* @param rmeth original method
* @param basicBlockIndex index this block will have
* @param parent method of this block predecessor set will be
* updated
* @return new instance
*/
public static SsaBasicBlock newFromRop(RopMethod rmeth, int basicBlockIndex, final SsaMethod parent) {
BasicBlockList ropBlocks = rmeth.getBlocks();
BasicBlock bb = ropBlocks.get(basicBlockIndex);
SsaBasicBlock result = new SsaBasicBlock(basicBlockIndex, bb.getLabel(), parent);
InsnList ropInsns = bb.getInsns();
result.insns.ensureCapacity(ropInsns.size());
for (int i = 0, sz = ropInsns.size(); i < sz; i++) {
result.insns.add(new NormalSsaInsn(ropInsns.get(i), result));
}
result.predecessors = SsaMethod.bitSetFromLabelList(ropBlocks, rmeth.labelToPredecessors(bb.getLabel()));
result.successors = SsaMethod.bitSetFromLabelList(ropBlocks, bb.getSuccessors());
result.successorList = SsaMethod.indexListFromLabelList(ropBlocks, bb.getSuccessors());
if (result.successorList.size() != 0) {
int primarySuccessor = bb.getPrimarySuccessor();
result.primarySuccessor = (primarySuccessor < 0) ? -1 : ropBlocks.indexOfLabel(primarySuccessor);
}
return result;
}
use of com.taobao.android.dx.rop.code.BasicBlockList in project atlas by alibaba.
the class SsaMethod method convertRopToSsaBlocks.
private void convertRopToSsaBlocks(RopMethod rmeth) {
BasicBlockList ropBlocks = rmeth.getBlocks();
int sz = ropBlocks.size();
blocks = new ArrayList<SsaBasicBlock>(sz + 2);
for (int i = 0; i < sz; i++) {
SsaBasicBlock sbb = SsaBasicBlock.newFromRop(rmeth, i, this);
blocks.add(sbb);
}
// Add an no-op entry block.
int origEntryBlockIndex = rmeth.getBlocks().indexOfLabel(rmeth.getFirstLabel());
SsaBasicBlock entryBlock = blocks.get(origEntryBlockIndex).insertNewPredecessor();
entryBlockIndex = entryBlock.getIndex();
// This gets made later.
exitBlockIndex = -1;
}
Aggregations