org.ow2.asmdex.instruction
Class Instruction

java.lang.Object
  extended by org.ow2.asmdex.instruction.Instruction
Direct Known Subclasses:
InstructionFormat10T, InstructionFormat10X, InstructionFormat11N, InstructionFormat11X, InstructionFormat12X, InstructionFormat20T, InstructionFormat21C, InstructionFormat21H, InstructionFormat21S, InstructionFormat21T, InstructionFormat22B, InstructionFormat22C, InstructionFormat22S, InstructionFormat22T, InstructionFormat22X, InstructionFormat23X, InstructionFormat30T, InstructionFormat31C, InstructionFormat31I, InstructionFormat31T, InstructionFormat32X, InstructionFormat35C, InstructionFormat3RC, InstructionFormat51L, PseudoInstructionFillArrayData, PseudoInstructionPackedSwitch, PseudoInstructionSparseSwitch

public abstract class Instruction
extends java.lang.Object

Represents an instruction of the Dalvik bytecode. An instruction also has a Line Number, superior to 0 if set.

Author:
Julien Névo

Field Summary
protected  int lineNumber
          Line Number of this Instruction.
protected  int opcodeByte
          Represents the opcode itself (8 bits).
protected  int opcodeHighOrderByte
          Represents the data of the opcode (8 bits).
 
Constructor Summary
Instruction(int opcode)
          Builds an instruction from its 16-bit opcode.
 
Method Summary
static byte getInstructionSizeInByte(int opcode)
          Returns the size in bytes of the given opcode.
 int getLineNumber()
          Returns the line number of the Instruction.
 int getOpcodeByte()
          Returns the low order byte of the 16-bit opcode (i.e.
 int getOpcodeHighOrderByte()
          Returns the high order byte of the 16-bit opcode.
abstract  int getSize()
          Returns the size of the instruction in bytes.
 void setLineNumber(int lineNumber)
          Sets the line number of the Instruction.
static void test4BitsLimit(int number)
          Tests if the given number can be held in 4 bits, throw an IllegalArgumentException otherwise.
static void test4BitsLimit(int[] numbers)
          Tests if the given numbers can be held in 4 bits, throw an IllegalArgumentException otherwise.
abstract  void write(ByteVector out, ConstantPool constantPool)
          Encodes the instruction, in the Dalvik format, to an output buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

opcodeHighOrderByte

protected int opcodeHighOrderByte
Represents the data of the opcode (8 bits).


opcodeByte

protected int opcodeByte
Represents the opcode itself (8 bits).


lineNumber

protected int lineNumber
Line Number of this Instruction. It must be superior to 0, unless the Line Number has not been set.

Constructor Detail

Instruction

public Instruction(int opcode)
Builds an instruction from its 16-bit opcode.

Parameters:
opcode - the 16-bit opcode of the instruction.
Method Detail

write

public abstract void write(ByteVector out,
                           ConstantPool constantPool)
Encodes the instruction, in the Dalvik format, to an output buffer.

Parameters:
out - output buffer.
constantPool - the constantPool.

getSize

public abstract int getSize()
Returns the size of the instruction in bytes.

Returns:
the size of the instruction in bytes.

getOpcodeHighOrderByte

public int getOpcodeHighOrderByte()
Returns the high order byte of the 16-bit opcode.

Returns:
the high order byte of the 16-bit opcode.

getOpcodeByte

public int getOpcodeByte()
Returns the low order byte of the 16-bit opcode (i.e. the opcode itself).

Returns:
the low order byte of the 16-bit opcode (i.e. the opcode itself).

getLineNumber

public int getLineNumber()
Returns the line number of the Instruction. A line number equals to 0 means that no line number has been set.

Returns:
the line number of the Instruction.

setLineNumber

public void setLineNumber(int lineNumber)
Sets the line number of the Instruction. It must be superior to 0 in order to be valid.

Parameters:
lineNumber - the line number.

test4BitsLimit

public static void test4BitsLimit(int number)
Tests if the given number can be held in 4 bits, throw an IllegalArgumentException otherwise.


test4BitsLimit

public static void test4BitsLimit(int[] numbers)
Tests if the given numbers can be held in 4 bits, throw an IllegalArgumentException otherwise.


getInstructionSizeInByte

public static byte getInstructionSizeInByte(int opcode)
Returns the size in bytes of the given opcode.

Parameters:
opcode - from 0 to 255.
Returns:
the size in bytes of the given opcode.