本文整理汇总了Java中com.android.dx.rop.code.Insn类的典型用法代码示例。如果您正苦于以下问题:Java Insn类的具体用法?Java Insn怎么用?Java Insn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Insn类属于com.android.dx.rop.code包,在下文中一共展示了Insn类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupArrays
import com.android.dx.rop.code.Insn; //导入依赖的package包/类
/**
* 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);
}
}
示例2: getRegs
import com.android.dx.rop.code.Insn; //导入依赖的package包/类
/**
* Gets the complete register list (result and sources) out of a
* given rop instruction. For insns that are commutative, have
* two register sources, and have a source equal to the result,
* place that source first.
*
* @param insn {@code non-null;} instruction in question
* @param resultReg {@code null-ok;} the real result to use (ignore the insn's)
* @return {@code non-null;} the instruction's complete register list
*/
private static RegisterSpecList getRegs(Insn insn,
RegisterSpec resultReg) {
RegisterSpecList regs = insn.getSources();
if (insn.getOpcode().isCommutative()
&& (regs.size() == 2)
&& (resultReg.getReg() == regs.get(1).getReg())) {
/*
* For commutative ops which have two register sources,
* if the second source is the same register as the result,
* swap the sources so that an opcode of form 12x can be selected
* instead of one of form 23x
*/
regs = RegisterSpecList.make(regs.get(1), regs.get(0));
}
if (resultReg == null) {
return regs;
}
return regs.withFirst(resultReg);
}
示例3: getNextMoveResultPseudo
import com.android.dx.rop.code.Insn; //导入依赖的package包/类
/**
* Looks forward to the current block's primary successor, returning
* the RegisterSpec of the result of the move-result-pseudo at the
* top of that block or null if none.
*
* @return {@code null-ok;} result of move-result-pseudo at the beginning of
* primary successor
*/
private RegisterSpec getNextMoveResultPseudo()
{
int label = block.getPrimarySuccessor();
if (label < 0) {
return null;
}
Insn insn
= method.getBlocks().labelToBlock(label).getInsns().get(0);
if (insn.getOpcode().getOpcode() != RegOps.MOVE_RESULT_PSEUDO) {
return null;
} else {
return insn.getResult();
}
}
示例4: isRegALocal
import com.android.dx.rop.code.Insn; //导入依赖的package包/类
/**
* Checks to see if the given SSA reg is ever associated with a local
* local variable. Each SSA reg may be associated with at most one
* local var.
*
* @param spec {@code non-null;} ssa reg
* @return true if reg is ever associated with a local
*/
public boolean isRegALocal(RegisterSpec spec) {
SsaInsn defn = getDefinitionForRegister(spec.getReg());
if (defn == null) {
// version 0 registers are never used as locals
return false;
}
// Does the definition have a local associated with it?
if (defn.getLocalAssignment() != null) return true;
// If not, is there a mark-local insn?
for (SsaInsn use : getUseListForRegister(spec.getReg())) {
Insn insn = use.getOriginalRopInsn();
if (insn != null
&& insn.getOpcode().getOpcode() == RegOps.MARK_LOCAL) {
return true;
}
}
return false;
}
示例5: calculateParamsAreInOrder
import com.android.dx.rop.code.Insn; //导入依赖的package包/类
/**
* Checks to see if the move-param instructions that occur in this
* method happen to slot the params in an order at the top of the
* stack frame that matches dalvik's calling conventions. This will
* alway result in "true" for methods that have run through the
* SSA optimizer.
*
* @param paramSize size, in register units, of all the parameters
* to this method
*/
private static boolean calculateParamsAreInOrder(RopMethod method,
final int paramSize) {
final boolean[] paramsAreInOrder = { true };
final int initialRegCount = method.getBlocks().getRegCount();
/*
* We almost could just check the first block here, but the
* {@code cf} layer will put in a second move-param in a
* subsequent block in the case of synchronized methods.
*/
method.getBlocks().forEachInsn(new Insn.BaseVisitor() {
@Override
public void visitPlainCstInsn(PlainCstInsn insn) {
if (insn.getOpcode().getOpcode()== RegOps.MOVE_PARAM) {
int param =
((CstInteger) insn.getConstant()).getValue();
paramsAreInOrder[0] = paramsAreInOrder[0]
&& ((initialRegCount - paramSize + param)
== insn.getResult().getReg());
}
}
});
return paramsAreInOrder[0];
}
示例6: addIntroductionIfNecessary
import com.android.dx.rop.code.Insn; //导入依赖的package包/类
/**
* Adds a {@link LocalStart} to the output if the given
* instruction in fact introduces a local variable.
*
* @param insn {@code non-null;} instruction in question
*/
public void addIntroductionIfNecessary(Insn insn) {
RegisterSpec spec = locals.getAssignment(insn);
if (spec != null) {
addOutput(new LocalStart(insn.getPosition(), spec));
}
}
示例7: filterMoveReturnAddressInsns
import com.android.dx.rop.code.Insn; //导入依赖的package包/类
/**
* Removes all {@code move-return-address} instructions, returning a new
* {@code InsnList} if necessary. The {@code move-return-address}
* insns are dead code after subroutines have been inlined.
*
* @param insns {@code InsnList} that may contain
* {@code move-return-address} insns
* @return {@code InsnList} with {@code move-return-address} removed
*/
private InsnList filterMoveReturnAddressInsns(InsnList insns) {
int sz;
int newSz = 0;
// First see if we need to filter, and if so what the new size will be
sz = insns.size();
for (int i = 0; i < sz; i++) {
if (insns.get(i).getOpcode() != Rops.MOVE_RETURN_ADDRESS) {
newSz++;
}
}
if (newSz == sz) {
return insns;
}
// Make a new list without the MOVE_RETURN_ADDRESS insns
InsnList newInsns = new InsnList(newSz);
int newIndex = 0;
for (int i = 0; i < sz; i++) {
Insn insn = insns.get(i);
if (insn.getOpcode() != Rops.MOVE_RETURN_ADDRESS) {
newInsns.set(newIndex++, insn);
}
}
newInsns.setImmutable();
return newInsns;
}
示例8: RopperMachine
import com.android.dx.rop.code.Insn; //导入依赖的package包/类
/**
* Constructs an instance.
*
* @param ropper {@code non-null;} ropper controlling this instance
* @param method {@code non-null;} method being converted
* @param advice {@code non-null;} translation advice to use
* @param methods {@code non-null;} list of methods defined by the class
* that defines {@code method}.
*/
public RopperMachine(Ropper ropper, ConcreteMethod method,
TranslationAdvice advice, MethodList methods) {
super(method.getEffectiveDescriptor());
if (methods == null) {
throw new NullPointerException("methods == null");
}
if (ropper == null) {
throw new NullPointerException("ropper == null");
}
if (advice == null) {
throw new NullPointerException("advice == null");
}
this.ropper = ropper;
this.method = method;
this.methods = methods;
this.advice = advice;
this.maxLocals = method.getMaxLocals();
this.insns = new ArrayList<Insn>(25);
this.catches = null;
this.catchesUsed = false;
this.returns = false;
this.primarySuccessorIndex = -1;
this.extraBlockCount = 0;
this.blockCanThrow = false;
this.returnOp = null;
this.returnPosition = null;
}
示例9: replaceBranches
import com.android.dx.rop.code.Insn; //导入依赖的package包/类
/**
* Replaces branches that have constant conditions with gotos
*/
private void replaceBranches() {
for (SsaInsn insn : branchWorklist) {
// Find if a successor block is never executed
int oldSuccessor = -1;
SsaBasicBlock block = insn.getBlock();
int successorSize = block.getSuccessorList().size();
for (int i = 0; i < successorSize; i++) {
int successorBlock = block.getSuccessorList().get(i);
if (!executableBlocks.get(successorBlock)) {
oldSuccessor = successorBlock;
}
}
/*
* Prune branches that have already been handled and ones that no
* longer have constant conditions (no nonexecutable successors)
*/
if (successorSize != 2 || oldSuccessor == -1) continue;
// Replace branch with goto
Insn originalRopInsn = insn.getOriginalRopInsn();
block.replaceLastInsn(new PlainInsn(Rops.GOTO,
originalRopInsn.getPosition(), null, RegisterSpecList.EMPTY));
block.removeSuccessor(oldSuccessor);
}
}
示例10: tryReplacingWithConstant
import com.android.dx.rop.code.Insn; //导入依赖的package包/类
/**
* Tries to replace an instruction with a const instruction. The given
* instruction must have a constant result for it to be replaced.
*
* @param insn {@code non-null;} instruction to try to replace
* @return true if the instruction was replaced
*/
private boolean tryReplacingWithConstant(NormalSsaInsn insn) {
Insn originalRopInsn = insn.getOriginalRopInsn();
Rop opcode = originalRopInsn.getOpcode();
RegisterSpec result = insn.getResult();
if (result != null && !ssaMeth.isRegALocal(result) &&
opcode.getOpcode() != RegOps.CONST) {
TypeBearer type = insn.getResult().getTypeBearer();
if (type.isConstant() && type.getBasicType() == Type.BT_INT) {
// Replace the instruction with a constant
replacePlainInsn(insn, RegisterSpecList.EMPTY,
RegOps.CONST, (Constant) type);
// Remove the source as well if this is a move-result-pseudo
if (opcode.getOpcode() == RegOps.MOVE_RESULT_PSEUDO) {
int pred = insn.getBlock().getPredecessors().nextSetBit(0);
ArrayList<SsaInsn> predInsns =
ssaMeth.getBlocks().get(pred).getInsns();
NormalSsaInsn sourceInsn =
(NormalSsaInsn) predInsns.get(predInsns.size()-1);
replacePlainInsn(sourceInsn, RegisterSpecList.EMPTY,
RegOps.GOTO, null);
}
return true;
}
}
return false;
}
示例11: replaceLastInsn
import com.android.dx.rop.code.Insn; //导入依赖的package包/类
/**
* Replaces the last insn in this block. The provided insn must have
* some branchingness.
*
* @param insn {@code non-null;} rop-form insn to add, which must branch.
*/
public void replaceLastInsn(Insn insn) {
if (insn.getOpcode().getBranchingness() == Rop.BRANCH_NONE) {
throw new IllegalArgumentException("last insn must branch");
}
SsaInsn oldInsn = insns.get(insns.size() - 1);
SsaInsn newInsn = SsaInsn.makeFromRop(insn, this);
insns.set(insns.size() - 1, newInsn);
parent.onInsnRemoved(oldInsn);
parent.onInsnAdded(newInsn);
}
示例12: deleteInsns
import com.android.dx.rop.code.Insn; //导入依赖的package包/类
/**
* Deletes all insns in the set from this method.
*
* @param deletedInsns {@code non-null;} insns to delete
*/
public void deleteInsns(Set<SsaInsn> deletedInsns) {
for (SsaBasicBlock block : getBlocks()) {
ArrayList<SsaInsn> insns = block.getInsns();
for (int i = insns.size() - 1; i >= 0; i--) {
SsaInsn insn = insns.get(i);
if (deletedInsns.contains(insn)) {
onInsnRemoved(insn);
insns.remove(i);
}
}
// Check to see if we need to add a GOTO
int insnsSz = insns.size();
SsaInsn lastInsn = (insnsSz == 0) ? null : insns.get(insnsSz - 1);
if (block != getExitBlock() && (insnsSz == 0
|| lastInsn.getOriginalRopInsn() == null
|| lastInsn.getOriginalRopInsn().getOpcode()
.getBranchingness() == Rop.BRANCH_NONE)) {
// We managed to eat a throwable insn
Insn gotoInsn = new PlainInsn(Rops.GOTO,
SourcePosition.NO_INFO, null, RegisterSpecList.EMPTY);
insns.add(SsaInsn.makeFromRop(gotoInsn, block));
// Remove secondary successors from this block
BitSet succs = block.getSuccessors();
for (int i = succs.nextSetBit(0); i >= 0;
i = succs.nextSetBit(i + 1)) {
if (i != block.getPrimarySuccessorIndex()) {
block.removeSuccessor(i);
}
}
}
}
}
示例13: RopperMachine
import com.android.dx.rop.code.Insn; //导入依赖的package包/类
/**
* Constructs an instance.
*
* @param ropper {@code non-null;} ropper controlling this instance
* @param method {@code non-null;} method being converted
* @param advice {@code non-null;} translation advice to use
*/
public RopperMachine(Ropper ropper, ConcreteMethod method,
TranslationAdvice advice) {
super(method.getEffectiveDescriptor());
if (ropper == null) {
throw new NullPointerException("ropper == null");
}
if (advice == null) {
throw new NullPointerException("advice == null");
}
this.ropper = ropper;
this.method = method;
this.advice = advice;
this.maxLocals = method.getMaxLocals();
this.insns = new ArrayList<Insn>(25);
this.catches = null;
this.catchesUsed = false;
this.returns = false;
this.primarySuccessorIndex = -1;
this.extraBlockCount = 0;
this.blockCanThrow = false;
this.returnOp = null;
this.returnPosition = null;
}