Class AbstractAssemblyTreeResolver<RP extends AssemblyResolvedPatterns>
- Direct Known Subclasses:
AssemblyTreeResolver
This class takes a parse tree and some additional information (start address, context, etc.) and
attempts to determine possible encodings using the semantics associated with each branch of the
given parse tree. Details of this process are described in SleighAssemblerBuilder
.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Address
protected final AssemblyPatternBlock
protected final AssemblyContextGraph
protected static final DbgTimer
protected final AbstractAssemblyResolutionFactory
<RP, ?> protected final AssemblyGrammar
static final String
static final String
static final String
protected final SleighLanguage
protected static final RecursiveDescentSolver
protected final AssemblyParseBranch
-
Constructor Summary
ConstructorDescriptionAbstractAssemblyTreeResolver
(AbstractAssemblyResolutionFactory<RP, ?> factory, SleighLanguage lang, Address at, AssemblyParseBranch tree, AssemblyPatternBlock context, AssemblyContextGraph ctxGraph) Construct a resolver for the given parse tree -
Method Summary
Modifier and TypeMethodDescriptionprotected AssemblyResolutionResults
TODO: This is currently used only for resolving recursion.protected AssemblyResolutionResults
applyPatterns
(AssemblyConstructorSemantic sem, int shift, AssemblyResolutionResults temp) TODO: This is currently used only for resolving recursion.protected AssemblyResolutionResults
applyRecursionPath
(Deque<AssemblyConstructorSemantic> path, AssemblyParseBranch branch, AssemblyProduction rec, AssemblyResolution child) Apply constructors as indicated by a path returned by the context resolution graphstatic int
computeOffset
(OperandSymbol opsym, Constructor cons) Compute the offset of an operand encoded in the instruction blockprotected AssemblyResolutionResults
Filter out results that get disassembled differently than assembledprotected AssemblyResolutionResults
Filter out results that would certainly be disassembled differently than assembledprotected AbstractAssemblyStateGenerator
<?> getHiddenStateGenerator
(OperandSymbol opSym, AssemblyResolvedPatterns fromLeft) Get the state generator for a hidden operandprotected AssemblyProduction
If applicable, get theI => I
production of the grammarprotected AbstractAssemblyStateGenerator
<?> getStateGenerator
(OperandSymbol opSym, AssemblyParseTreeNode node, AssemblyResolvedPatterns fromLeft) Get the state generator for a given operand and parse tree nodeprotected AssemblyResolutionResults
parent
(String description, AssemblyResolutionResults temp, int opCount) resolve()
Resolve the tree for the given parametersprotected AssemblyResolutionResults
resolvePatterns
(AssemblyConstructorSemantic sem, int shift, AssemblyResolutionResults fromChildren) Apply a constructor patternprotected AssemblyResolutionResults
Attempt a second time to solve operands and context changesIf necessary, resolve recursive constructors at the root, usually for prefixesprotected AssemblyResolutionResults
Filter out results whose context do not match that requestedprotected AssemblyResolutionResults
TODO: This is currently used only for resolving recursion.
-
Field Details
-
SOLVER
-
DBG
-
INST_START
- See Also:
-
INST_NEXT
- See Also:
-
INST_NEXT2
- See Also:
-
factory
-
lang
-
at
-
vals
-
tree
-
grammar
-
context
-
ctxGraph
-
-
Constructor Details
-
AbstractAssemblyTreeResolver
public AbstractAssemblyTreeResolver(AbstractAssemblyResolutionFactory<RP, ?> factory, SleighLanguage lang, Address at, AssemblyParseBranch tree, AssemblyPatternBlock context, AssemblyContextGraph ctxGraph) Construct a resolver for the given parse tree- Parameters:
lang
-at
- the address where the instruction will starttree
- the parse treecontext
- the context expected atinstStart
ctxGraph
- the context transition graph used to resolve purely-recursive productions
-
-
Method Details
-
getFactory
-
resolve
Resolve the tree for the given parameters- Returns:
- a set of resolutions (encodings and errors)
-
getRootRecursion
If applicable, get theI => I
production of the grammar- Returns:
- the production
-
resolveRootRecursion
If necessary, resolve recursive constructors at the root, usually for prefixesIf there are no pure recursive constructors at the root, then this simply returns
temp
unmodified.- Parameters:
temp
- the resolved root results- Returns:
- the results with pure recursive constructors applied to obtain a compatible context
-
resolvePendingBackfills
Attempt a second time to solve operands and context changesBackfills that depended on
inst_next
should now easily be solved, since the instruction length is now known.- Parameters:
temp
- the resolved results, with backfill pending- Returns:
- the results without backfill, possible with new errors
-
selectContext
Filter out results whose context do not match that requested- Parameters:
temp
- the results whose contexts have not yet been checked- Returns:
- the results that pass. Those that do not are replaced with errors.
-
filterForbidden
Filter out results that would certainly be disassembled differently than assembledBecause of constructor precedence rules, it is possible to assemble a pattern from a prototype that would not result in equivalent disassembly. This can be detected in some cases via the "forbids" mechanism, where more specific constructors are recorded with the result. If the generated pattern matches on of those more-specific constructors, it is forbidden.
- Parameters:
temp
- the results whose forbids have not yet been checked- Returns:
- the results that pass. Those that do not are replaced with errors.
-
filterByDisassembly
Filter out results that get disassembled differently than assembledThe forbids mechanism is not perfect, so as a final fail safe, we disassemble the result and compare the prototypes.
- Parameters:
temp
- the results whose disassemblies have not yet been checked- Returns:
- the results that pass. Those that do not are replaced with errors.
-
getStateGenerator
protected AbstractAssemblyStateGenerator<?> getStateGenerator(OperandSymbol opSym, AssemblyParseTreeNode node, AssemblyResolvedPatterns fromLeft) Get the state generator for a given operand and parse tree node- Parameters:
opSym
- the operand symbolnode
- the corresponding parse tree node, possibly null indicating a hidden operandfromLeft
- the accumulated patterns from the left sibling or parent- Returns:
- the generator
-
getHiddenStateGenerator
protected AbstractAssemblyStateGenerator<?> getHiddenStateGenerator(OperandSymbol opSym, AssemblyResolvedPatterns fromLeft) Get the state generator for a hidden operand- Parameters:
opSym
- the operand symbolfromLeft
- the accumulated patterns from the left sibling or parent- Returns:
- the generator
-
resolvePatterns
protected AssemblyResolutionResults resolvePatterns(AssemblyConstructorSemantic sem, int shift, AssemblyResolutionResults fromChildren) Apply a constructor patternTODO: This is currently used only for resolving recursion. Could this be factored with
AssemblyConstructState.resolve(AssemblyResolvedPatterns, Collection)
?- Parameters:
sem
- the SLEIGH constructorshift
- the shiftfromChildren
- the results from the single resolved child- Returns:
- the results
-
parent
protected AssemblyResolutionResults parent(String description, AssemblyResolutionResults temp, int opCount) -
applyMutations
protected AssemblyResolutionResults applyMutations(AssemblyConstructorSemantic sem, AssemblyResolutionResults temp) TODO: This is currently used only for resolving recursion. Could this be factored withAssemblyConstructState.resolveMutations(AssemblyResolvedPatterns, Collection)
? -
applyPatterns
protected AssemblyResolutionResults applyPatterns(AssemblyConstructorSemantic sem, int shift, AssemblyResolutionResults temp) TODO: This is currently used only for resolving recursion. Could this be factored withAssemblyConstructState.resolvePatterns(AssemblyResolvedPatterns, Collection)
? -
applyRecursionPath
protected AssemblyResolutionResults applyRecursionPath(Deque<AssemblyConstructorSemantic> path, AssemblyParseBranch branch, AssemblyProduction rec, AssemblyResolution child) Apply constructors as indicated by a path returned by the context resolution graphNOTE: The given path will be emptied during processing.
- Parameters:
path
- the path to applybranch
- the branch corresponding to the production whose LHS has a purely-recursive definition.rec
- the purely-recursive productionchild
- the intermediate result to apply the constructors to- Returns:
- the results
-
tryResolveBackfills
TODO: This is currently used only for resolving recursion. It seems it's missing from the refactor? -
computeOffset
Compute the offset of an operand encoded in the instruction blockTODO: Currently, there are duplicate mechanisms for resolving a constructor: 1) The newer mechanism implemented in
AssemblyConstructState
, and 2) the older one implemented inapplyPatterns(AssemblyConstructorSemantic, int, AssemblyResolutionResults)
. The latter seems to require this method, since it does not have pre-computed shifts as in the former. We should probably remove the latter in favor of the former....- Parameters:
opsym
- the operand symbolcons
- the constructor containing the operand- Returns:
- the offset (right shift) to apply to the encoded operand
-
getGrammar
-