public class

EPatternCompiler

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.core.units.code.asm.decompiler.ir.compiler.EPatternCompiler

Class Overview

IR expression pattern compiler. (Do not confuse this class with the IR compiler.)

Can compile, match and optionally replace full list statements or pure expressions.

Rules:

 Use parentheses. The parser is relatively simple and does not know about operator precedence.
 Therefore, an excess of parens around expressions is better than the reverse.
 
 Immediate literals: should always start with a digit. Therefore, to use write in base 16, use the 0x prefix.
 Negative literals are allowed but must be enclosed in parens, e.g. (-3).
 
 Special BOL characters:
 > at beginning of line indicates the trigger (if unspecified,
   the most appropriate trigger statement will be determined heuristically)
 X at beginning of line indicates that the input expression should not be
   discarded during a replacement (if any). It can only be used for leading
   and trailing statements of an input pattern. Gaps are not allowed.
 
 Triggers for leaves:
   $      any (terminals and non-terminals)
   T      terminals (imm, var, range)
   N      non-terminals
   V      variables
   #      immediates
   DIGITS a specific immediate (an optional id can be specified in curly braces after the value)
 
 Examples:
   $0     match any expression, assign the id 0
   V1     match any EVar, assign the id 1
   #2     match any immediate; assign the id 2 to it
   10     match an immediate holding the value 10, of any size; do not assign an id to it (will not be in the matchmap)
   10{2}  match an immediate holding the value 10; assign the id 2 to it
 
 When compiling an output pattern for replacement, immediates can reference existing matched-item ids,
 in which case their bitsize will be the one of the matched item.
 When an output pattern uses id-less immediates, the pattern-replacer engine will attempt to infer its bitsize
 from the surrounding expression. (Not recommended.) 
 

See Also

Summary

Nested Classes
class EPatternCompiler.EPattern IR expression multi-pattern, consisting of one or more inputs, and zero or one output (for replacement). 
Constants
int FLAG_NO_VARIABLE_LEAF_OVERLAP This flag is used to indicate that input patterns leaves matching EVar should not map to overlapped IR elements.
int FLAG_SAME_BITSIZE_FOR_LEAVES This flag indicates that all leaves in the input pattern must have the same bitsize.
Fields
public static final EPatternCompiler DEFAULT_COMPILER A static pattern compiler using default settings (no flags).
Public Constructors
EPatternCompiler(int flags)
Create a pattern compiler.
EPatternCompiler()
Create a pattern compiler using default settings.
Public Methods
EPatternCompiler.EPattern compile(EPatternCompiler.EPattern pattern)
Compile an IR pattern.
int getFlags()
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int FLAG_NO_VARIABLE_LEAF_OVERLAP

This flag is used to indicate that input patterns leaves matching EVar should not map to overlapped IR elements.

Example:

 Pattern: V0 = V1
 IR:      r5 = r5
 
If this flag is specified, the pattern will not match on the IR since leaves ids 0 and 1 would map to the same underlying IR EVar r5.

Constant Value: 1 (0x00000001)

public static final int FLAG_SAME_BITSIZE_FOR_LEAVES

This flag indicates that all leaves in the input pattern must have the same bitsize.

If some leaves in the pattern have specified (required) bitsizes, then those bitsizes must be the same and other leaves with unspecified bitsizes must have that same bitsize as well, else matching will fail.

Constant Value: 2 (0x00000002)

Fields

public static final EPatternCompiler DEFAULT_COMPILER

A static pattern compiler using default settings (no flags).

Public Constructors

public EPatternCompiler (int flags)

Create a pattern compiler.

Parameters
flags compiler flags

public EPatternCompiler ()

Create a pattern compiler using default settings.

Public Methods

public EPatternCompiler.EPattern compile (EPatternCompiler.EPattern pattern)

Compile an IR pattern.

Parameters
pattern a non-compiled pattern; attempting to compile an already-compiled pattern will raise an IllegalStateException
Returns
  • this pattern, compiled

public int getFlags ()