Class 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
FieldsChangeModifier and TypeFieldDescriptionNEWprotected final Addressprotected final AssemblyPatternBlockprotected final AssemblyContextGraphNEWprotected static final DbgTimerprotected final AssemblyGrammarstatic final StringNEWstatic final Stringstatic final Stringprotected final SleighLanguageNEWprotected static final RecursiveDescentSolverprotected final AssemblyParseBranchREMOVEDsolver() RemovedREMOVEDdbg() RemovedREMOVEDRemoved -
Constructor Summary
ConstructorsChangeConstructorDescriptionAssemblyTreeResolver(SleighLanguage lang, Address at, AssemblyParseBranch tree, AssemblyPatternBlock context, AssemblyContextGraph ctxGraph) Construct a resolver for the given parse tree -
Method Summary
ChangeModifier and TypeMethodDescriptionNEWprotected AssemblyResolutionResultsTODO: This is currently used only for resolving recursion.NEWprotected AssemblyResolutionResultsapplyPatterns(AssemblyConstructorSemantic sem, int shift, AssemblyResolutionResults temp) TODO: This is currently used only for resolving recursion.protected AssemblyResolutionResultsapplyRecursionPath(Deque<AssemblyConstructorSemantic> path, AssemblyParseBranch branch, AssemblyProduction rec, AssemblyResolvedPatterns child) Apply constructors as indicated by a path returned by the context resolution graphNEWstatic intcomputeOffset(OperandSymbol opsym, Constructor cons) Compute the offset of an operand encoded in the instruction blockNEWprotected AssemblyResolutionResultsFilter out results that get disassembled differently than assembledNEWprotected AssemblyResolutionResultsFilter out results that would certainly be disassembled differently than assembledNEWprotected AbstractAssemblyStateGenerator<?>getHiddenStateGenerator(OperandSymbol opSym, AssemblyResolvedPatterns fromLeft) Get the state generator for a hidden operandNEWprotected AssemblyProductionIf applicable, get theI => Iproduction of the grammarNEWprotected AbstractAssemblyStateGenerator<?>getStateGenerator(OperandSymbol opSym, AssemblyParseTreeNode node, AssemblyResolvedPatterns fromLeft) Get the state generator for a given operand and parse tree nodeNEWprotected AssemblyResolutionResultsparent(String description, AssemblyResolutionResults temp, int opCount) TODO: Can this be factored?resolve()Resolve the tree for the given parametersNEWprotected AssemblyResolutionResultsresolvePatterns(AssemblyConstructorSemantic sem, int shift, AssemblyResolutionResults fromChildren) Apply a constructor patternNEWprotected AssemblyResolutionResultsAttempt a second time to solve operands and context changesNEWIf necessary, resolve recursive constructors at the root, usually for prefixesNEWprotected AssemblyResolutionResultsFilter out results whose context do not match that requestedprotected static AssemblyResolutionsolveOrBackfill(PatternExpression exp, long goal, int bits, Map<String, Long> vals, AssemblyResolvedPatterns cur, String description) Attempt to solve an expressionprotected static AssemblyResolutionsolveOrBackfill(PatternExpression exp, long goal, Map<String, Long> vals, AssemblyResolvedPatterns cur, String description) Attempt to solve an expressionprotected static AssemblyResolutionsolveOrBackfill(PatternExpression exp, MaskedLong goal, Map<String, Long> vals, AssemblyResolvedPatterns cur, String description) Attempt to solve an expressionprotected AssemblyResolutionResultsTODO: This is currently used only for resolving recursion.REMOVEDAssemblyResolutionResultsresolveBranch(AssemblyParseBranch branch) RemovedREMOVEDAssemblyResolutionResultsresolveBranchRecursive(AssemblyParseBranch branch, AssemblyProduction rec) RemovedREMOVEDAssemblyResolutionResultsresolveBranchNonRecursive(AssemblyParseBranch branch) Removed
-
Field Details
-
SOLVER NEW
-
DBG NEW
-
INST_START
- See Also:
-
INST_NEXT
- See Also:
-
INST_NEXT2 NEW
- See Also:
-
lang
-
at NEW
-
vals
-
tree
-
grammar
-
context
-
ctxGraph
-
-
Constructor Details
-
AssemblyTreeResolver
public AssemblyTreeResolver(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 atinstStartctxGraph- the context transition graph used to resolve purely-recursive productions
-
-
Method Details
-
resolve
Resolve the tree for the given parameters- Returns:
- a set of resolutions (encodings and errors)
-
getRootRecursion NEW
If applicable, get theI => Iproduction of the grammar- Returns:
- the production
-
resolveRootRecursion NEW
If necessary, resolve recursive constructors at the root, usually for prefixesIf there are no pure recursive constructors at the root, then this simply returns
tempunmodified.- Parameters:
temp- the resolved root results- Returns:
- the results with pure recursive constructors applied to obtain a compatible context
-
resolvePendingBackfills NEW
Attempt a second time to solve operands and context changesBackfills that depended on
inst_nextshould 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 NEW
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 NEW
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 NEW
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 NEW
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 NEW
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 NEW
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 NEW
protected AssemblyResolutionResults parent(String description, AssemblyResolutionResults temp, int opCount) TODO: Can this be factored? -
applyMutations NEW
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 NEW
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, AssemblyResolvedPatterns 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 its missing from the refactor? -
computeOffset NEW
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
-
solveOrBackfill
protected static AssemblyResolution solveOrBackfill(PatternExpression exp, MaskedLong goal, Map<String, Long> vals, AssemblyResolvedPatterns cur, String description) Attempt to solve an expression- Parameters:
exp- the expression to solvegoal- the desired value of the expressionvals- any defined symbolscur- the resolved constructor so fardescription- a description of the result- Returns:
- the encoded solution, or a backfill record
-
solveOrBackfill
protected static AssemblyResolution solveOrBackfill(PatternExpression exp, long goal, Map<String, Long> vals, AssemblyResolvedPatterns cur, String description) Attempt to solve an expressionConverts the given goal to a fully-defined
MaskedLongand then solves as before. -
solveOrBackfill
protected static AssemblyResolution solveOrBackfill(PatternExpression exp, long goal, int bits, Map<String, Long> vals, AssemblyResolvedPatterns cur, String description) Attempt to solve an expressionConverts the given goal and bits count to a
MaskedLongand then solves as before. As a special case, ifbits == 0, the goal is considered fully-defined (as ifbits == 64).
-