com.android.dx.rop.code.RegisterSpecList Java Examples

The following examples show how to use com.android.dx.rop.code.RegisterSpecList. 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 Project: Box   Author: lulululbj   File: CstInsn.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public DalvInsn withRegisters(RegisterSpecList registers) {
    CstInsn result =
        new CstInsn(getOpcode(), getPosition(), registers, constant);

    if (index >= 0) {
        result.setIndex(index);
    }

    if (classIndex >= 0) {
        result.setClassIndex(classIndex);
    }

    return result;
}
 
Example #2
Source Project: buck   Author: facebook   File: Form12x.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int sz = regs.size();

    /*
     * The (sz - 2) and (sz - 1) below makes this code work for
     * both the two- and three-register ops. (See "case 3" in
     * isCompatible(), above.)
     */

    write(out, opcodeUnit(insn,
                          makeByte(regs.get(sz - 2).getReg(),
                                   regs.get(sz - 1).getReg())));
}
 
Example #3
Source Project: Box   Author: lulululbj   File: EscapeAnalysis.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Replaces the instructions that define an array with equivalent registers.
 * For each entry in the array, a register is created, initialized to zero.
 * A mapping between this register and the corresponding array index is
 * added.
 *
 * @param def {@code non-null;} move result instruction for array
 * @param prev {@code non-null;} instruction for instantiating new array
 * @param length size of the new array
 * @param newRegs {@code non-null;} mapping of array indices to new
 * registers to be populated
 */
private void replaceDef(SsaInsn def, SsaInsn prev, int length,
                            ArrayList<RegisterSpec> newRegs) {
    Type resultType = def.getResult().getType();

    // Create new zeroed out registers for each element in the array
    for (int i = 0; i < length; i++) {
        Constant newZero = Zeroes.zeroFor(resultType.getComponentType());
        TypedConstant typedZero = (TypedConstant) newZero;
        RegisterSpec newReg =
            RegisterSpec.make(ssaMeth.makeNewSsaReg(), typedZero);
        newRegs.add(newReg);
        insertPlainInsnBefore(def, RegisterSpecList.EMPTY, newReg,
                                  RegOps.CONST, newZero);
    }
}
 
Example #4
Source Project: Box   Author: lulululbj   File: RopTranslator.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitInvokePolymorphicInsn(InvokePolymorphicInsn insn) {
    SourcePosition pos = insn.getPosition();
    Dop opcode = RopToDop.dopFor(insn);
    Rop rop = insn.getOpcode();

    if (rop.getBranchingness() != Rop.BRANCH_THROW) {
        throw new RuntimeException("Expected BRANCH_THROW got " + rop.getBranchingness());
    } else if (!rop.isCallLike()) {
        throw new RuntimeException("Expected call-like operation");
    }

    addOutput(lastAddress);

    RegisterSpecList regs = insn.getSources();
    Constant[] constants = new Constant[] {
        insn.getPolymorphicMethod(),
        insn.getCallSiteProto()
        };
    DalvInsn di = new MultiCstInsn(opcode, pos, regs, constants);

    addOutput(di);
}
 
Example #5
Source Project: buck   Author: facebook   File: Form22c.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    if (!((insn instanceof CstInsn) &&
          (regs.size() == 2) &&
          unsignedFitsInNibble(regs.get(0).getReg()) &&
          unsignedFitsInNibble(regs.get(1).getReg()))) {
        return false;
    }

    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();

    if (! unsignedFitsInShort(cpi)) {
        return false;
    }

    Constant cst = ci.getConstant();
    return (cst instanceof CstType) ||
        (cst instanceof CstFieldRef);
}
 
Example #6
Source Project: buck   Author: facebook   File: RopTranslator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #7
Source Project: J2ME-Loader   Author: nikita36078   File: Form31c.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int sz = regs.size();
    BitSet bits = new BitSet(sz);
    boolean compat = unsignedFitsInByte(regs.get(0).getReg());

    if (sz == 1) {
        bits.set(0, compat);
    } else {
        if (regs.get(0).getReg() == regs.get(1).getReg()) {
            bits.set(0, compat);
            bits.set(1, compat);
        }
    }

    return bits;
}
 
Example #8
Source Project: Box   Author: lulululbj   File: Form35c.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int sz = regs.size();
    BitSet bits = new BitSet(sz);

    for (int i = 0; i < sz; i++) {
        RegisterSpec reg = regs.get(i);
        /*
         * The check below adds (category - 1) to the register, to
         * account for the fact that the second half of a
         * category-2 register has to be represented explicitly in
         * the result.
         */
        bits.set(i, unsignedFitsInNibble(reg.getReg() +
                                         reg.getCategory() - 1));
    }

    return bits;
}
 
Example #9
Source Project: J2ME-Loader   Author: nikita36078   File: NormalSsaInsn.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Changes one of the insn's sources. New source should be of same type
 * and category.
 *
 * @param index {@code >=0;} index of source to change
 * @param newSpec spec for new source
 */
public final void changeOneSource(int index, RegisterSpec newSpec) {
    RegisterSpecList origSources = insn.getSources();
    int sz = origSources.size();
    RegisterSpecList newSources = new RegisterSpecList(sz);

    for (int i = 0; i < sz; i++) {
        newSources.set(i, i == index ? newSpec : origSources.get(i));
    }

    newSources.setImmutable();

    RegisterSpec origSpec = origSources.get(index);
    if (origSpec.getReg() != newSpec.getReg()) {
        /*
         * If the register remains unchanged, we're only changing
         * the type or local var name so don't update use list
         */
        getBlock().getParent().onSourceChanged(this, origSpec, newSpec);
    }

    insn = insn.withNewRegisters(getResult(), newSources);
}
 
Example #10
Source Project: buck   Author: facebook   File: SsaMethod.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Updates the use list for a source list change.
 *
 * @param insn {@code insn non-null;} insn being changed.
 * {@code insn.getSources()} must return the new source list.
 * @param oldSources {@code null-ok;} list of sources that were
 * previously used
 */
/*package*/ void onSourcesChanged(SsaInsn insn,
        RegisterSpecList oldSources) {
    if (useList == null) return;

    if (oldSources != null) {
        removeFromUseList(insn, oldSources);
    }

    RegisterSpecList sources = insn.getSources();
    int szNew = sources.size();

    for (int i = 0; i < szNew; i++) {
        int reg = sources.get(i).getReg();
        useList[reg].add(insn);
    }
}
 
Example #11
Source Project: Box   Author: lulululbj   File: HighRegisterPrefix.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected String listingString0(boolean noteIndices) {
    RegisterSpecList registers = getRegisters();
    int sz = registers.size();
    StringBuilder sb = new StringBuilder(100);

    for (int i = 0, outAt = 0; i < sz; i++) {
        RegisterSpec src = registers.get(i);
        SimpleInsn insn = moveInsnFor(src, outAt);

        if (i != 0) {
            sb.append('\n');
        }

        sb.append(insn.listingString0(noteIndices));

        outAt += src.getCategory();
    }

    return sb.toString();
}
 
Example #12
Source Project: Box   Author: lulululbj   File: InsnFormat.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to return a register list string.
 *
 * @param list {@code non-null;} the list of registers
 * @return {@code non-null;} the string form
 */
protected static String regListString(RegisterSpecList list) {
    int sz = list.size();
    StringBuilder sb = new StringBuilder(sz * 5 + 2);

    sb.append('{');

    for (int i = 0; i < sz; i++) {
        if (i != 0) {
            sb.append(", ");
        }
        sb.append(list.get(i).regString());
    }

    sb.append('}');

    return sb.toString();
}
 
Example #13
Source Project: Box   Author: lulululbj   File: RegisterMapper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param sources old register list
 * @return new mapped register list, or old if nothing has changed.
 */
public final RegisterSpecList map(RegisterSpecList sources) {
    int sz = sources.size();
    RegisterSpecList newSources = new RegisterSpecList(sz);

    for (int i = 0; i < sz; i++) {
        newSources.set(i, map(sources.get(i)));
    }

    newSources.setImmutable();

    // Return the old sources if nothing has changed.
    return newSources.equals(sources) ? sources : newSources;
}
 
Example #14
Source Project: buck   Author: facebook   File: Form21s.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int value =
        ((CstLiteralBits) ((CstInsn) insn).getConstant()).getIntBits();

    write(out,
          opcodeUnit(insn, regs.get(0).getReg()),
          (short) value);
}
 
Example #15
Source Project: J2ME-Loader   Author: nikita36078   File: Form45cc.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a register list which is equivalent to the given one,
 * except that it splits category-2 registers into two explicit
 * entries. This returns the original list if no modification is
 * required
 *
 * @param orig {@code non-null;} the original list
 * @return {@code non-null;} the list with the described transformation
 */
private static RegisterSpecList explicitize(RegisterSpecList orig) {
    int wordCount = wordCount(orig);
    int sz = orig.size();

    if (wordCount == sz) {
        return orig;
    }

    RegisterSpecList result = new RegisterSpecList(wordCount);
    int wordAt = 0;

    for (int i = 0; i < sz; i++) {
        RegisterSpec one = orig.get(i);
        result.set(wordAt, one);
        if (one.getCategory() == 2) {
            result.set(wordAt + 1,
                       RegisterSpec.make(one.getReg() + 1, Type.VOID));
            wordAt += 2;
        } else {
            wordAt++;
        }
    }

    result.setImmutable();
    return result;
}
 
Example #16
Source Project: buck   Author: facebook   File: SwitchData.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 #17
Source Project: lua-for-android   Author: qtiuto   File: Code.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Check if an int or reference equals to zero. If the comparison is true,
 * execution jumps to {@code trueLabel}. If it is false, execution continues to
 * the next instruction.
 */
public <T> void compareZ(Comparison comparison, Label trueLabel, Local<?> a) {
    adopt(trueLabel);
    Rop rop = comparison.rop(StdTypeList.make(a.type.ropType));
    addInstruction(new PlainInsn(rop, sourcePosition, null,
            RegisterSpecList.make(a.spec())), trueLabel);
}
 
Example #18
Source Project: Box   Author: lulululbj   File: Form21h.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    BitSet bits = new BitSet(1);

    bits.set(0, unsignedFitsInByte(regs.get(0).getReg()));
    return bits;
}
 
Example #19
Source Project: Box   Author: lulululbj   File: Form22x.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    write(out,
          opcodeUnit(insn, regs.get(0).getReg()),
          (short) regs.get(1).getReg());
}
 
Example #20
Source Project: buck   Author: facebook   File: Form32x.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    BitSet bits = new BitSet(2);

    bits.set(0, unsignedFitsInShort(regs.get(0).getReg()));
    bits.set(1, unsignedFitsInShort(regs.get(1).getReg()));
    return bits;
}
 
Example #21
Source Project: buck   Author: facebook   File: Form21t.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    BitSet bits = new BitSet(1);

    bits.set(0, unsignedFitsInByte(regs.get(0).getReg()));
    return bits;
}
 
Example #22
Source Project: Box   Author: lulululbj   File: Form45cc.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the number of words required for the given register list, where
 * category-2 values count as two words. Return {@code -1} if the
 * list requires more than five words or contains registers that need
 * more than a nibble to identify them.
 *
 * @param regs {@code non-null;} the register list in question
 * @return {@code >= -1;} the number of words required, or {@code -1}
 * if the list couldn't possibly fit in this format
 */
private static int wordCount(RegisterSpecList regs) {
    int sz = regs.size();

    if (sz > MAX_NUM_OPS) {
        // It can't possibly fit.
        return -1;
    }

    int result = 0;

    for (int i = 0; i < sz; i++) {
        RegisterSpec one = regs.get(i);
        result += one.getCategory();
        /*
         * The check below adds (category - 1) to the register, to
         * account for the fact that the second half of a
         * category-2 register has to be represented explicitly in
         * the result.
         */
        if (!unsignedFitsInNibble(one.getReg() + one.getCategory() - 1)) {
            return -1;
        }
    }

    return (result <= MAX_NUM_OPS) ? result : -1;
}
 
Example #23
Source Project: J2ME-Loader   Author: nikita36078   File: Form35c.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a register list which is equivalent to the given one,
 * except that it splits category-2 registers into two explicit
 * entries. This returns the original list if no modification is
 * required
 *
 * @param orig {@code non-null;} the original list
 * @return {@code non-null;} the list with the described transformation
 */
private static RegisterSpecList explicitize(RegisterSpecList orig) {
    int wordCount = wordCount(orig);
    int sz = orig.size();

    if (wordCount == sz) {
        return orig;
    }

    RegisterSpecList result = new RegisterSpecList(wordCount);
    int wordAt = 0;

    for (int i = 0; i < sz; i++) {
        RegisterSpec one = orig.get(i);
        result.set(wordAt, one);
        if (one.getCategory() == 2) {
            result.set(wordAt + 1,
                       RegisterSpec.make(one.getReg() + 1, Type.VOID));
            wordAt += 2;
        } else {
            wordAt++;
        }
    }

    result.setImmutable();
    return result;
}
 
Example #24
Source Project: J2ME-Loader   Author: nikita36078   File: Form22s.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int value =
        ((CstLiteralBits) ((CstInsn) insn).getConstant()).getIntBits();

    write(out,
          opcodeUnit(insn,
                     makeByte(regs.get(0).getReg(), regs.get(1).getReg())),
          (short) value);
}
 
Example #25
Source Project: Box   Author: lulululbj   File: Form32x.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();

    write(out,
          opcodeUnit(insn, 0),
          (short) regs.get(0).getReg(),
          (short) regs.get(1).getReg());
}
 
Example #26
Source Project: Box   Author: lulululbj   File: Form31t.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();

    if (!((insn instanceof TargetInsn) &&
          (regs.size() == 1) &&
          unsignedFitsInByte(regs.get(0).getReg()))) {
        return false;
    }

    return true;
}
 
Example #27
Source Project: J2ME-Loader   Author: nikita36078   File: Form31i.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int value =
        ((CstLiteralBits) ((CstInsn) insn).getConstant()).getIntBits();

    write(out, opcodeUnit(insn, regs.get(0).getReg()), value);
}
 
Example #28
Source Project: J2ME-Loader   Author: nikita36078   File: Form21h.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    BitSet bits = new BitSet(1);

    bits.set(0, unsignedFitsInByte(regs.get(0).getReg()));
    return bits;
}
 
Example #29
Source Project: buck   Author: facebook   File: RegisterMapper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param sources old register list
 * @return new mapped register list, or old if nothing has changed.
 */
public final RegisterSpecList map(RegisterSpecList sources) {
    int sz = sources.size();
    RegisterSpecList newSources = new RegisterSpecList(sz);

    for (int i = 0; i < sz; i++) {
        newSources.set(i, map(sources.get(i)));
    }

    newSources.setImmutable();

    // Return the old sources if nothing has changed.
    return newSources.equals(sources) ? sources : newSources;
}
 
Example #30
Source Project: Box   Author: lulululbj   File: Form21c.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int cpi = ((CstInsn) insn).getIndex();

    write(out,
          opcodeUnit(insn, regs.get(0).getReg()),
          (short) cpi);
}