alt.jiapi.reflect
Class InstructionList

java.lang.Object
  extended by alt.jiapi.reflect.InstructionList

public class InstructionList
extends java.lang.Object

InstructionList is a place holder for Instructions.

Author:
Mika Riekkinen

Constructor Summary
InstructionList()
           
 
Method Summary
 void add(Instruction i)
          Adds an Instruction to this InstructionList
 void add(InstructionList il)
          Adds all the Instructions in given list to this list.
 void clear()
          Clears this InstructionList.
 InstructionList createEmptyList()
          Create an empty list.
 InstructionList createView(int start)
          Creates a view.
 InstructionList createView(int start, int end)
          Creates a view.
 java.util.List findBranchesForTarget(Instruction target)
           
 Instruction get(int i)
          Gets an Instruction at given index.
 byte[] getBytes()
          Gets this InstructionList as a byte array.
 JiapiMethod getDeclaringMethod()
          Gets the declaring JiapiMethod of this InstructionList
 InstructionFactory getInstructionFactory()
          Get the InstructionFactory, that is associated with this InstructionList.
 int indexOf(byte opcode)
          Scans this InstructionList for a opcode.
 int indexOf(byte[] opcodes, int fromIndex)
          Scans this InstructionList for opcodes.
 int indexOf(byte opcode, int fromIndex)
          Scans this InstructionList for a opcode.
 int indexOf(Instruction ins)
          Scans this InstructionList for a opcode.
 boolean insert(int idx, Instruction i)
          Insert an Instruction to this InstructionList
 boolean insert(int idx, InstructionList il)
          Insert an InstructionList to this InstructionList
 void replace(InstructionList il)
           
 void replace(int idx, Instruction i)
          Replace an Instruction at given index
 void replace(int start, int end, InstructionList il)
          Replaces instructions with given range.
 int size()
          Gets the size of this InstructionList.
 int stackUsage()
          Calculates stack-usage of this InstructionList
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InstructionList

public InstructionList()
Method Detail

add

public void add(Instruction i)
Adds an Instruction to this InstructionList


add

public void add(InstructionList il)
Adds all the Instructions in given list to this list.

Parameters:
il - InstructionList to add

clear

public void clear()
Clears this InstructionList. All the Instructions are removed.


createEmptyList

public InstructionList createEmptyList()
Create an empty list.


createView

public InstructionList createView(int start)
Creates a view. View is created from start to the end of this list.

Parameters:
start - start of the view, inclusive

createView

public InstructionList createView(int start,
                                  int end)
Creates a view.

Parameters:
start - start of the view, inclusive
end - end of the view, exclusive

findBranchesForTarget

public java.util.List findBranchesForTarget(Instruction target)

get

public Instruction get(int i)
Gets an Instruction at given index. IndexOutOfBoundsException is thrown if index is not within this InstructionList

Parameters:
i - index
Returns:
Instruction

getBytes

public byte[] getBytes()
Gets this InstructionList as a byte array. This byte array may be put into alt.jiapi.file.Method as a code attribute. No checking is being made, whether this byte array makes any sense or not. It is thus the responsibility of the developer to keep this list in a correct form.

Returns:
a byte array representing this InstructionList

getDeclaringMethod

public JiapiMethod getDeclaringMethod()
Gets the declaring JiapiMethod of this InstructionList


getInstructionFactory

public InstructionFactory getInstructionFactory()
Get the InstructionFactory, that is associated with this InstructionList.


indexOf

public int indexOf(byte opcode)
Scans this InstructionList for a opcode. Scanning is started from the beginning of the InstructionList.

Parameters:
opcode - Opcode to look for
Returns:
index of the instruction that was found, or -1 if not found.

indexOf

public int indexOf(byte[] opcodes,
                   int fromIndex)
Scans this InstructionList for opcodes.

Parameters:
fromIndex - Index to start scanning from
opcodes - opcode to look for
Returns:
index of the instruction that was found, or -1 if not found.

indexOf

public int indexOf(byte opcode,
                   int fromIndex)
Scans this InstructionList for a opcode.

Parameters:
start - Index to start scanning from
opcode - Opcode to look for
Returns:
index of the instruction that was found, or -1 if not found.

indexOf

public int indexOf(Instruction ins)
Scans this InstructionList for a opcode. Scanning is started from the beginning of the InstructionList.

Parameters:
ins - Instruction to look for
Returns:
index of the instruction that was found, or -1 if not found.

insert

public boolean insert(int idx,
                      Instruction i)
Insert an Instruction to this InstructionList

Parameters:
idx - index of the Instruction
i - Instruction to insert

insert

public boolean insert(int idx,
                      InstructionList il)
Insert an InstructionList to this InstructionList

Parameters:
idx - index of the InstructionList
i - Instruction to insert

replace

public void replace(InstructionList il)

replace

public void replace(int idx,
                    Instruction i)
Replace an Instruction at given index

Parameters:
idx - Index of the Instruction to replace
i - Instruction to replace

replace

public void replace(int start,
                    int end,
                    InstructionList il)
Replaces instructions with given range. Stack-usages are checked before replace. If stack usages do not match, an exception is thrown. Furthermore, if instructions to be replaced contain some sort of 'target', like with BranchInstruction, an exception is thrown. Only first instruction to be replaced is allowed to be a 'target'. If this is the case, first Instruction in new list becames that target.

Note, that exception table might get corrupted with this method.

Parameters:
start - start of old Instructions, inclusive
end - end of old Instructions, exclusive
il - InstructionList containing new Instructions.
Throws:
java.lang.IllegalArgumentException - is thrown, if stack-usages do not match
java.lang.IllegalArgumentException - is thrown, if there is an instruction in the range, that is a target to some other entity.

size

public int size()
Gets the size of this InstructionList.

Returns:
number of instructions in this InstructionList

stackUsage

public int stackUsage()
Calculates stack-usage of this InstructionList

Returns:
stack usage

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2001. Documenation generated August 26 2011.