Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

FindPattern Class Reference

Inheritance diagram for FindPattern:
[legend]
Collaboration diagram for FindPattern:
[legend]
List of all members.

Public Methods

final InstructionList getInstructionList ()
final InstructionHandle[] getMatch ()
final int getMatchLength ()
final void reread ()
final InstructionHandle search (String pattern)
final InstructionHandle search (String pattern, CodeConstraint constraint)
final InstructionHandle search (String pattern, InstructionHandle from)
final InstructionHandle search (String pattern, InstructionHandle from, CodeConstraint constraint)
final void setInstructionList (InstructionList il)
final InstructionList getInstructionList ()
final InstructionHandle[] getMatch ()
final int getMatchLength ()
final void reread ()
final InstructionHandle search (String pattern)
final InstructionHandle search (String pattern, CodeConstraint constraint)
final InstructionHandle search (String pattern, InstructionHandle from)
final InstructionHandle search (String pattern, InstructionHandle from, CodeConstraint constraint)
final void setInstructionList (InstructionList il)

Static Public Methods

 FindPattern (InstructionList il)
 FindPattern (InstructionList il)

Static Private Methods

final void appendPatterns (StringBuffer buf, short from, short to)
final String getPattern (String pattern)
final char makeChar (short opcode)
final String makePattern (String pattern)
final String pattern2string (String pattern)
final String pattern2string (String pattern, boolean make_string)
final void appendPatterns (StringBuffer buf, short from, short to)
final String getPattern (String pattern)
final char makeChar (short opcode)
final String makePattern (String pattern)
final String pattern2string (String pattern)
final String pattern2string (String pattern, boolean make_string)

Private Attributes

InstructionList il
String il_string
InstructionHandle[] handles
int match_length
int matched_from
InstructionHandle[] handles

Static Private Attributes

final int OFFSET = 32767
final int NO_OPCODES = 256
final String[] patterns
String[] pattern_map
final String[] patterns
String[] pattern_map

Detailed Description

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.1.1.1 2002/01/24 03:44:05 pserver Exp
Author:
M. Dahm
See also:
Instruction , InstructionList , CodeConstraint

Definition at line 23 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.


Constructor & Destructor Documentation

FindPattern::FindPattern InstructionList   il [inline, static]
 

Parameters:
il   instruction list to search for given patterns

Definition at line 210 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

FindPattern::FindPattern InstructionList   il [inline, static]
 

Parameters:
il   instruction list to search for given patterns

Definition at line 210 of file src/de/fub/bytecode/generic/FindPattern.java.


Member Function Documentation

final void FindPattern::appendPatterns StringBuffer   buf,
short   from,
short   to
[inline, static, private]
 

Append instructions characters starting from `start' to `to'.

Definition at line 217 of file src/de/fub/bytecode/generic/FindPattern.java.

final void FindPattern::appendPatterns StringBuffer   buf,
short   from,
short   to
[inline, static, private]
 

Append instructions characters starting from `start' to `to'.

Definition at line 217 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

final InstructionList FindPattern::getInstructionList   [inline]
 

Returns:
the inquired instruction list

Definition at line 228 of file src/de/fub/bytecode/generic/FindPattern.java.

final InstructionList FindPattern::getInstructionList   [inline]
 

Returns:
the inquired instruction list

Definition at line 228 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

final InstructionHandle [] FindPattern::getMatch   [inline]
 

Returns:
the matched piece of code as an array of instruction (handles)

Definition at line 232 of file src/de/fub/bytecode/generic/FindPattern.java.

final InstructionHandle [] FindPattern::getMatch   [inline]
 

Returns:
the matched piece of code as an array of instruction (handles)

Definition at line 232 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

final int FindPattern::getMatchLength   [inline]
 

Returns:
number of matched instructions, or -1 if the match did not succeed

Definition at line 244 of file src/de/fub/bytecode/generic/FindPattern.java.

final int FindPattern::getMatchLength   [inline]
 

Returns:
number of matched instructions, or -1 if the match did not succeed

Definition at line 244 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

final String FindPattern::getPattern String   pattern [inline, static, private]
 

Map symbolic strings like `branchinstruction' or `'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".

Definition at line 252 of file src/de/fub/bytecode/generic/FindPattern.java.

final String FindPattern::getPattern String   pattern [inline, static, private]
 

Map symbolic strings like `branchinstruction' or `'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".

Definition at line 252 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

final char FindPattern::makeChar short   opcode [inline, static, private]
 

Convert opcode number to char.

Definition at line 269 of file src/de/fub/bytecode/generic/FindPattern.java.

final char FindPattern::makeChar short   opcode [inline, static, private]
 

Convert opcode number to char.

Definition at line 269 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

Referenced by appendPatterns(), and getPattern().

final String FindPattern::makePattern String   pattern [inline, static, private]
 

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

Definition at line 281 of file src/de/fub/bytecode/generic/FindPattern.java.

final String FindPattern::makePattern String   pattern [inline, static, private]
 

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

Definition at line 281 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

final String FindPattern::pattern2string String   pattern [inline, static, private]
 

Internal debugging routines.

Definition at line 331 of file src/de/fub/bytecode/generic/FindPattern.java.

final String FindPattern::pattern2string String   pattern [inline, static, private]
 

Internal debugging routines.

Definition at line 331 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

final void FindPattern::reread   [inline]
 

Rereads the instruction list, e.g., after you've altered the list upon a match.

Definition at line 355 of file src/de/fub/bytecode/generic/FindPattern.java.

final void FindPattern::reread   [inline]
 

Rereads the instruction list, e.g., after you've altered the list upon a match.

Definition at line 355 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

Referenced by FindPattern().

final InstructionHandle FindPattern::search String   pattern,
InstructionHandle   from,
CodeConstraint   constraint
[inline]
 

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

Definition at line 432 of file src/de/fub/bytecode/generic/FindPattern.java.

final InstructionHandle FindPattern::search String   pattern,
InstructionHandle   from
[inline]
 

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

Definition at line 395 of file src/de/fub/bytecode/generic/FindPattern.java.

final InstructionHandle FindPattern::search String   pattern,
CodeConstraint   constraint
[inline]
 

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

Definition at line 385 of file src/de/fub/bytecode/generic/FindPattern.java.

final InstructionHandle FindPattern::search String   pattern [inline]
 

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

Definition at line 374 of file src/de/fub/bytecode/generic/FindPattern.java.

final InstructionHandle FindPattern::search String   pattern,
InstructionHandle   from,
CodeConstraint   constraint
[inline]
 

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

Definition at line 432 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

final InstructionHandle FindPattern::search String   pattern,
InstructionHandle   from
[inline]
 

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

Definition at line 395 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

final InstructionHandle FindPattern::search String   pattern,
CodeConstraint   constraint
[inline]
 

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

Definition at line 385 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

final InstructionHandle FindPattern::search String   pattern [inline]
 

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

Definition at line 374 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.

final void FindPattern::setInstructionList InstructionList   il [inline]
 

Defines a new instruction list. Automatically calls reread() to update the object.

Parameters:
il   the new instuction list

Definition at line 473 of file src/de/fub/bytecode/generic/FindPattern.java.

final void FindPattern::setInstructionList InstructionList   il [inline]
 

Defines a new instruction list. Automatically calls reread() to update the object.

Parameters:
il   the new instuction list

Definition at line 473 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.


Member Data Documentation

final String [] FindPattern::patterns [static, private]
 

Initial value:

 {
    "instruction", "branchinstruction", "if_icmp__", "if__", "push",
    "iload__", "aload__", "fload__", "dload__", "lload__",
    "istore__", "astore__", "fstore__", "dstore__", "lstore__",
    "invokeinstruction", "returninstruction", "ifinstruction"
  }

Definition at line 27 of file src/de/fub/bytecode/generic/FindPattern.java.

final String [] FindPattern::patterns [static, private]
 

Initial value:

 {
    "instruction", "branchinstruction", "if_icmp__", "if__", "push",
    "iload__", "aload__", "fload__", "dload__", "lload__",
    "istore__", "astore__", "fstore__", "dstore__", "lstore__",
    "invokeinstruction", "returninstruction", "ifinstruction"
  }

Definition at line 27 of file lib/jpf/de/fub/bytecode/generic/FindPattern.java.


The documentation for this class was generated from the following files:
Generated at Thu Feb 7 07:11:34 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001