Class AssemblyConstructStateGenerator
- Direct Known Subclasses:
AssemblyHiddenConstructStateGenerator
AssemblyConstructState
from AssemblyParseBranch
In short, this handles the selection of each possible constructor for the production recorded by a given parse branch.
-
Nested Class Summary
Nested classes/interfaces inherited from class ghidra.app.plugin.assembler.sleigh.sem.AbstractAssemblyStateGenerator
AbstractAssemblyStateGenerator.GeneratorContext
-
Field Summary
Fields inherited from class ghidra.app.plugin.assembler.sleigh.sem.AbstractAssemblyStateGenerator
DBG, fromLeft, node, resolver
-
Constructor Summary
ConstructorDescriptionAssemblyConstructStateGenerator
(AbstractAssemblyTreeResolver<?> resolver, AssemblyParseBranch node, AssemblyResolvedPatterns fromLeft) Construct the instruction state generator or a sub-table operand state generator -
Method Summary
Modifier and TypeMethodDescriptionprotected Stream
<AssemblyGeneratedPrototype> applyConstructor
(AbstractAssemblyStateGenerator.GeneratorContext gc, AssemblyConstructorSemantic sem) Generate prototypes, considering the given SLEIGH constructorprotected Stream
<AssemblyGeneratedPrototype> applyOperands
(AbstractAssemblyStateGenerator.GeneratorContext gc, AssemblyResolvedPatterns fromMutations, AssemblyConstructorSemantic sem, List<AssemblyParseTreeNode> opOrdered) Generate prototypes by considering all the operands of the given SLEIGH constructorprotected Stream
<AssemblyGeneratedPrototype> applyRemainingOperands
(AbstractAssemblyStateGenerator.GeneratorContext parentGc, List<AbstractAssemblyStateGenerator.GeneratorContext> childGcs, AssemblyResolvedPatterns fromLeft, AssemblyConstructorSemantic sem, List<AssemblyParseTreeNode> opOrdered, List<AbstractAssemblyState> children) A recursive function for generating child operand prototypes and constructing the parent(s)Generate statesprotected List
<AssemblyParseTreeNode> Arrange the branch's (mnemonic) children according to the machine-code production
-
Constructor Details
-
AssemblyConstructStateGenerator
public AssemblyConstructStateGenerator(AbstractAssemblyTreeResolver<?> resolver, AssemblyParseBranch node, AssemblyResolvedPatterns fromLeft) Construct the instruction state generator or a sub-table operand state generator- Parameters:
resolver
- the resolvernode
- the node from which to generate statesfromLeft
- the accumulated patterns from the left sibling or the parent
-
-
Method Details
-
generate
public Stream<AssemblyGeneratedPrototype> generate(AbstractAssemblyStateGenerator.GeneratorContext gc) Description copied from class:AbstractAssemblyStateGenerator
Generate states- Specified by:
generate
in classAbstractAssemblyStateGenerator<AssemblyParseBranch>
- Parameters:
gc
- the generator context for this node- Returns:
- the stream of prototypes, each including accumulated patterns
-
orderOpNodes
Arrange the branch's (mnemonic) children according to the machine-code productionThis orders the parsed children so that each is readily paired to its operand as given by
Constructor.getOperand(int)
.- Parameters:
sem
- the SLEIGH constructor whose machine-code production to consider- Returns:
- the children arranged in constructor operand order
-
applyConstructor
protected Stream<AssemblyGeneratedPrototype> applyConstructor(AbstractAssemblyStateGenerator.GeneratorContext gc, AssemblyConstructorSemantic sem) Generate prototypes, considering the given SLEIGH constructorThis comprises three steps: apply patterns, apply context changes, apply operands left-to-right.
- Parameters:
gc
- the generator context for this nodesem
- the SLEIGH constructor to apply- Returns:
- the stream of generated (sub) prototypes
-
applyOperands
protected Stream<AssemblyGeneratedPrototype> applyOperands(AbstractAssemblyStateGenerator.GeneratorContext gc, AssemblyResolvedPatterns fromMutations, AssemblyConstructorSemantic sem, List<AssemblyParseTreeNode> opOrdered) Generate prototypes by considering all the operands of the given SLEIGH constructorThis is the last step of applying a constructor.
- Parameters:
gc
- the generator context for this nodefromMutations
- the patterns as accumulated after context changessem
- the selected SLEIGH constructoropOrdered
- the parsed children ordered as the constructor's operands- Returns:
- the stream of generated (sub) prototypes
-
applyRemainingOperands
protected Stream<AssemblyGeneratedPrototype> applyRemainingOperands(AbstractAssemblyStateGenerator.GeneratorContext parentGc, List<AbstractAssemblyStateGenerator.GeneratorContext> childGcs, AssemblyResolvedPatterns fromLeft, AssemblyConstructorSemantic sem, List<AssemblyParseTreeNode> opOrdered, List<AbstractAssemblyState> children) A recursive function for generating child operand prototypes and constructing the parent(s)The implementation generates states for the left-most node not yet considered. It knows which is next by examining the length of
children
, which records the generated state for each child already considered. It then appends the result tochildren
and recurses, using the resulting patterns asfromLeft
. Given that multiple prototypes can be generated,Stream.flatMap(java.util.function.Function)
makes the recursive invocation somewhat fluent. The base case occurs when all children have states generated. It constructs the state for this node, storing the generated children with it.This routine is also operative in computing shifts, since the offset of each operand is incorporated here. Two accessors are needed to compute the offset:
OperandSymbol.getOffsetBase()
andOperandSymbol.getRelativeOffset()
. The former identifies which operand's end (exclusive) byte is the base of the offset. The latter specifies an additional number of bytes to the right. Consider an operand consisting of three operands, each consuming a 1-byte token.+-----+-----+-----+ | op0 | op1 | op2 | +-----+-----+-----+ ^-1 ^0 ^1 ^2
A base offset of 0 would indicate that the overall offset is the end of op0 (relative to the parent op) plus the relative offset. A base offset of -1 is special, but is easy to conceptualize from the diagram. It indicates the beginning byte of the parent op. Thus every child operand boundary is numbered. The offset base must always refer to an operand to the left.
- Parameters:
parentGc
- the generator context for this nodechildGcs
- a list to collect the generator context for each child operand. The root invocation should pass a fixed-length mutable list of nulls, one for each child.fromLeft
- the accumulated patterns from the left sibling. The root invocation should pass the patterns accumulated after context changes.sem
- the selected SLEIGH constructor, whose operands to generateopOrdered
- the parsed children ordered as the constructor's operandschildren
- the list of children generated so far. The root invocation should pass the empty list.- Returns:
- the stream of generated (sub) prototypes
-