Class OutputFinisher

java.lang.Object
com.android.dx.dex.code.OutputFinisher

public final class OutputFinisher extends Object
Processor for instruction lists, which takes a "first cut" of instruction selection as a basis and produces a "final cut" in the form of a DalvInsnList instance.
  • Constructor Details

    • OutputFinisher

      public OutputFinisher(DexOptions dexOptions, int initialCapacity, int regCount, int paramSize)
      Constructs an instance. It initially contains no instructions.
      Parameters:
      dexOptions - non-null; options for dex output
      initialCapacity - >= 0; initial capacity of the instructions list
      regCount - >= 0; register count for the method
      paramSize - size, in register units, of all the parameters for this method
  • Method Details

    • hasAnyPositionInfo

      public boolean hasAnyPositionInfo()
      Returns whether any of the instructions added to this instance come with position info.
      Returns:
      whether any of the instructions added to this instance come with position info
    • hasAnyLocalInfo

      public boolean hasAnyLocalInfo()
      Returns whether this instance has any local variable information.
      Returns:
      whether this instance has any local variable information
    • getAllConstants

      public HashSet<Constant> getAllConstants()
      Returns the set of all constants referred to by instructions added to this instance.
      Returns:
      non-null; the set of constants
    • add

      public void add(DalvInsn insn)
      Adds an instruction to the output.
      Parameters:
      insn - non-null; the instruction to add
    • insert

      public void insert(int at, DalvInsn insn)
      Inserts an instruction in the output at the given offset.
      Parameters:
      at - at >= 0; what index to insert at
      insn - non-null; the instruction to insert
    • get

      public DalvInsn get(int at)
    • size

      public int size()
    • reverseBranch

      public void reverseBranch(int which, CodeAddress newTarget)
      Reverses a branch which is buried a given number of instructions backward in the output. It is illegal to call this unless the indicated instruction really is a reversible branch.
      Parameters:
      which - how many instructions back to find the branch; 0 is the most recently added instruction, 1 is the instruction before that, etc.
      newTarget - non-null; the new target for the reversed branch
    • assignIndices

      public void assignIndices(DalvCode.AssignIndicesCallback callback)
      Assigns indices in all instructions that need them, using the given callback to perform lookups. This should be called before calling finishProcessingAndGetList().
      Parameters:
      callback - non-null; callback object
    • finishProcessingAndGetList

      public DalvInsnList finishProcessingAndGetList()
      Does final processing on this instance and gets the output as a DalvInsnList. Final processing consists of:
      • optionally renumbering registers (to make room as needed for expanded instructions)
      • picking a final opcode for each instruction
      • rewriting instructions, because of register number, constant pool index, or branch target size issues
      • assigning final addresses

      Note: This method may only be called once per instance of this class.

      Returns:
      non-null; the output list
      Throws:
      UnsupportedOperationException - if this method has already been called