Class AssemblyConstructorSemantic
- java.lang.Object
-
- ghidra.app.plugin.assembler.sleigh.sem.AssemblyConstructorSemantic
-
- All Implemented Interfaces:
java.lang.Comparable<AssemblyConstructorSemantic>
public class AssemblyConstructorSemantic extends java.lang.Object implements java.lang.Comparable<AssemblyConstructorSemantic>
Describes a SLEIGH constructor semantic These are collected and associated with productions in the grammar based on the given constructor's print pieces.
-
-
Field Summary
Fields Modifier and Type Field Description protected Constructor
cons
protected static DbgTimer
dbg
protected com.google.common.collect.ImmutableList<java.lang.Integer>
indices
protected java.util.Set<AssemblyResolvedConstructor>
patterns
protected static RecursiveDescentSolver
solver
protected com.google.common.collect.ImmutableSet<AssemblyResolvedConstructor>
upatterns
-
Constructor Summary
Constructors Constructor Description AssemblyConstructorSemantic(Constructor cons, java.util.List<java.lang.Integer> indices)
Build a new SLEIGH constructor semantic
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPattern(AssemblyResolvedConstructor pat)
void
addPattern(DisjointPattern pat)
AssemblyResolvedConstructor
applyForward(AssemblyResolvedConstructor outer)
Apply just context transformations in the forward (disassembly) directionint
compareTo(AssemblyConstructorSemantic that)
protected void
computeAllForbids()
Initialize upatterns with an unmodifiable copy of patterns, with forbidden patterns addedConstructor
getConstructor()
Get the SLEIGH constructorint
getOperandIndex(int printpos)
Convert the index of a print piece to its associated operand indexjava.util.Iterator<java.lang.Integer>
getOperandIndexIterator()
Get an iterator over the operand indices If this iterator is advanced for each non-terminal, while simultaneously iterating over the RHS of the associated production, then this will identify the corresponding operand index for each non-terminalcom.google.common.collect.ImmutableList<java.lang.Integer>
getOperandIndices()
Get the list of operand indices in print piece orderjava.util.Collection<AssemblyResolvedConstructor>
getPatterns()
Get the associated encoding patterns for the constructorAssemblyResolution
solveContextChanges(AssemblyResolvedConstructor res, java.util.Map<java.lang.String,java.lang.Long> vals, java.util.Map<java.lang.Integer,java.lang.Object> opvals)
Solve this constructor's context changesjava.lang.String
toString()
protected AssemblyResolvedConstructor
withComputedForbids(AssemblyResolvedConstructor pat)
Add the list of forbidden patterns to one of the constructor's patterns SLEIGH disambiguates multiple matching pattern by two rules.
-
-
-
Field Detail
-
solver
protected static final RecursiveDescentSolver solver
-
dbg
protected static final DbgTimer dbg
-
patterns
protected final java.util.Set<AssemblyResolvedConstructor> patterns
-
cons
protected final Constructor cons
-
indices
protected final com.google.common.collect.ImmutableList<java.lang.Integer> indices
-
upatterns
protected com.google.common.collect.ImmutableSet<AssemblyResolvedConstructor> upatterns
-
-
Constructor Detail
-
AssemblyConstructorSemantic
public AssemblyConstructorSemantic(Constructor cons, java.util.List<java.lang.Integer> indices)
Build a new SLEIGH constructor semantic- Parameters:
pattern
- the encoding pattern associated with the constructorcons
- the SLEIGH constructorindices
- the indices of RHS non-terminals in the associated production that represent an operand in the SLEIGH constructor
-
-
Method Detail
-
addPattern
public void addPattern(DisjointPattern pat)
-
addPattern
public void addPattern(AssemblyResolvedConstructor pat)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getConstructor
public Constructor getConstructor()
Get the SLEIGH constructor- Returns:
- the constructor
-
getPatterns
public java.util.Collection<AssemblyResolvedConstructor> getPatterns()
Get the associated encoding patterns for the constructor- Returns:
- the patterns
-
getOperandIndex
public int getOperandIndex(int printpos)
Convert the index of a print piece to its associated operand index- Parameters:
printpos
- position excluding whitespace and string tokens.- Returns:
- the operand index
-
getOperandIndices
public com.google.common.collect.ImmutableList<java.lang.Integer> getOperandIndices()
Get the list of operand indices in print piece order- Returns:
- the list
-
getOperandIndexIterator
public java.util.Iterator<java.lang.Integer> getOperandIndexIterator()
Get an iterator over the operand indices If this iterator is advanced for each non-terminal, while simultaneously iterating over the RHS of the associated production, then this will identify the corresponding operand index for each non-terminal- Returns:
- the iterator
-
computeAllForbids
protected void computeAllForbids()
Initialize upatterns with an unmodifiable copy of patterns, with forbidden patterns added
-
withComputedForbids
protected AssemblyResolvedConstructor withComputedForbids(AssemblyResolvedConstructor pat)
Add the list of forbidden patterns to one of the constructor's patterns SLEIGH disambiguates multiple matching pattern by two rules. First, if one is more specific than ("specializes") another, i.e., it matches on more bits than another pattern, the more specific pattern is chosen. Second, if the two are equally special, then the one that occurs first in the SLEIGH specification is taken. So, during resolution, if a less-special or later-occurring constructor is chosen, we must prevent continued resolution from matching the more-special or earlier-occurring pattern(s). Essentially, this states, "you may choose any value matching my pattern, except those that match these forbidden patterns." This takes a given pattern, and searches the rest of the language for any patterns that would take precedence, and combines them as forbidden patterns with the given pattern.- Parameters:
pat2
- the given pattern
-
solveContextChanges
public AssemblyResolution solveContextChanges(AssemblyResolvedConstructor res, java.util.Map<java.lang.String,java.lang.Long> vals, java.util.Map<java.lang.Integer,java.lang.Object> opvals)
Solve this constructor's context changes- Parameters:
res
- the combined resolution requirements derived from the subconstructorsvals
- any defined symbols (usuallyinst_start
, andinst_next
)opvals
- a map from operand index to operand value- Returns:
- the resolution with context changes applied in reverse, or an error
Each value in
opvals
must either be a numeric value, e.g., an index from a varnode list, or anotherAssemblyResolvedConstructor
for a subconstructor operand. It's helpful to think of the SLEIGH disassembly process here. Normally, once the appropriate constructor has been identified (by matching patterns), its context changes are applied, and then its operands parsed (possibly parsing subconstructor operands). Thus,res
can be thought of as the intermediate result between applying context changes and parsing operands, except in reverse. The output of this method corresponds to the state before context changes were applied, i.e., immediately after selecting the constructor. Thus, in reverse, the context is solved immediately before applying the selected constructor patterns. - See Also:
AssemblyTreeResolver#resolveSelectedChildren(AssemblyProduction, List, List, Collection)
-
applyForward
public AssemblyResolvedConstructor applyForward(AssemblyResolvedConstructor outer)
Apply just context transformations in the forward (disassembly) direction- Parameters:
outer
- the state before context changes- Returns:
- the state after context changes
Unlike the usual disassembly process, this method does not take into account any information
from the instruction encoding. Any context bits that depend on it are set to unknown
(
x
) in the output. This method is used to pre-compute a context transition graph in order to quickly resolve purely-recursive semantics on the root constructor table.
-
compareTo
public int compareTo(AssemblyConstructorSemantic that)
- Specified by:
compareTo
in interfacejava.lang.Comparable<AssemblyConstructorSemantic>
-
-