Java Code Examples for com.android.dx.rop.code.RegisterSpecList#EMPTY
The following examples show how to use
com.android.dx.rop.code.RegisterSpecList#EMPTY .
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: SwitchData.java From Box with Apache License 2.0 | 5 votes |
/** * Constructs an instance. The output address of this instance is initially * unknown ({@code -1}). * * @param position {@code non-null;} source position * @param user {@code non-null;} address representing the instruction that * uses this instance * @param cases {@code non-null;} sorted list of switch cases (keys) * @param targets {@code non-null;} corresponding list of code addresses; the * branch target for each case */ public SwitchData(SourcePosition position, CodeAddress user, IntList cases, CodeAddress[] targets) { super(position, RegisterSpecList.EMPTY); if (user == null) { throw new NullPointerException("user == null"); } if (cases == null) { throw new NullPointerException("cases == null"); } if (targets == null) { throw new NullPointerException("targets == null"); } int sz = cases.size(); if (sz != targets.length) { throw new IllegalArgumentException("cases / targets mismatch"); } if (sz > 65535) { throw new IllegalArgumentException("too many cases"); } this.user = user; this.cases = cases; this.targets = targets; this.packed = shouldPack(cases); }
Example 2
Source File: SsaMethod.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * 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); } } } } }
Example 3
Source File: SwitchData.java From buck with Apache License 2.0 | 5 votes |
/** * Constructs an instance. The output address of this instance is initially * unknown ({@code -1}). * * @param position {@code non-null;} source position * @param user {@code non-null;} address representing the instruction that * uses this instance * @param cases {@code non-null;} sorted list of switch cases (keys) * @param targets {@code non-null;} corresponding list of code addresses; the * branch target for each case */ public SwitchData(SourcePosition position, CodeAddress user, IntList cases, CodeAddress[] targets) { super(position, RegisterSpecList.EMPTY); if (user == null) { throw new NullPointerException("user == null"); } if (cases == null) { throw new NullPointerException("cases == null"); } if (targets == null) { throw new NullPointerException("targets == null"); } int sz = cases.size(); if (sz != targets.length) { throw new IllegalArgumentException("cases / targets mismatch"); } if (sz > 65535) { throw new IllegalArgumentException("too many cases"); } this.user = user; this.cases = cases; this.targets = targets; this.packed = shouldPack(cases); }
Example 4
Source File: RopTranslator.java From Box with Apache License 2.0 | 4 votes |
/** * Helper for {@link #outputInstructions}, which does the processing * and output of one block. * * @param block {@code non-null;} the block to process and output * @param nextLabel {@code >= -1;} the next block that will be processed, or * {@code -1} if there is no next block */ private void outputBlock(BasicBlock block, int nextLabel) { // Append the code address for this block. CodeAddress startAddress = addresses.getStart(block); output.add(startAddress); // Append the local variable state for the block. if (locals != null) { RegisterSpecSet starts = locals.getStarts(block); output.add(new LocalSnapshot(startAddress.getPosition(), starts)); } /* * Choose and append an output instruction for each original * instruction. */ translationVisitor.setBlock(block, addresses.getLast(block)); block.getInsns().forEach(translationVisitor); // Insert the block end code address. output.add(addresses.getEnd(block)); // Set up for end-of-block activities. int succ = block.getPrimarySuccessor(); Insn lastInsn = block.getLastInsn(); /* * Check for (and possibly correct for) a non-optimal choice of * which block will get output next. */ if ((succ >= 0) && (succ != nextLabel)) { /* * The block has a "primary successor" and that primary * successor isn't the next block to be output. */ Rop lastRop = lastInsn.getOpcode(); if ((lastRop.getBranchingness() == Rop.BRANCH_IF) && (block.getSecondarySuccessor() == nextLabel)) { /* * The block ends with an "if" of some sort, and its * secondary successor (the "then") is in fact the * next block to output. So, reverse the sense of * the test, so that we can just emit the next block * without an interstitial goto. */ output.reverseBranch(1, addresses.getStart(succ)); } else { /* * Our only recourse is to add a goto here to get the * flow to be correct. */ TargetInsn insn = new TargetInsn(Dops.GOTO, lastInsn.getPosition(), RegisterSpecList.EMPTY, addresses.getStart(succ)); output.add(insn); } } }
Example 5
Source File: ArrayData.java From J2ME-Loader with Apache License 2.0 | 4 votes |
/** * Constructs an instance. The output address of this instance is initially * unknown ({@code -1}). * * @param position {@code non-null;} source position * @param user {@code non-null;} address representing the instruction that * uses this instance * @param values {@code non-null;} initial values to be filled into an array */ public ArrayData(SourcePosition position, CodeAddress user, ArrayList<Constant> values, Constant arrayType) { super(position, RegisterSpecList.EMPTY); if (user == null) { throw new NullPointerException("user == null"); } if (values == null) { throw new NullPointerException("values == null"); } int sz = values.size(); if (sz <= 0) { throw new IllegalArgumentException("Illegal number of init values"); } this.arrayType = arrayType; if (arrayType == CstType.BYTE_ARRAY || arrayType == CstType.BOOLEAN_ARRAY) { elemWidth = 1; } else if (arrayType == CstType.SHORT_ARRAY || arrayType == CstType.CHAR_ARRAY) { elemWidth = 2; } else if (arrayType == CstType.INT_ARRAY || arrayType == CstType.FLOAT_ARRAY) { elemWidth = 4; } else if (arrayType == CstType.LONG_ARRAY || arrayType == CstType.DOUBLE_ARRAY) { elemWidth = 8; } else { throw new IllegalArgumentException("Unexpected constant type"); } this.user = user; this.values = values; initLength = values.size(); }
Example 6
Source File: SsaMethod.java From Box with Apache License 2.0 | 4 votes |
/** * Deletes all insns in the set from this method. * * @param deletedInsns {@code non-null;} insns to delete */ public void deleteInsns(Set<SsaInsn> deletedInsns) { for (SsaInsn deletedInsn : deletedInsns) { SsaBasicBlock block = deletedInsn.getBlock(); ArrayList<SsaInsn> insns = block.getInsns(); for (int i = insns.size() - 1; i >= 0; i--) { SsaInsn insn = insns.get(i); if (deletedInsn == insn) { onInsnRemoved(insn); insns.remove(i); break; } } // 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); } } } } }
Example 7
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 8
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 9
Source File: RopTranslator.java From Box with Apache License 2.0 | 4 votes |
/** * Helper for {@link #outputInstructions}, which does the processing * and output of one block. * * @param block {@code non-null;} the block to process and output * @param nextLabel {@code >= -1;} the next block that will be processed, or * {@code -1} if there is no next block */ private void outputBlock(BasicBlock block, int nextLabel) { // Append the code address for this block. CodeAddress startAddress = addresses.getStart(block); output.add(startAddress); // Append the local variable state for the block. if (locals != null) { RegisterSpecSet starts = locals.getStarts(block); output.add(new LocalSnapshot(startAddress.getPosition(), starts)); } /* * Choose and append an output instruction for each original * instruction. */ translationVisitor.setBlock(block, addresses.getLast(block)); block.getInsns().forEach(translationVisitor); // Insert the block end code address. output.add(addresses.getEnd(block)); // Set up for end-of-block activities. int succ = block.getPrimarySuccessor(); Insn lastInsn = block.getLastInsn(); /* * Check for (and possibly correct for) a non-optimal choice of * which block will get output next. */ if ((succ >= 0) && (succ != nextLabel)) { /* * The block has a "primary successor" and that primary * successor isn't the next block to be output. */ Rop lastRop = lastInsn.getOpcode(); if ((lastRop.getBranchingness() == Rop.BRANCH_IF) && (block.getSecondarySuccessor() == nextLabel)) { /* * The block ends with an "if" of some sort, and its * secondary successor (the "then") is in fact the * next block to output. So, reverse the sense of * the test, so that we can just emit the next block * without an interstitial goto. */ output.reverseBranch(1, addresses.getStart(succ)); } else { /* * Our only recourse is to add a goto here to get the * flow to be correct. */ TargetInsn insn = new TargetInsn(Dops.GOTO, lastInsn.getPosition(), RegisterSpecList.EMPTY, addresses.getStart(succ)); output.add(insn); } } }
Example 10
Source File: RopTranslator.java From buck with Apache License 2.0 | 4 votes |
/** * Helper for {@link #outputInstructions}, which does the processing * and output of one block. * * @param block {@code non-null;} the block to process and output * @param nextLabel {@code >= -1;} the next block that will be processed, or * {@code -1} if there is no next block */ private void outputBlock(BasicBlock block, int nextLabel) { // Append the code address for this block. CodeAddress startAddress = addresses.getStart(block); output.add(startAddress); // Append the local variable state for the block. if (locals != null) { RegisterSpecSet starts = locals.getStarts(block); output.add(new LocalSnapshot(startAddress.getPosition(), starts)); } /* * Choose and append an output instruction for each original * instruction. */ translationVisitor.setBlock(block, addresses.getLast(block)); block.getInsns().forEach(translationVisitor); // Insert the block end code address. output.add(addresses.getEnd(block)); // Set up for end-of-block activities. int succ = block.getPrimarySuccessor(); Insn lastInsn = block.getLastInsn(); /* * Check for (and possibly correct for) a non-optimal choice of * which block will get output next. */ if ((succ >= 0) && (succ != nextLabel)) { /* * The block has a "primary successor" and that primary * successor isn't the next block to be output. */ Rop lastRop = lastInsn.getOpcode(); if ((lastRop.getBranchingness() == Rop.BRANCH_IF) && (block.getSecondarySuccessor() == nextLabel)) { /* * The block ends with an "if" of some sort, and its * secondary successor (the "then") is in fact the * next block to output. So, reverse the sense of * the test, so that we can just emit the next block * without an interstitial goto. */ output.reverseBranch(1, addresses.getStart(succ)); } else { /* * Our only recourse is to add a goto here to get the * flow to be correct. */ TargetInsn insn = new TargetInsn(Dops.GOTO, lastInsn.getPosition(), RegisterSpecList.EMPTY, addresses.getStart(succ)); output.add(insn); } } }
Example 11
Source File: ArrayData.java From buck with Apache License 2.0 | 4 votes |
/** * Constructs an instance. The output address of this instance is initially * unknown ({@code -1}). * * @param position {@code non-null;} source position * @param user {@code non-null;} address representing the instruction that * uses this instance * @param values {@code non-null;} initial values to be filled into an array */ public ArrayData(SourcePosition position, CodeAddress user, ArrayList<Constant> values, Constant arrayType) { super(position, RegisterSpecList.EMPTY); if (user == null) { throw new NullPointerException("user == null"); } if (values == null) { throw new NullPointerException("values == null"); } int sz = values.size(); if (sz <= 0) { throw new IllegalArgumentException("Illegal number of init values"); } this.arrayType = arrayType; if (arrayType == CstType.BYTE_ARRAY || arrayType == CstType.BOOLEAN_ARRAY) { elemWidth = 1; } else if (arrayType == CstType.SHORT_ARRAY || arrayType == CstType.CHAR_ARRAY) { elemWidth = 2; } else if (arrayType == CstType.INT_ARRAY || arrayType == CstType.FLOAT_ARRAY) { elemWidth = 4; } else if (arrayType == CstType.LONG_ARRAY || arrayType == CstType.DOUBLE_ARRAY) { elemWidth = 8; } else { throw new IllegalArgumentException("Unexpected constant type"); } this.user = user; this.values = values; initLength = values.size(); }
Example 12
Source File: SsaMethod.java From buck with Apache License 2.0 | 2 votes |
/** * Gets a new {@code GOTO} insn. * * @param block block to which this GOTO will be added * (not it's destination!) * @return an appropriately-constructed instance. */ private static SsaInsn getGoto(SsaBasicBlock block) { return new NormalSsaInsn ( new PlainInsn(Rops.GOTO, SourcePosition.NO_INFO, null, RegisterSpecList.EMPTY), block); }
Example 13
Source File: ZeroSizeInsn.java From Box with Apache License 2.0 | 2 votes |
/** * Constructs an instance. The output address of this instance is initially * unknown ({@code -1}). * * @param position {@code non-null;} source position */ public ZeroSizeInsn(SourcePosition position) { super(Dops.SPECIAL_FORMAT, position, RegisterSpecList.EMPTY); }
Example 14
Source File: OddSpacer.java From Box with Apache License 2.0 | 2 votes |
/** * Constructs an instance. The output address of this instance is initially * unknown ({@code -1}). * * @param position {@code non-null;} source position */ public OddSpacer(SourcePosition position) { super(position, RegisterSpecList.EMPTY); }
Example 15
Source File: SsaMethod.java From Box with Apache License 2.0 | 2 votes |
/** * Gets a new {@code GOTO} insn. * * @param block block to which this GOTO will be added * (not it's destination!) * @return an appropriately-constructed instance. */ private static SsaInsn getGoto(SsaBasicBlock block) { return new NormalSsaInsn ( new PlainInsn(Rops.GOTO, SourcePosition.NO_INFO, null, RegisterSpecList.EMPTY), block); }
Example 16
Source File: ZeroSizeInsn.java From buck with Apache License 2.0 | 2 votes |
/** * Constructs an instance. The output address of this instance is initially * unknown ({@code -1}). * * @param position {@code non-null;} source position */ public ZeroSizeInsn(SourcePosition position) { super(Dops.SPECIAL_FORMAT, position, RegisterSpecList.EMPTY); }
Example 17
Source File: OddSpacer.java From buck with Apache License 2.0 | 2 votes |
/** * Constructs an instance. The output address of this instance is initially * unknown ({@code -1}). * * @param position {@code non-null;} source position */ public OddSpacer(SourcePosition position) { super(position, RegisterSpecList.EMPTY); }
Example 18
Source File: OddSpacer.java From J2ME-Loader with Apache License 2.0 | 2 votes |
/** * Constructs an instance. The output address of this instance is initially * unknown ({@code -1}). * * @param position {@code non-null;} source position */ public OddSpacer(SourcePosition position) { super(position, RegisterSpecList.EMPTY); }
Example 19
Source File: ZeroSizeInsn.java From J2ME-Loader with Apache License 2.0 | 2 votes |
/** * Constructs an instance. The output address of this instance is initially * unknown ({@code -1}). * * @param position {@code non-null;} source position */ public ZeroSizeInsn(SourcePosition position) { super(Dops.SPECIAL_FORMAT, position, RegisterSpecList.EMPTY); }
Example 20
Source File: ZeroSizeInsn.java From Box with Apache License 2.0 | 2 votes |
/** * Constructs an instance. The output address of this instance is initially * unknown ({@code -1}). * * @param position {@code non-null;} source position */ public ZeroSizeInsn(SourcePosition position) { super(Dops.SPECIAL_FORMAT, position, RegisterSpecList.EMPTY); }