Class AssemblyConstructState
This is roughly analogous to ConstructState
, but for assembly. It records the assembly
semantic, i.e., SLEIGH constructor, and the child states, one for each operand in the
constructor. It's implementation of resolve(AssemblyResolvedPatterns, Collection)
encapsulates, perhaps the very kernel of, machine-code generation. Operands can have there own
complexity, but most of the core machine-code concepts of SLEIGH are handled by constructors.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final List
<AbstractAssemblyState> protected final AssemblyConstructorSemantic
-
Constructor Summary
ConstructorDescriptionAssemblyConstructState
(AbstractAssemblyTreeResolver<?> resolver, List<AssemblyConstructorSemantic> path, int shift, AssemblyConstructorSemantic sem, List<AbstractAssemblyState> children) Construct the state for a selected SLEIGH constructor of a sub-table operand -
Method Summary
Modifier and TypeMethodDescriptionprotected static int
computeEnd
(List<? extends AbstractAssemblyState> operands) Compute the farthest end byte (exclusive) among the given operandsint
Pre compute this nodes hashboolean
protected Stream
<AssemblyResolvedPatterns> resolve
(AssemblyResolvedPatterns fromRight, Collection<AssemblyResolvedError> errors) Generate machine (partial) code for this nodeprotected Stream
<AssemblyResolvedPatterns> resolveMutations
(AssemblyResolvedPatterns fromChildren, Collection<AssemblyResolvedError> errors) Solve the mutations for the selected constructorprotected Stream
<AssemblyResolvedPatterns> resolvePatterns
(AssemblyResolvedPatterns fromMutations, Collection<AssemblyResolvedError> errors) Apply each possible pattern for the selected constructorprotected Stream
<AssemblyResolvedPatterns> resolveRemainingChildren
(AssemblyResolvedPatterns fromRight, Collection<AssemblyResolvedError> errors, List<AbstractAssemblyState> children) A recursive function from resolving all children right-to-left and accumulating the patternstoString()
Methods inherited from class ghidra.app.plugin.assembler.sleigh.sem.AbstractAssemblyState
getLength, getPath, getResolver, getShift, hashCode
-
Field Details
-
sem
-
children
-
-
Constructor Details
-
AssemblyConstructState
public AssemblyConstructState(AbstractAssemblyTreeResolver<?> resolver, List<AssemblyConstructorSemantic> path, int shift, AssemblyConstructorSemantic sem, List<AbstractAssemblyState> children) Construct the state for a selected SLEIGH constructor of a sub-table operandThe operand's length is computed from the constructors length and the shifts and lengths of its generated operands.
- Parameters:
resolver
- the resolverpath
- the path for diagnosticsshift
- the (right) shift of this operandsem
- the selected SLEIGH constructorchildren
- the child state for each operand in the constructor
-
-
Method Details
-
computeEnd
Compute the farthest end byte (exclusive) among the given operands- Parameters:
operands
- the operands- Returns:
- the farthest end byte
-
computeHash
public int computeHash()Description copied from class:AbstractAssemblyState
Pre compute this nodes hash- Specified by:
computeHash
in classAbstractAssemblyState
- Returns:
- the hash
-
equals
- Specified by:
equals
in classAbstractAssemblyState
-
toString
-
resolve
protected Stream<AssemblyResolvedPatterns> resolve(AssemblyResolvedPatterns fromRight, Collection<AssemblyResolvedError> errors) Generate machine (partial) code for this nodeCurrently, this is used to generate machine-code from a generated assembly instruction prototype, but it is not used to apply recursive constructors, i.e., for prefix generation. TODO: That should change. This performs the reverse of the machine-code parsing process, both in concept and in implementation. First, it descends to the children. Each child is a
AbstractAssemblyState
, i.e., either another constructor, or a value operand. (There are also specializations for dealing with hidden constructor and value operands.) Then it solves context changes, in the reverse order of the specification. Finally, it applies the patterns, in order to satisfy the constraints specified by the constructor. As a final detail, it records, for diagnostic purposes, the intermediate child patterns into the parent pattern.- Specified by:
resolve
in classAbstractAssemblyState
- Parameters:
fromRight
- the accumulated patterns thus far, from the right sibling or left-most childerrors
- a place to collect error reports- Returns:
- the stream of generated patterns, as accumulated
-
resolvePatterns
protected Stream<AssemblyResolvedPatterns> resolvePatterns(AssemblyResolvedPatterns fromMutations, Collection<AssemblyResolvedError> errors) Apply each possible pattern for the selected constructor- Parameters:
fromMutations
- the assembly pattern after mutations were solvederrors
- a place to collect errors- Returns:
- the stream of patterns, as accumulated with
fromMutations
-
resolveMutations
protected Stream<AssemblyResolvedPatterns> resolveMutations(AssemblyResolvedPatterns fromChildren, Collection<AssemblyResolvedError> errors) Solve the mutations for the selected constructor- Parameters:
fromChildren
- the assembly pattern as accumulated from the left-most childerrors
- a place to collect errors- Returns:
- the stream of patterns, as accumulated with
fromChildren
-
resolveRemainingChildren
protected Stream<AssemblyResolvedPatterns> resolveRemainingChildren(AssemblyResolvedPatterns fromRight, Collection<AssemblyResolvedError> errors, List<AbstractAssemblyState> children) A recursive function from resolving all children right-to-left and accumulating the patternsThis pops the right-most child in
children
, resolves it, and then recurses, passing the accumulated patterns in asfromRight
with the remaining children.Stream.flatMap(java.util.function.Function)
makes this somewhat fluent, given the possibility of multiple resolutions.- Parameters:
fromRight
- the assembly pattern as accumulated from the right sibling. If this is the right-most sibling, then this is the pattern accumulated from the parent's right sibling, as so on. If no such sibling exists, it is the unrestricted (empty) pattern.errors
- a place to collect errorschildren
- the remaining children to resolve- Returns:
- the stream of accumulated patterns
-