FileDocCategorySizeDatePackage
PlainInsn.javaAPI DocAndroid 5.1 API5301Thu Mar 12 22:18:30 GMT 2015com.android.dx.rop.code

PlainInsn

public final class PlainInsn extends Insn
Plain instruction, which has no embedded data and which cannot possibly throw an exception.

Fields Summary
Constructors Summary
public PlainInsn(Rop opcode, SourcePosition position, RegisterSpec result, RegisterSpecList sources)
Constructs an instance.

param
opcode {@code non-null;} the opcode
param
position {@code non-null;} source position
param
result {@code null-ok;} spec for the result, if any
param
sources {@code non-null;} specs for all the sources

        super(opcode, position, result, sources);

        switch (opcode.getBranchingness()) {
            case Rop.BRANCH_SWITCH:
            case Rop.BRANCH_THROW: {
                throw new IllegalArgumentException("bogus branchingness");
            }
        }

        if (result != null && opcode.getBranchingness() != Rop.BRANCH_NONE) {
            // move-result-pseudo is required here
            throw new IllegalArgumentException
                    ("can't mix branchingness with result");
        }
    
public PlainInsn(Rop opcode, SourcePosition position, RegisterSpec result, RegisterSpec source)
Constructs a single-source instance.

param
opcode {@code non-null;} the opcode
param
position {@code non-null;} source position
param
result {@code null-ok;} spec for the result, if any
param
source {@code non-null;} spec for the source

        this(opcode, position, result, RegisterSpecList.make(source));
    
Methods Summary
public voidaccept(Visitor visitor)
{@inheritDoc}

        visitor.visitPlainInsn(this);
    
public com.android.dx.rop.type.TypeListgetCatches()
{@inheritDoc}

        return StdTypeList.EMPTY;
    
public InsnwithAddedCatch(com.android.dx.rop.type.Type type)
{@inheritDoc}

        throw new UnsupportedOperationException("unsupported");
    
public InsnwithNewRegisters(RegisterSpec result, RegisterSpecList sources)
{@inheritDoc}


        return new PlainInsn(getOpcode(), getPosition(),
                             result,
                             sources);

    
public InsnwithRegisterOffset(int delta)
{@inheritDoc}

        return new PlainInsn(getOpcode(), getPosition(),
                             getResult().withOffset(delta),
                             getSources().withOffset(delta));
    
public InsnwithSourceLiteral()
{@inheritDoc}

        RegisterSpecList sources = getSources();
        int szSources = sources.size();

        if (szSources == 0) {
            return this;
        }

        TypeBearer lastType = sources.get(szSources - 1).getTypeBearer();

        if (!lastType.isConstant()) {
            // Check for reverse subtraction, where first source is constant
            TypeBearer firstType = sources.get(0).getTypeBearer();
            if (szSources == 2 && firstType.isConstant()) {
                Constant cst = (Constant) firstType;
                RegisterSpecList newSources = sources.withoutFirst();
                Rop newRop = Rops.ropFor(getOpcode().getOpcode(), getResult(),
                                             newSources, cst);
                return new PlainCstInsn(newRop, getPosition(), getResult(),
                                            newSources, cst);
            }
            return this;
        } else {

            Constant cst = (Constant) lastType;

            RegisterSpecList newSources = sources.withoutLast();

            Rop newRop;
            try {
                // Check for constant subtraction and flip it to be addition
                int opcode = getOpcode().getOpcode();
                if (opcode == RegOps.SUB && cst instanceof CstInteger) {
                    opcode = RegOps.ADD;
                    cst = CstInteger.make(-((CstInteger)cst).getValue());
                }
                newRop = Rops.ropFor(opcode, getResult(), newSources, cst);
            } catch (IllegalArgumentException ex) {
                // There's no rop for this case
                return this;
            }

            return new PlainCstInsn(newRop, getPosition(),
                    getResult(), newSources, cst);
        }