Class Insn

java.lang.Object
com.android.dx.rop.code.Insn
All Implemented Interfaces:
ToHuman
Direct Known Subclasses:
CstInsn, FillArrayDataInsn, InvokePolymorphicInsn, PlainInsn, SwitchInsn, ThrowingInsn

public abstract class Insn extends Object implements ToHuman
A register-based instruction. An instruction is the combination of an opcode (which specifies operation and source/result types), a list of actual sources and result registers/values, and additional information.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Base implementation of Insn.Visitor, which has empty method bodies for all methods.
    static interface 
    Visitor interface for this (outer) class.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Insn(Rop opcode, SourcePosition position, RegisterSpec result, RegisterSpecList sources)
    Constructs an instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Calls the appropriate method on the given visitor, depending on the class of this instance.
    final boolean
    Gets whether this instruction can possibly throw an exception.
    boolean
    Compares Insn contents, since Insn.equals() is defined to be an identity compare.
    Returns an exact copy of this Insn
    final boolean
    equals(Object other)
    Instances of this class compare by identity.
    abstract TypeList
    Gets the list of possibly-caught exceptions.
    Gets an "inline" string portion for toHuman(), if available.
    Gets the spec of a local variable assignment that occurs at this instruction, or null if no local variable assignment occurs.
    final Rop
    Gets the opcode.
    Gets the source position.
    Gets the result spec, if any.
    Gets the source specs.
    final int
    This implementation returns the identity hashcode of this instance.
    Gets a human-oriented (and slightly lossy) string for this instance.
    protected final String
    Returns the human string form of this instance, with the given bit added in the standard location for an inline argument.
    protected final String
    Returns the string form of this instance, with the given bit added in the standard location for an inline argument.
    abstract Insn
    Returns an instance that is just like this one, except that it has a catch list with the given item appended to the end.
    abstract Insn
    Returns an instance that is just like this one, except with new result and source registers.
    abstract Insn
    withRegisterOffset(int delta)
    Returns an instance that is just like this one, except that all register references have been offset by the given delta.
    Returns an instance that is just like this one, except that, if possible, the insn is converted into a version in which a source (if it is a constant) is represented directly rather than as a register reference.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Insn

      public Insn(Rop opcode, SourcePosition position, RegisterSpec result, RegisterSpecList sources)
      Constructs an instance.
      Parameters:
      opcode - non-null; the opcode
      position - non-null; source position
      result - null-ok; spec for the result, if any
      sources - non-null; specs for all the sources
  • Method Details

    • equals

      public final boolean equals(Object other)
      Instances of this class compare by identity. That is, x.equals(y) is only true if x == y.
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      This implementation returns the identity hashcode of this instance. This is proper, since instances of this class compare by identity (see equals(java.lang.Object)).
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toHuman

      public String toHuman()
      Gets a human-oriented (and slightly lossy) string for this instance.
      Specified by:
      toHuman in interface ToHuman
      Returns:
      non-null; the human string form
    • getInlineString

      public String getInlineString()
      Gets an "inline" string portion for toHuman(), if available. This is the portion that appears after the Rop opcode
      Returns:
      null-ok; if non-null, the inline text for toHuman()
    • getOpcode

      public final Rop getOpcode()
      Gets the opcode.
      Returns:
      non-null; the opcode
    • getPosition

      public final SourcePosition getPosition()
      Gets the source position.
      Returns:
      non-null; the source position
    • getResult

      public final RegisterSpec getResult()
      Gets the result spec, if any. A return value of null means this instruction returns nothing.
      Returns:
      null-ok; the result spec, if any
    • getLocalAssignment

      public final RegisterSpec getLocalAssignment()
      Gets the spec of a local variable assignment that occurs at this instruction, or null if no local variable assignment occurs. This may be the result register, or for mark-local insns it may be the source.
      Returns:
      null-ok; a named register spec or null
    • getSources

      public final RegisterSpecList getSources()
      Gets the source specs.
      Returns:
      non-null; the source specs
    • canThrow

      public final boolean canThrow()
      Gets whether this instruction can possibly throw an exception. This is just a convenient wrapper for getOpcode().canThrow().
      Returns:
      true iff this instruction can possibly throw
    • getCatches

      public abstract TypeList getCatches()
      Gets the list of possibly-caught exceptions. This returns StdTypeList.EMPTY if this instruction has no handlers, which can be either if this instruction can't possibly throw or if it merely doesn't handle any of its possible exceptions. To determine whether this instruction can throw, use canThrow().
      Returns:
      non-null; the catches list
    • accept

      public abstract void accept(Insn.Visitor visitor)
      Calls the appropriate method on the given visitor, depending on the class of this instance. Subclasses must override this.
      Parameters:
      visitor - non-null; the visitor to call on
    • withAddedCatch

      public abstract Insn withAddedCatch(Type type)
      Returns an instance that is just like this one, except that it has a catch list with the given item appended to the end. This method throws an exception if this instance can't possibly throw. To determine whether this instruction can throw, use canThrow().
      Parameters:
      type - non-null; type to append to the catch list
      Returns:
      non-null; an appropriately-constructed instance
    • withRegisterOffset

      public abstract Insn withRegisterOffset(int delta)
      Returns an instance that is just like this one, except that all register references have been offset by the given delta.
      Parameters:
      delta - the amount to offset register references by
      Returns:
      non-null; an appropriately-constructed instance
    • withSourceLiteral

      public Insn withSourceLiteral()
      Returns an instance that is just like this one, except that, if possible, the insn is converted into a version in which a source (if it is a constant) is represented directly rather than as a register reference. this is returned in cases where the translation is not possible.
      Returns:
      non-null; an appropriately-constructed instance
    • copy

      public Insn copy()
      Returns an exact copy of this Insn
      Returns:
      non-null; an appropriately-constructed instance
    • contentEquals

      public boolean contentEquals(Insn b)
      Compares Insn contents, since Insn.equals() is defined to be an identity compare. Insn's are contentEquals() if they have the same opcode, registers, source position, and other metadata.
      Returns:
      true in the case described above
    • withNewRegisters

      public abstract Insn withNewRegisters(RegisterSpec result, RegisterSpecList sources)
      Returns an instance that is just like this one, except with new result and source registers.
      Parameters:
      result - null-ok; new result register
      sources - non-null; new sources registers
      Returns:
      non-null; an appropriately-constructed instance
    • toStringWithInline

      protected final String toStringWithInline(String extra)
      Returns the string form of this instance, with the given bit added in the standard location for an inline argument.
      Parameters:
      extra - null-ok; the inline argument string
      Returns:
      non-null; the string form
    • toHumanWithInline

      protected final String toHumanWithInline(String extra)
      Returns the human string form of this instance, with the given bit added in the standard location for an inline argument.
      Parameters:
      extra - null-ok; the inline argument string
      Returns:
      non-null; the human string form