com.android.dx.rop.code.PlainCstInsn Java Examples
The following examples show how to use
com.android.dx.rop.code.PlainCstInsn.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RopTranslator.java From Box with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void visitPlainCstInsn(PlainCstInsn insn) { SourcePosition pos = insn.getPosition(); Dop opcode = RopToDop.dopFor(insn); Rop rop = insn.getOpcode(); int ropOpcode = rop.getOpcode(); DalvInsn di; if (rop.getBranchingness() != Rop.BRANCH_NONE) { throw new RuntimeException("shouldn't happen"); } if (ropOpcode == RegOps.MOVE_PARAM) { if (!paramsAreInOrder) { /* * Parameters are not in order at the top of the reg space. * We need to add moves. */ RegisterSpec dest = insn.getResult(); int param = ((CstInteger) insn.getConstant()).getValue(); RegisterSpec source = RegisterSpec.make(regCount - paramSize + param, dest.getType()); di = new SimpleInsn(opcode, pos, RegisterSpecList.make(dest, source)); addOutput(di); } } else { // No moves required for the parameters RegisterSpecList regs = getRegs(insn); di = new CstInsn(opcode, pos, regs, insn.getConstant()); addOutput(di); } }
Example #2
Source File: RopTranslator.java From buck with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ public void visitPlainCstInsn(PlainCstInsn insn) { SourcePosition pos = insn.getPosition(); Dop opcode = RopToDop.dopFor(insn); Rop rop = insn.getOpcode(); int ropOpcode = rop.getOpcode(); DalvInsn di; if (rop.getBranchingness() != Rop.BRANCH_NONE) { throw new RuntimeException("shouldn't happen"); } if (ropOpcode == RegOps.MOVE_PARAM) { if (!paramsAreInOrder) { /* * Parameters are not in order at the top of the reg space. * We need to add moves. */ RegisterSpec dest = insn.getResult(); int param = ((CstInteger) insn.getConstant()).getValue(); RegisterSpec source = RegisterSpec.make(regCount - paramSize + param, dest.getType()); di = new SimpleInsn(opcode, pos, RegisterSpecList.make(dest, source)); addOutput(di); } } else { // No moves required for the parameters RegisterSpecList regs = getRegs(insn); di = new CstInsn(opcode, pos, regs, insn.getConstant()); addOutput(di); } }
Example #3
Source File: RopTranslator.java From buck with Apache License 2.0 | 5 votes |
/** * 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]; }
Example #4
Source File: Code.java From dexmaker with Apache License 2.0 | 5 votes |
private void loadConstantInternal(Local target, Object value) { Rop rop = value == null ? Rops.CONST_OBJECT_NOTHROW : Rops.opConst(target.type.ropType); if (rop.getBranchingness() == BRANCH_NONE) { addInstruction(new PlainCstInsn(rop, sourcePosition, target.spec(), RegisterSpecList.EMPTY, Constants.getConstant(value))); } else { addInstruction(new ThrowingCstInsn(rop, sourcePosition, RegisterSpecList.EMPTY, catches, Constants.getConstant(value))); moveResult(target, true); } }
Example #5
Source File: RopTranslator.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void visitPlainCstInsn(PlainCstInsn insn) { SourcePosition pos = insn.getPosition(); Dop opcode = RopToDop.dopFor(insn); Rop rop = insn.getOpcode(); int ropOpcode = rop.getOpcode(); DalvInsn di; if (rop.getBranchingness() != Rop.BRANCH_NONE) { throw new RuntimeException("shouldn't happen"); } if (ropOpcode == RegOps.MOVE_PARAM) { if (!paramsAreInOrder) { /* * Parameters are not in order at the top of the reg space. * We need to add moves. */ RegisterSpec dest = insn.getResult(); int param = ((CstInteger) insn.getConstant()).getValue(); RegisterSpec source = RegisterSpec.make(regCount - paramSize + param, dest.getType()); di = new SimpleInsn(opcode, pos, RegisterSpecList.make(dest, source)); addOutput(di); } } else { // No moves required for the parameters RegisterSpecList regs = getRegs(insn); di = new CstInsn(opcode, pos, regs, insn.getConstant()); addOutput(di); } }
Example #6
Source File: RopTranslator.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * 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]; }
Example #7
Source File: Code.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Copies the constant value {@code value} to {@code target}. The constant * must be a primitive, String, Class, TypeId, or null. */ public <T> void loadConstant(Local<T> target, T value) { Rop rop = value == null ? Rops.CONST_OBJECT_NOTHROW : Rops.opConst(target.type.ropType); if (rop.getBranchingness() == BRANCH_NONE) { addInstruction(new PlainCstInsn(rop, sourcePosition, target.spec(), RegisterSpecList.EMPTY, Constants.getConstant(value))); } else { addInstruction(new ThrowingCstInsn(rop, sourcePosition, RegisterSpecList.EMPTY, catches, Constants.getConstant(value))); moveResult(target, true); } }
Example #8
Source File: RopTranslator.java From Box with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void visitPlainCstInsn(PlainCstInsn insn) { SourcePosition pos = insn.getPosition(); Dop opcode = RopToDop.dopFor(insn); Rop rop = insn.getOpcode(); int ropOpcode = rop.getOpcode(); DalvInsn di; if (rop.getBranchingness() != Rop.BRANCH_NONE) { throw new RuntimeException("shouldn't happen"); } if (ropOpcode == RegOps.MOVE_PARAM) { if (!paramsAreInOrder) { /* * Parameters are not in order at the top of the reg space. * We need to add moves. */ RegisterSpec dest = insn.getResult(); int param = ((CstInteger) insn.getConstant()).getValue(); RegisterSpec source = RegisterSpec.make(regCount - paramSize + param, dest.getType()); di = new SimpleInsn(opcode, pos, RegisterSpecList.make(dest, source)); addOutput(di); } } else { // No moves required for the parameters RegisterSpecList regs = getRegs(insn); di = new CstInsn(opcode, pos, regs, insn.getConstant()); addOutput(di); } }
Example #9
Source File: RopTranslator.java From Box with Apache License 2.0 | 5 votes |
/** * 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]; }
Example #10
Source File: RopTranslator.java From Box with Apache License 2.0 | 5 votes |
/** * 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]; }
Example #11
Source File: ConstCollector.java From Box with Apache License 2.0 | 4 votes |
/** * Applies the optimization. */ private void run() { int regSz = ssaMeth.getRegCount(); ArrayList<TypedConstant> constantList = getConstsSortedByCountUse(); int toCollect = Math.min(constantList.size(), MAX_COLLECTED_CONSTANTS); SsaBasicBlock start = ssaMeth.getEntryBlock(); // Constant to new register containing the constant HashMap<TypedConstant, RegisterSpec> newRegs = new HashMap<TypedConstant, RegisterSpec> (toCollect); for (int i = 0; i < toCollect; i++) { TypedConstant cst = constantList.get(i); RegisterSpec result = RegisterSpec.make(ssaMeth.makeNewSsaReg(), cst); Rop constRop = Rops.opConst(cst); if (constRop.getBranchingness() == Rop.BRANCH_NONE) { start.addInsnToHead( new PlainCstInsn(Rops.opConst(cst), SourcePosition.NO_INFO, result, RegisterSpecList.EMPTY, cst)); } else { // We need two new basic blocks along with the new insn SsaBasicBlock entryBlock = ssaMeth.getEntryBlock(); SsaBasicBlock successorBlock = entryBlock.getPrimarySuccessor(); // Insert a block containing the const insn. SsaBasicBlock constBlock = entryBlock.insertNewSuccessor(successorBlock); constBlock.replaceLastInsn( new ThrowingCstInsn(constRop, SourcePosition.NO_INFO, RegisterSpecList.EMPTY, StdTypeList.EMPTY, cst)); // Insert a block containing the move-result-pseudo insn. SsaBasicBlock resultBlock = constBlock.insertNewSuccessor(successorBlock); PlainInsn insn = new PlainInsn( Rops.opMoveResultPseudo(result.getTypeBearer()), SourcePosition.NO_INFO, result, RegisterSpecList.EMPTY); resultBlock.addInsnToHead(insn); } newRegs.put(cst, result); } updateConstUses(newRegs, regSz); }
Example #12
Source File: RopTranslator.java From Box with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public void visitPlainCstInsn(PlainCstInsn insn) { super.visitPlainCstInsn(insn); addIntroductionIfNecessary(insn); }
Example #13
Source File: RopTranslator.java From J2ME-Loader with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public void visitPlainCstInsn(PlainCstInsn insn) { super.visitPlainCstInsn(insn); addIntroductionIfNecessary(insn); }
Example #14
Source File: ConstCollector.java From J2ME-Loader with Apache License 2.0 | 4 votes |
/** * Applies the optimization. */ private void run() { int regSz = ssaMeth.getRegCount(); ArrayList<TypedConstant> constantList = getConstsSortedByCountUse(); int toCollect = Math.min(constantList.size(), MAX_COLLECTED_CONSTANTS); SsaBasicBlock start = ssaMeth.getEntryBlock(); // Constant to new register containing the constant HashMap<TypedConstant, RegisterSpec> newRegs = new HashMap<TypedConstant, RegisterSpec> (toCollect); for (int i = 0; i < toCollect; i++) { TypedConstant cst = constantList.get(i); RegisterSpec result = RegisterSpec.make(ssaMeth.makeNewSsaReg(), cst); Rop constRop = Rops.opConst(cst); if (constRop.getBranchingness() == Rop.BRANCH_NONE) { start.addInsnToHead( new PlainCstInsn(Rops.opConst(cst), SourcePosition.NO_INFO, result, RegisterSpecList.EMPTY, cst)); } else { // We need two new basic blocks along with the new insn SsaBasicBlock entryBlock = ssaMeth.getEntryBlock(); SsaBasicBlock successorBlock = entryBlock.getPrimarySuccessor(); // Insert a block containing the const insn. SsaBasicBlock constBlock = entryBlock.insertNewSuccessor(successorBlock); constBlock.replaceLastInsn( new ThrowingCstInsn(constRop, SourcePosition.NO_INFO, RegisterSpecList.EMPTY, StdTypeList.EMPTY, cst)); // Insert a block containing the move-result-pseudo insn. SsaBasicBlock resultBlock = constBlock.insertNewSuccessor(successorBlock); PlainInsn insn = new PlainInsn( Rops.opMoveResultPseudo(result.getTypeBearer()), SourcePosition.NO_INFO, result, RegisterSpecList.EMPTY); resultBlock.addInsnToHead(insn); } newRegs.put(cst, result); } updateConstUses(newRegs, regSz); }
Example #15
Source File: ConstCollector.java From Box with Apache License 2.0 | 4 votes |
/** * Applies the optimization. */ private void run() { int regSz = ssaMeth.getRegCount(); ArrayList<TypedConstant> constantList = getConstsSortedByCountUse(); int toCollect = Math.min(constantList.size(), MAX_COLLECTED_CONSTANTS); SsaBasicBlock start = ssaMeth.getEntryBlock(); // Constant to new register containing the constant HashMap<TypedConstant, RegisterSpec> newRegs = new HashMap<TypedConstant, RegisterSpec> (toCollect); for (int i = 0; i < toCollect; i++) { TypedConstant cst = constantList.get(i); RegisterSpec result = RegisterSpec.make(ssaMeth.makeNewSsaReg(), cst); Rop constRop = Rops.opConst(cst); if (constRop.getBranchingness() == Rop.BRANCH_NONE) { start.addInsnToHead( new PlainCstInsn(Rops.opConst(cst), SourcePosition.NO_INFO, result, RegisterSpecList.EMPTY, cst)); } else { // We need two new basic blocks along with the new insn SsaBasicBlock entryBlock = ssaMeth.getEntryBlock(); SsaBasicBlock successorBlock = entryBlock.getPrimarySuccessor(); // Insert a block containing the const insn. SsaBasicBlock constBlock = entryBlock.insertNewSuccessor(successorBlock); constBlock.replaceLastInsn( new ThrowingCstInsn(constRop, SourcePosition.NO_INFO, RegisterSpecList.EMPTY, StdTypeList.EMPTY, cst)); // Insert a block containing the move-result-pseudo insn. SsaBasicBlock resultBlock = constBlock.insertNewSuccessor(successorBlock); PlainInsn insn = new PlainInsn( Rops.opMoveResultPseudo(result.getTypeBearer()), SourcePosition.NO_INFO, result, RegisterSpecList.EMPTY); resultBlock.addInsnToHead(insn); } newRegs.put(cst, result); } updateConstUses(newRegs, regSz); }
Example #16
Source File: RopTranslator.java From Box with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public void visitPlainCstInsn(PlainCstInsn insn) { super.visitPlainCstInsn(insn); addIntroductionIfNecessary(insn); }
Example #17
Source File: RopTranslator.java From buck with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public void visitPlainCstInsn(PlainCstInsn insn) { super.visitPlainCstInsn(insn); addIntroductionIfNecessary(insn); }
Example #18
Source File: ConstCollector.java From buck with Apache License 2.0 | 4 votes |
/** * Applies the optimization. */ private void run() { int regSz = ssaMeth.getRegCount(); ArrayList<TypedConstant> constantList = getConstsSortedByCountUse(); int toCollect = Math.min(constantList.size(), MAX_COLLECTED_CONSTANTS); SsaBasicBlock start = ssaMeth.getEntryBlock(); // Constant to new register containing the constant HashMap<TypedConstant, RegisterSpec> newRegs = new HashMap<TypedConstant, RegisterSpec> (toCollect); for (int i = 0; i < toCollect; i++) { TypedConstant cst = constantList.get(i); RegisterSpec result = RegisterSpec.make(ssaMeth.makeNewSsaReg(), cst); Rop constRop = Rops.opConst(cst); if (constRop.getBranchingness() == Rop.BRANCH_NONE) { start.addInsnToHead( new PlainCstInsn(Rops.opConst(cst), SourcePosition.NO_INFO, result, RegisterSpecList.EMPTY, cst)); } else { // We need two new basic blocks along with the new insn SsaBasicBlock entryBlock = ssaMeth.getEntryBlock(); SsaBasicBlock successorBlock = entryBlock.getPrimarySuccessor(); // Insert a block containing the const insn. SsaBasicBlock constBlock = entryBlock.insertNewSuccessor(successorBlock); constBlock.replaceLastInsn( new ThrowingCstInsn(constRop, SourcePosition.NO_INFO, RegisterSpecList.EMPTY, StdTypeList.EMPTY, cst)); // Insert a block containing the move-result-pseudo insn. SsaBasicBlock resultBlock = constBlock.insertNewSuccessor(successorBlock); PlainInsn insn = new PlainInsn( Rops.opMoveResultPseudo(result.getTypeBearer()), SourcePosition.NO_INFO, result, RegisterSpecList.EMPTY); resultBlock.addInsnToHead(insn); } newRegs.put(cst, result); } updateConstUses(newRegs, regSz); }