FileDocCategorySizeDatePackage
DexTranslationAdvice.javaAPI DocAndroid 1.5 API3676Wed May 06 22:41:02 BST 2009com.android.dx.rop.code

DexTranslationAdvice

public final class DexTranslationAdvice extends Object implements TranslationAdvice
Implementation of {@link TranslationAdvice} which represents what the dex format will be able to represent.

Fields Summary
public static final DexTranslationAdvice
THE_ONE
non-null; standard instance of this class
public static final DexTranslationAdvice
NO_SOURCES_IN_ORDER
debug advice for disabling invoke-range optimization
private static final int
MIN_INVOKE_IN_ORDER
The minimum source width, in register units, for an invoke instruction that requires its sources to be in order and contiguous.
private final boolean
disableSourcesInOrder
when true: always returns false for requiresSourcesInOrder
Constructors Summary
private DexTranslationAdvice()
This class is not publicly instantiable. Use {@link #THE_ONE}.


                  
      
        disableSourcesInOrder = false;
    
private DexTranslationAdvice(boolean disableInvokeRange)

        this.disableSourcesInOrder = disableInvokeRange;
    
Methods Summary
public intgetMaxOptimalRegisterCount()
{@inheritDoc}

        return 16;
    
public booleanhasConstantOperation(Rop opcode, RegisterSpec sourceA, RegisterSpec sourceB)
{@inheritDoc}

        if (sourceA.getType() != Type.INT) {
            return false;
        }

        if (! (sourceB.getTypeBearer() instanceof CstInteger)) {
            return false;
        }

        CstInteger cst = (CstInteger) sourceB.getTypeBearer();

        // TODO handle rsub
        switch (opcode.getOpcode()) {
            // These have 8 and 16 bit cst representations
            case RegOps.REM:
            case RegOps.ADD:
            case RegOps.MUL:
            case RegOps.DIV:
            case RegOps.AND:
            case RegOps.OR:
            case RegOps.XOR:
                return cst.fitsIn16Bits();
            // These only have 8 bit cst reps
            case RegOps.SHL:
            case RegOps.SHR:
            case RegOps.USHR:
                return cst.fitsIn8Bits();
            default:
                return false;
        }
    
public booleanrequiresSourcesInOrder(Rop opcode, RegisterSpecList sources)
{@inheritDoc}


        return !disableSourcesInOrder && opcode.isCallLike()
                && totalRopWidth(sources) >= MIN_INVOKE_IN_ORDER;
    
private inttotalRopWidth(RegisterSpecList sources)
Calculates the total rop width of the list of SSA registers

param
sources non-null; list of SSA registers
return
>= 0 rop-form width in register units

        int sz = sources.size();
        int total = 0;

        for (int i = 0; i < sz; i++) {
            total += sources.get(i).getCategory();
        }

        return total;