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
-
aload_pattern
-
-
astore_pattern
-
-
binstruction_pattern
-
-
dload_pattern
-
-
dstore_pattern
-
-
fload_pattern
-
-
fstore_pattern
-
-
handles
-
-
if_icmp_pattern
-
-
if_pattern
-
-
il
-
-
il_string
-
-
iload_pattern
-
-
instruction_pattern
-
-
istore_pattern
-
-
lload_pattern
-
-
lstore_pattern
-
-
match_length
-
-
matched_from
-
-
NO_OPCODES
-
-
OFFSET
-
-
pattern_map
-
-
patterns
-
-
push_pattern
-
-
regex
-
-
FindPattern(InstructionList)
-
-
()
-
-
appendPatterns(StringBuffer, short, short)
- Append instructions characters starting from `start' to `to'.
-
getInstructionList()
-
-
getMatch()
-
-
getMatchLength()
-
-
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)
-
makePattern(String)
- Replace all occurences of `something' with the appropiate pattern, the `' chars
are used as an escape sequence.
-
pattern2string(String)
- Internal debugging routines.
-
pattern2string(String, boolean)
-
-
reread()
- Rereads the instruction list, e.g., if you've altered the list upon a match.
-
search(String)
- Start search beginning from the start of the given instruction list.
-
search(String, CodeConstraint)
- Start search beginning from the start of the given instruction list.
-
search(String, InstructionHandle)
- Start search beginning from `from'.
-
search(String, InstructionHandle, CodeConstraint)
- Search for the given pattern in the InstructionList.
-
setInstructionList(InstructionList)
- Defines a new instruction list.
OFFSET
private static final int OFFSET
NO_OPCODES
private static final int NO_OPCODES
instruction_pattern
private static String instruction_pattern
binstruction_pattern
private static String binstruction_pattern
if_icmp_pattern
private static String if_icmp_pattern
if_pattern
private static String if_pattern
push_pattern
private static String push_pattern
iload_pattern
private static String iload_pattern
aload_pattern
private static String aload_pattern
fload_pattern
private static String fload_pattern
dload_pattern
private static String dload_pattern
lload_pattern
private static String lload_pattern
istore_pattern
private static String istore_pattern
astore_pattern
private static String astore_pattern
fstore_pattern
private static String fstore_pattern
dstore_pattern
private static String dstore_pattern
lstore_pattern
private static String lstore_pattern
patterns
private static final String patterns[]
pattern_map
private static String pattern_map[]
il
private InstructionList il
il_string
private String il_string
regex
private Regex regex
handles
private InstructionHandle handles[]
match_length
private int match_length
matched_from
private int matched_from
FindPattern
public FindPattern(InstructionList il)
- Parameters:
- il - instruction list to search for given patterns
reread
public final void reread()
- Rereads the instruction list, e.g., if you've altered the list upon a match.
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".
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
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
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
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
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
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
pattern2string
private static final String pattern2string(String pattern)
- Internal debugging routines.
pattern2string
private static final String pattern2string(String pattern,
boolean make_string)
static void ()
appendPatterns
private static final void appendPatterns(StringBuffer buf,
short from,
short to)
- Append instructions characters starting from `start' to `to'.
getInstructionList
public final InstructionList getInstructionList()
- Returns:
- the inquired instruction list
All Packages Class Hierarchy This Package Previous Next Index