Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class DE.fub.inf.JVM.ClassGen.FindPattern

java.lang.Object
  |
  +--DE.fub.inf.JVM.ClassGen.FindPattern

public final class FindPattern
extends java.lang.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 COM.stevesoft.pat to search for regular expressions. Pat comes as a distribution of its own rights.

Version:
$Id: FindPattern.java,v 1.1 1998/07/01 13:06:23 dahm Exp $
Author:
M. Dahm
See Also:
Instruction, InstructionList, Regex, CodeConstraint

Constructor Summary
FindPattern(InstructionList il)
           
 
Method Summary
InstructionList getInstructionList()
           
InstructionHandle[] getMatch()
           
int getMatchLength()
           
void reread()
          Rereads the instruction list, e.g.
InstructionHandle search(java.lang.String pattern, InstructionHandle from, CodeConstraint constraint)
          Search for the given pattern in the InstructionList.
InstructionHandle search(java.lang.String pattern)
          Start search beginning from the start of the given instruction list.
InstructionHandle search(java.lang.String pattern, InstructionHandle from)
          Start search beginning from `from'.
InstructionHandle search(java.lang.String pattern, CodeConstraint constraint)
          Start search beginning from the start of the given instruction list.
void setInstructionList(InstructionList il)
          Defines a new instruction list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Constructor Detail

FindPattern

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

reread

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

search

public final InstructionHandle search(java.lang.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' `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

search

public final InstructionHandle search(java.lang.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

search

public final InstructionHandle search(java.lang.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

search

public final InstructionHandle search(java.lang.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

getMatchLength

public final int getMatchLength()
Returns:
number of matched instructions, or -1 if the match did not succeed

getMatch

public final InstructionHandle[] getMatch()
Returns:
the matched piece of code as an array of instruction (handles)

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

getInstructionList

public final InstructionList getInstructionList()
Returns:
the inquired instruction list

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD