Class AssemblyContextGraph
- All Implemented Interfaces:
GImplicitDirectedGraph<AssemblyContextGraph.Vertex,
AssemblyContextGraph.Edge>
This is used primarily to find optimal paths for the application of recursive rules, i.e., those of the form I => I. These cannot be resolved without some form of semantic analysis. The most notable disadvantage to all of this is that you no longer get all of the possible assemblies, but only those with the fewest rule applications.
Conceivably, this may also be used to prune some possibilities during semantic resolution of a parse tree. Even better, it may be possible to derive a grammar which accounts for the context changes already; however, it's unclear how many rules this will generate, and consequently, how much larger its LALR(1) parser would become.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
A transition in a context transition graphprotected static class
A vertex in a context transition graph -
Field Summary
Modifier and TypeFieldDescriptionprotected final Set
<AssemblyContextGraph.Edge> protected final Map
<AssemblyContextGraph.Vertex, Set<AssemblyContextGraph.Edge>> protected final Set
<AssemblyContextGraph.Vertex> protected final DijkstraShortestPathsAlgorithm
<AssemblyContextGraph.Vertex, AssemblyContextGraph.Edge> protected final AbstractAssemblyResolutionFactory
<?, ?> protected final AssemblyGrammar
protected final SleighLanguage
protected final Map
<String, Set<AssemblyConstructorSemantic>> -
Constructor Summary
ConstructorDescriptionAssemblyContextGraph
(AbstractAssemblyResolutionFactory<?, ?> factory, SleighLanguage lang, AssemblyGrammar grammar) Build the context change graph for a given language and grammar -
Method Summary
Modifier and TypeMethodDescriptioncomputeOptimalApplications
(AssemblyPatternBlock src, String srcTable, AssemblyPatternBlock dst, String dstTable) Compute the optimal, i.e., shortest, sequences of applications to resolve a given context to another, often the language's default context.protected Set
<AssemblyContextGraph.Edge> copy()
Returns a copy of the graph explored so farprotected void
Gather all the semantics that can be used as state transitionsThis operation is not supported.Compute the incident edges that start at the given vertex NOTE: This method ought to return cached results if available NOTE: As part of computing out-edges, this method will also provide successorsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ghidra.graph.GImplicitDirectedGraph
getPredecessors, getSuccessors
-
Field Details
-
factory
-
semantics
-
grammar
-
lang
-
dijkstra
protected final DijkstraShortestPathsAlgorithm<AssemblyContextGraph.Vertex,AssemblyContextGraph.Edge> dijkstra -
cachedVertices
-
cachedEdges
-
cachedOutEdges
-
-
Constructor Details
-
AssemblyContextGraph
public AssemblyContextGraph(AbstractAssemblyResolutionFactory<?, ?> factory, SleighLanguage lang, AssemblyGrammar grammar) Build the context change graph for a given language and grammarThe grammar must have been constructed from the given language. The language is used just to obtain the most common default context.
At the moment, this graph only expands the recursive rules at the root constructor table, i.e., "instruction". Thus, the assembler will not be able to process any language that has purely-recursive rules at sub-constructors.
- Parameters:
lang
- the languagegrammar
- the grammar derived from the given language
-
-
Method Details
-
computeOptimalApplications
public Collection<Deque<AssemblyConstructorSemantic>> computeOptimalApplications(AssemblyPatternBlock src, String srcTable, AssemblyPatternBlock dst, String dstTable) Compute the optimal, i.e., shortest, sequences of applications to resolve a given context to another, often the language's default context.- Parameters:
src
- presumably, the language's default contextsrcTable
- the name of the SLEIGH constructor table, presumably "instruction"dst
- the context block being resolveddstTable
- the name of the SLEIGH constructor table being resolved- Returns:
- a collection of sequences of constructor applications from
src
todst
NOTE: For assembly, the sequences will need to be applied right-to-left.
-
gatherSemantics
protected void gatherSemantics()Gather all the semantics that can be used as state transitionsCurrently, only semantics from
:^instruction
constructors are taken. -
computeOutEdges
-
getInEdges
This operation is not supported.I could implement this using the cached edges, but that may not be semantically, what a path computation algorithm actually requires. Instead, I will assume the algorithm only explores the graph in the same direction as its edges. If not, I will hear about it quickly.
- Specified by:
getInEdges
in interfaceGImplicitDirectedGraph<AssemblyContextGraph.Vertex,
AssemblyContextGraph.Edge> - Parameters:
v
- the destination vertex- Returns:
- the in-edges to the given vertex
-
getOutEdges
Description copied from interface:GImplicitDirectedGraph
Compute the incident edges that start at the given vertex NOTE: This method ought to return cached results if available NOTE: As part of computing out-edges, this method will also provide successors- Specified by:
getOutEdges
in interfaceGImplicitDirectedGraph<AssemblyContextGraph.Vertex,
AssemblyContextGraph.Edge> - Parameters:
v
- the source vertex- Returns:
- the out-edges from the given vertex
-
copy
Returns a copy of the graph explored so far- Specified by:
copy
in interfaceGImplicitDirectedGraph<AssemblyContextGraph.Vertex,
AssemblyContextGraph.Edge> - Returns:
- a "copy" of this implicit graph
-