Class AssemblyTreeResolver
- java.lang.Object
-
- ghidra.app.plugin.assembler.sleigh.sem.AssemblyTreeResolver
-
public class AssemblyTreeResolver extends java.lang.Object
The workhorse of semantic resolution for the assembler 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 inSleighAssemblerBuilder
.- See Also:
SleighAssemblerBuilder
-
-
Field Summary
Fields Modifier and Type Field Description protected AssemblyPatternBlock
context
protected AssemblyContextGraph
ctxGraph
protected static DbgTimer
dbg
protected AssemblyGrammar
grammar
static java.lang.String
INST_NEXT
static java.lang.String
INST_START
protected long
instStart
protected SleighLanguage
lang
protected static RecursiveDescentSolver
solver
protected AssemblyParseBranch
tree
protected java.util.Map<java.lang.String,java.lang.Long>
vals
-
Constructor Summary
Constructors Constructor Description AssemblyTreeResolver(SleighLanguage lang, long instStart, AssemblyParseBranch tree, AssemblyPatternBlock context, AssemblyContextGraph ctxGraph)
Construct a resolver for the given parse tree
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected AssemblyResolutionResults
applyRecursionPath(java.util.Deque<AssemblyConstructorSemantic> path, AssemblyParseBranch branch, AssemblyProduction rec, AssemblyResolvedConstructor child)
Apply constructors as indicated by a path returned by the context resolution graph Please note: The path given will be emptied during processing.static int
computeOffset(OperandSymbol opsym, Constructor cons, java.util.Map<java.lang.Integer,java.lang.Object> res)
Compute the offset of an operand encoded in the instruction blockAssemblyResolutionResults
resolve()
Resolve the tree for the given parametersprotected AssemblyResolutionResults
resolveBranch(AssemblyParseBranch branch)
Resolve a branch of the parse treeprotected AssemblyResolutionResults
resolveBranchNonRecursive(AssemblyParseBranch branch)
Resolve a branch without considering any purely-recursive productions This method is used either when the LHS has no purely-recursive definition, or before considering the purely-recursive definition when it is present.protected AssemblyResolutionResults
resolveBranchRecursive(AssemblyParseBranch branch, AssemblyProduction rec)
Resolve a branch where the production's LHS has a purely-recursive definitionprotected AssemblyResolutionResults
resolveSelectedChildren(AssemblyProduction prod, java.util.List<AssemblyParseTreeNode> substs, com.google.common.collect.ImmutableList<AssemblyResolvedConstructor> sel, java.util.Collection<AssemblyConstructorSemantic> semantics)
Resolve the given branch, having selected a particular combination of subconstructor resultsprotected static AssemblyResolution
solveOrBackfill(PatternExpression exp, long goal, int bits, java.util.Map<java.lang.String,java.lang.Long> vals, java.util.Map<java.lang.Integer,java.lang.Object> res, AssemblyResolvedConstructor cur, java.lang.String description)
Attempt to solve an expression Converts the given goal and bits count to aMaskedLong
and then solves as before.protected static AssemblyResolution
solveOrBackfill(PatternExpression exp, long goal, java.util.Map<java.lang.String,java.lang.Long> vals, java.util.Map<java.lang.Integer,java.lang.Object> res, AssemblyResolvedConstructor cur, java.lang.String description)
Attempt to solve an expression Converts the given goal to a fully-definedMaskedLong
and then solves as before.protected static AssemblyResolution
solveOrBackfill(PatternExpression exp, MaskedLong goal, java.util.Map<java.lang.String,java.lang.Long> vals, java.util.Map<java.lang.Integer,java.lang.Object> res, AssemblyResolvedConstructor cur, java.lang.String description)
Attempt to solve an expressionprotected AssemblyResolutionResults
tryResolveBackfills(AssemblyResolutionResults results)
-
-
-
Field Detail
-
solver
protected static final RecursiveDescentSolver solver
-
dbg
protected static final DbgTimer dbg
-
lang
protected final SleighLanguage lang
-
instStart
protected final long instStart
-
vals
protected final java.util.Map<java.lang.String,java.lang.Long> vals
-
tree
protected final AssemblyParseBranch tree
-
grammar
protected final AssemblyGrammar grammar
-
context
protected final AssemblyPatternBlock context
-
ctxGraph
protected final AssemblyContextGraph ctxGraph
-
INST_START
public static final java.lang.String INST_START
- See Also:
- Constant Field Values
-
INST_NEXT
public static final java.lang.String INST_NEXT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AssemblyTreeResolver
public AssemblyTreeResolver(SleighLanguage lang, long instStart, AssemblyParseBranch tree, AssemblyPatternBlock context, AssemblyContextGraph ctxGraph)
Construct a resolver for the given parse tree- Parameters:
lang
-instStart
- the byte offset where the instruction will starttree
- the parse treecontext
- the context expected atinstStart
ctxGraph
- the context transition graph used to resolve purely-recursive productions
-
-
Method Detail
-
resolve
public AssemblyResolutionResults resolve()
Resolve the tree for the given parameters- Returns:
- a set of resolutions (encodings and errors)
-
resolveBranch
protected AssemblyResolutionResults resolveBranch(AssemblyParseBranch branch)
Resolve a branch of the parse tree- Parameters:
branch
- the branch- Returns:
- the intermediate results
-
applyRecursionPath
protected AssemblyResolutionResults applyRecursionPath(java.util.Deque<AssemblyConstructorSemantic> path, AssemblyParseBranch branch, AssemblyProduction rec, AssemblyResolvedConstructor child)
Apply constructors as indicated by a path returned by the context resolution graph Please note: The path given 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
-
resolveBranchRecursive
protected AssemblyResolutionResults resolveBranchRecursive(AssemblyParseBranch branch, AssemblyProduction rec)
Resolve a branch where the production's LHS has a purely-recursive definition- Parameters:
branch
- the branchrec
- the purely-recursive definition- Returns:
- the results
-
resolveSelectedChildren
protected AssemblyResolutionResults resolveSelectedChildren(AssemblyProduction prod, java.util.List<AssemblyParseTreeNode> substs, com.google.common.collect.ImmutableList<AssemblyResolvedConstructor> sel, java.util.Collection<AssemblyConstructorSemantic> semantics)
Resolve the given branch, having selected a particular combination of subconstructor results- Parameters:
prod
- the productionsubsts
- the braches and tokens corrresponding to the symbols of the production's RHSsel
- the selected subconstructor resultssemantics
- the collection of possible constructors for this production- Returns:
- the results
-
tryResolveBackfills
protected AssemblyResolutionResults tryResolveBackfills(AssemblyResolutionResults results)
-
resolveBranchNonRecursive
protected AssemblyResolutionResults resolveBranchNonRecursive(AssemblyParseBranch branch)
Resolve a branch without considering any purely-recursive productions This method is used either when the LHS has no purely-recursive definition, or before considering the purely-recursive definition when it is present.- Parameters:
branch
- the branch- Returns:
- the results
-
computeOffset
public static int computeOffset(OperandSymbol opsym, Constructor cons, java.util.Map<java.lang.Integer,java.lang.Object> res)
Compute the offset of an operand encoded in the instruction block- Parameters:
opsym
- the operand symbolcons
- the constructor containing the operandres
- the selected subconstructor encodings- Returns:
- the offset (right shift) to apply to the encoded operand
-
solveOrBackfill
protected static AssemblyResolution solveOrBackfill(PatternExpression exp, MaskedLong goal, java.util.Map<java.lang.String,java.lang.Long> vals, java.util.Map<java.lang.Integer,java.lang.Object> res, AssemblyResolvedConstructor cur, java.lang.String description)
Attempt to solve an expression- Parameters:
exp
- the expression to solvegoal
- the desired value of the expressionvals
- any defined symbolsres
- the selected subconstructor encodingscur
- 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, java.util.Map<java.lang.String,java.lang.Long> vals, java.util.Map<java.lang.Integer,java.lang.Object> res, AssemblyResolvedConstructor cur, java.lang.String description)
Attempt to solve an expression Converts the given goal to a fully-definedMaskedLong
and then solves as before.
-
solveOrBackfill
protected static AssemblyResolution solveOrBackfill(PatternExpression exp, long goal, int bits, java.util.Map<java.lang.String,java.lang.Long> vals, java.util.Map<java.lang.Integer,java.lang.Object> res, AssemblyResolvedConstructor cur, java.lang.String description)
Attempt to solve an expression Converts the given goal and bits count to aMaskedLong
and then solves as before. As a special case, ifbits == 0
, the goal is considered fully-defined (as ifbits == 64
).
-
-