org.ow2.asmdex.lowLevelUtils
Class InstructionEncoder

java.lang.Object
  extended by org.ow2.asmdex.lowLevelUtils.InstructionEncoder

public class InstructionEncoder
extends java.lang.Object

Utility class that encodes Instructions in the most optimized possible form. Each static method builds an Instruction according to its given parameters, and returns it.

Author:
Julien Névo

Constructor Summary
InstructionEncoder()
           
 
Method Summary
static Instruction encodeArrayLength(int destinationRegister, int arrayReferenceBearing)
           
static Instruction encodeArrayOperation(int opcode, int valueRegister, int arrayRegister, int indexRegister)
          Operation on array
static DebugInstruction encodeDebugStartLocal(java.lang.String name, java.lang.String desc, java.lang.String signature, int index, Label start)
          Pseudo debug instruction
static Instruction encodeFieldInsn(int opcode, int valueRegister, int objectRegister, Field field)
          Field getter or setter
static Instruction encodeFillArrayDataInsn(int opcode, int arrayReference, Label arrayLabel, int instructionOffset)
          Fill array
static Instruction encodeInsn(int opcode)
          Encode instructions without args
static Instruction encodeIntInsn(int opcode, int operand)
          Unary instruction
static Instruction encodeJumpInsn(int opcode, Label label, int registerA, int registerB, int instructionOffset)
          Encode jumps (conditional or not)
static Instruction encodeMethodInsn(int opcode, Method method, int[] arguments)
          Method invocation encoder
static Instruction encodeMultiANewArrayInsn(java.lang.String type, int[] registers)
          Multi new array
static Instruction encodeOperationInsn(int opcode, int destinationRegister, int firstSourceRegister, int secondSourceRegister, int value)
          Encode three arguments operations
static Instruction encodeSparseSwitchInsn(int register, Label switchTableLabel, int instructionOffset)
          Sparse switch
static Instruction encodeStringOperation(int opcode, int destinationRegister, java.lang.String string)
          Operation with strings
static Instruction encodeTableSwitchInsn(int register, Label switchTableLabel, int instructionOffset)
          Table switch
static Instruction encodeTypeInsn(int opcode, int destinationRegister, int referenceBearingRegister, int sizeRegister, java.lang.String type)
          Instructions handling type representation
static Instruction encodeVarInsn(int opcode, int destinationRegister, int var)
          Move variable encoder
static Instruction encodeVarInsn(int opcode, int destinationRegister, long var)
          Move variable encoder for long constant source
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InstructionEncoder

public InstructionEncoder()
Method Detail

encodeMethodInsn

public static Instruction encodeMethodInsn(int opcode,
                                           Method method,
                                           int[] arguments)
Method invocation encoder

Parameters:
opcode -
method -
arguments -
Returns:
abstract instruction

encodeVarInsn

public static Instruction encodeVarInsn(int opcode,
                                        int destinationRegister,
                                        int var)
Move variable encoder

Parameters:
opcode -
destinationRegister -
var -
Returns:
instruction encoded

encodeVarInsn

public static Instruction encodeVarInsn(int opcode,
                                        int destinationRegister,
                                        long var)
Move variable encoder for long constant source

Parameters:
opcode -
destinationRegister -
var -
Returns:
abstract instruction

encodeInsn

public static Instruction encodeInsn(int opcode)
Encode instructions without args

Parameters:
opcode -
Returns:
abstract instruction

encodeOperationInsn

public static Instruction encodeOperationInsn(int opcode,
                                              int destinationRegister,
                                              int firstSourceRegister,
                                              int secondSourceRegister,
                                              int value)
Encode three arguments operations

Parameters:
opcode -
destinationRegister -
firstSourceRegister -
secondSourceRegister -
value -
Returns:
abstract instruction

encodeIntInsn

public static Instruction encodeIntInsn(int opcode,
                                        int operand)
Unary instruction

Parameters:
opcode -
operand -
Returns:
abstract instruction

encodeJumpInsn

public static Instruction encodeJumpInsn(int opcode,
                                         Label label,
                                         int registerA,
                                         int registerB,
                                         int instructionOffset)
Encode jumps (conditional or not)

Parameters:
opcode -
label -
registerA -
registerB -
instructionOffset -
Returns:
abstract instruction

encodeFillArrayDataInsn

public static Instruction encodeFillArrayDataInsn(int opcode,
                                                  int arrayReference,
                                                  Label arrayLabel,
                                                  int instructionOffset)
Fill array

Parameters:
opcode -
arrayReference -
arrayLabel -
instructionOffset -
Returns:
abstract instruction

encodeTypeInsn

public static Instruction encodeTypeInsn(int opcode,
                                         int destinationRegister,
                                         int referenceBearingRegister,
                                         int sizeRegister,
                                         java.lang.String type)
Instructions handling type representation

Parameters:
opcode -
destinationRegister -
referenceBearingRegister -
sizeRegister -
type -
Returns:
abstract instruction

encodeMultiANewArrayInsn

public static Instruction encodeMultiANewArrayInsn(java.lang.String type,
                                                   int[] registers)
Multi new array

Parameters:
type -
registers -
Returns:
abstract instruction

encodeTableSwitchInsn

public static Instruction encodeTableSwitchInsn(int register,
                                                Label switchTableLabel,
                                                int instructionOffset)
Table switch

Parameters:
register -
switchTableLabel -
instructionOffset -
Returns:
abstract instruction

encodeSparseSwitchInsn

public static Instruction encodeSparseSwitchInsn(int register,
                                                 Label switchTableLabel,
                                                 int instructionOffset)
Sparse switch

Parameters:
register -
switchTableLabel -
instructionOffset -
Returns:
abstract instruction

encodeArrayLength

public static Instruction encodeArrayLength(int destinationRegister,
                                            int arrayReferenceBearing)
Parameters:
destinationRegister -
arrayReferenceBearing -
Returns:
abstract instruction

encodeArrayOperation

public static Instruction encodeArrayOperation(int opcode,
                                               int valueRegister,
                                               int arrayRegister,
                                               int indexRegister)
Operation on array

Parameters:
opcode -
valueRegister -
arrayRegister -
indexRegister -
Returns:
abstract instruction

encodeStringOperation

public static Instruction encodeStringOperation(int opcode,
                                                int destinationRegister,
                                                java.lang.String string)
Operation with strings

Parameters:
opcode -
destinationRegister -
string -
Returns:
abstract instruction

encodeFieldInsn

public static Instruction encodeFieldInsn(int opcode,
                                          int valueRegister,
                                          int objectRegister,
                                          Field field)
Field getter or setter

Parameters:
opcode -
valueRegister -
objectRegister -
field -
Returns:
abstract instruction

encodeDebugStartLocal

public static DebugInstruction encodeDebugStartLocal(java.lang.String name,
                                                     java.lang.String desc,
                                                     java.lang.String signature,
                                                     int index,
                                                     Label start)
Pseudo debug instruction

Parameters:
name -
desc -
signature -
index -
start -
Returns:
abstract instruction