All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class de.fub.bytecode.generic.FindPattern

java.lang.Object
   |
   +----de.fub.bytecode.generic.FindPattern

public class FindPattern
extends Object
implements Constants
This class is an utility to search for given patterns, i.e. regular expressions in an instruction list. This can be used in order to implement a peep hole optimizer that looks for code patterns and replaces them with faster equivalents. This class internally uses the package gnu.regexp to search for regular expressions.

Version:
$Id: FindPattern.java,v 1.6 1999/08/13 08:18:30 dahm Exp $
Author:
M. Dahm
See Also:
Instruction, InstructionList, CodeConstraint

Constructor Index

 o FindPattern(InstructionList)

Method Index

 o getInstructionList()
 o getMatch()
 o getMatchLength()
 o reread()
Rereads the instruction list, e.g., after you've altered the list upon a match.
 o search(String)
Start search beginning from the start of the given instruction list.
 o search(String, CodeConstraint)
Start search beginning from the start of the given instruction list.
 o search(String, InstructionHandle)
Start search beginning from `from'.
 o search(String, InstructionHandle, CodeConstraint)
Search for the given pattern in the InstructionList.
 o setInstructionList(InstructionList)
Defines a new instruction list.

Constructors

 o FindPattern
 public FindPattern(InstructionList il)
Parameters:
il - instruction list to search for given patterns

Methods

 o reread
 public final void reread()
Rereads the instruction list, e.g., after you've altered the list upon a match.

 o search
 public final InstructionHandle search(String pattern,
                                       InstructionHandle from,
                                       CodeConstraint constraint)
Search for the given pattern in the InstructionList. You may use the following special expressions in your pattern string which match instructions that belong to the denoted class. The `' are an escape and must not be omitted. You can use the Instruction names directly: `ILOAD_1', `GOTO', 'NOP', etc.. For convenience there exist some abbreviations for instructions that belong to the same group (underscores _ are used as some kind of wildcards): `Instruction', `BranchInstruction', `InvokeInstruction', `ReturnInstruction', `IfInstruction' correspond to their classes. `IF_ICMP__', `IF__', where __ stands for EQ, LE, etc. `xLOAD__', `xSTORE__', where x stands for I, D, F, L or A. __ is 0..3 or empty `PUSH' stands for any LDC, xCONST__, SIPUSH or BIPUSH instruction You must put the `' around these words or they can't be matched correctly. For the rest the usual (PERL) pattern matching rules apply.

Example pattern:

search("(`BranchInstruction')`NOP'((`IF_ICMP__'|`GOTO')+`ISTORE__'`Instruction')*");
 

Parameters:
pattern - the instruction pattern to search for, case is ignored
from - where to start the search in the instruction list
constraint - optional CodeConstraint to check the found code pattern for given constraints
Returns:
instruction handle or `null' if the matching fails
 o search
 public final InstructionHandle search(String pattern)
Start search beginning from the start of the given instruction list.

Parameters:
pattern - the instruction pattern to search for, case is ignored
Returns:
instruction handle or `null' if the matching fails
 o search
 public final InstructionHandle search(String pattern,
                                       InstructionHandle from)
Start search beginning from `from'.

Parameters:
pattern - the instruction pattern to search for, case is ignored
from - where to start the search in the instruction list
Returns:
instruction handle or `null' if the matching fails
 o search
 public final InstructionHandle search(String pattern,
                                       CodeConstraint constraint)
Start search beginning from the start of the given instruction list. Check found matches with the constraint object.

Parameters:
pattern - the instruction pattern to search for, case is ignored
constraint - constraints to be checked on matching code
Returns:
instruction handle or `null' if the match failed
 o getMatchLength
 public final int getMatchLength()
Returns:
number of matched instructions, or -1 if the match did not succeed
 o getMatch
 public final InstructionHandle[] getMatch()
Returns:
the matched piece of code as an array of instruction (handles)
 o setInstructionList
 public final void setInstructionList(InstructionList il)
Defines a new instruction list. Automatically calls reread() to update the object.

Parameters:
il - the new instuction list
 o getInstructionList
 public final InstructionList getInstructionList()
Returns:
the inquired instruction list

All Packages  Class Hierarchy  This Package  Previous  Next  Index