All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class espresso.classfile.classgen.FindPattern

java.lang.Object
   |
   +----espresso.classfile.classgen.FindPattern

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

See Also:
Instruction, InstructionList, Regex, CodeConstraint

Variable Index

 o aload_pattern
 o astore_pattern
 o binstruction_pattern
 o dload_pattern
 o dstore_pattern
 o fload_pattern
 o fstore_pattern
 o handles
 o if_icmp_pattern
 o if_pattern
 o il
 o il_string
 o iload_pattern
 o instruction_pattern
 o istore_pattern
 o lload_pattern
 o lstore_pattern
 o match_length
 o matched_from
 o NO_OPCODES
 o OFFSET
 o pattern_map
 o patterns
 o push_pattern
 o regex

Constructor Index

 o FindPattern(InstructionList)

Method Index

 o ()
 o appendPatterns(StringBuffer, short, short)
Append instructions characters starting from `start' to `to'.
 o getInstructionList()
 o getMatch()
 o getMatchLength()
 o getPattern(String)
Make a pattern such as `branchinstruction' a regular expression string such as (a|b|z) (where a,b,c whil be non-printable characters in LATIN-1)
 o makePattern(String)
Replace all occurences of `something' with the appropiate pattern, the `' chars are used as an escape sequence.
 o pattern2string(String)
Internal debugging routines.
 o pattern2string(String, boolean)
 o reread()
Rereads the instruction list, e.g., if 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.

Variables

 o OFFSET
 private static final int OFFSET
 o NO_OPCODES
 private static final int NO_OPCODES
 o instruction_pattern
 private static String instruction_pattern
 o binstruction_pattern
 private static String binstruction_pattern
 o if_icmp_pattern
 private static String if_icmp_pattern
 o if_pattern
 private static String if_pattern
 o push_pattern
 private static String push_pattern
 o iload_pattern
 private static String iload_pattern
 o aload_pattern
 private static String aload_pattern
 o fload_pattern
 private static String fload_pattern
 o dload_pattern
 private static String dload_pattern
 o lload_pattern
 private static String lload_pattern
 o istore_pattern
 private static String istore_pattern
 o astore_pattern
 private static String astore_pattern
 o fstore_pattern
 private static String fstore_pattern
 o dstore_pattern
 private static String dstore_pattern
 o lstore_pattern
 private static String lstore_pattern
 o patterns
 private static final String patterns[]
 o pattern_map
 private static String pattern_map[]
 o il
 private InstructionList il
 o il_string
 private String il_string
 o regex
 private Regex regex
 o handles
 private InstructionHandle handles[]
 o match_length
 private int match_length
 o matched_from
 private int matched_from

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., if you've altered the list upon a match.

 o getPattern
 private static final String getPattern(String pattern)
Make a pattern such as `branchinstruction' a regular expression string such as (a|b|z) (where a,b,c whil be non-printable characters in LATIN-1)

Parameters:
pattern - instruction pattern in lower case
Returns:
encoded string for a pattern such as "BranchInstruction".
 o makePattern
 private static final String makePattern(String pattern)
Replace all occurences of `something' with the appropiate pattern, the `' chars are used as an escape sequence. Other characters than the escaped one will be ignored, in particular the meta characters used for regular expression such as *, +, [, etc.

Parameters:
pattern - The pattern to compile
Returns:
complete regular expression string
 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' `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 pattern2string
 private static final String pattern2string(String pattern)
Internal debugging routines.

 o pattern2string
 private static final String pattern2string(String pattern,
                                            boolean make_string)
 o
 static void ()
 o appendPatterns
 private static final void appendPatterns(StringBuffer buf,
                                          short from,
                                          short to)
Append instructions characters starting from `start' to `to'.

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

All Packages  Class Hierarchy  This Package  Previous  Next  Index