Class AssemblyConstructStateGenerator

java.lang.Object
ghidra.app.plugin.assembler.sleigh.sem.AbstractAssemblyStateGenerator<AssemblyParseBranch>
ghidra.app.plugin.assembler.sleigh.sem.AssemblyConstructStateGenerator
Direct Known Subclasses:
AssemblyHiddenConstructStateGenerator

public class AssemblyConstructStateGenerator extends AbstractAssemblyStateGenerator<AssemblyParseBranch>
The generator of AssemblyConstructState from AssemblyParseBranch

In short, this handles the selection of each possible constructor for the production recorded by a given parse branch.

  • 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 resolver
      node - the node from which to generate states
      fromLeft - the accumulated patterns from the left sibling or the parent
  • Method Details

    • generate

      Description copied from class: AbstractAssemblyStateGenerator
      Generate states
      Specified by:
      generate in class AbstractAssemblyStateGenerator<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 production

      This 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

      Generate prototypes, considering the given SLEIGH constructor

      This comprises three steps: apply patterns, apply context changes, apply operands left-to-right.

      Parameters:
      gc - the generator context for this node
      sem - the SLEIGH constructor to apply
      Returns:
      the stream of generated (sub) prototypes
    • applyOperands

      Generate prototypes by considering all the operands of the given SLEIGH constructor

      This is the last step of applying a constructor.

      Parameters:
      gc - the generator context for this node
      fromMutations - the patterns as accumulated after context changes
      sem - the selected SLEIGH constructor
      opOrdered - the parsed children ordered as the constructor's operands
      Returns:
      the stream of generated (sub) prototypes
    • applyRemainingOperands

      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 to children and recurses, using the resulting patterns as fromLeft. 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() and OperandSymbol.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 node
      childGcs - 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 generate
      opOrdered - the parsed children ordered as the constructor's operands
      children - the list of children generated so far. The root invocation should pass the empty list.
      Returns:
      the stream of generated (sub) prototypes