Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cfg step adjustments. #1992

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ class DdgGenerator {
private val edgeCache = mutable.Map[StoredNode, List[Edge]]()

def generate(methodNode: Method)(implicit semantics: Semantics = DefaultSemantics()): Graph = {
val entryNode = methodNode
val paramNodes = methodNode.parameter.l
val allOtherNodes = methodNode.cfgNode.l
val exitNode = methodNode.methodReturn
val allNodes: List[StoredNode] = List(entryNode, exitNode) ++ paramNodes ++ allOtherNodes
val allNodes: List[StoredNode] = paramNodes ++ allOtherNodes
val visibleNodes = allNodes.filter(shouldBeDisplayed)

val edges = visibleNodes.map { dstNode =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CfgGenerator {
val edgeType: String = EdgeTypes.CFG

def generate(methodNode: Method): Graph = {
val vertices = methodNode.cfgNode.l ++ List(methodNode, methodNode.methodReturn) ++ methodNode.parameter.l
val vertices = methodNode.cfgNode.l ++ methodNode.parameter.l
val verticesToDisplay = vertices.filter(cfgNodeShouldBeDisplayed)

def edgesToDisplay(srcNode: StoredNode, visited: List[StoredNode] = List()): List[Edge] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CfgNodeMethods(val node: CfgNode) extends AnyVal with NodeExtension {
/** Successors in the CFG
*/
def cfgNext: Traversal[CfgNode] = {
Traversal.fromSingle(node).cfgNext
node._cfgOut.collectAll[CfgNode]
}

/** Maps each node in the traversal to a traversal returning its n successors.
Expand All @@ -43,7 +43,7 @@ class CfgNodeMethods(val node: CfgNode) extends AnyVal with NodeExtension {
/** Predecessors in the CFG
*/
def cfgPrev: Traversal[CfgNode] = {
Traversal.fromSingle(node).cfgPrev
node._cfgIn.collectAll[CfgNode]
}

/** Recursively determine all nodes on which this CFG node is control-dependent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MethodMethods(val method: Method) extends AnyVal with NodeExtension with H
}

def cfgNode: Traversal[CfgNode] =
method._containsOut.collectAll[CfgNode]
method ++ method._containsOut.collectAll[CfgNode] ++ method.methodReturn

/** List of CFG nodes in reverse post order
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,13 @@ class CfgNodeTraversal[A <: CfgNode](val traversal: Traversal[A]) extends AnyVal

@Doc(info = "Nodes directly reachable via outgoing CFG edges")
def cfgNext: Traversal[CfgNode] =
traversal
.out(EdgeTypes.CFG)
.not(_.hasLabel(NodeTypes.METHOD_RETURN))
.cast[CfgNode]
traversal.flatMap(_.cfgNext)

/** Traverse to previous expression in CFG.
*/
@Doc(info = "Nodes directly reachable via incoming CFG edges")
def cfgPrev: Traversal[CfgNode] =
traversal
.in(EdgeTypes.CFG)
.not(_.hasLabel(NodeTypes.METHOD))
.cast[CfgNode]
traversal.flatMap(_.cfgPrev)

/** All nodes reachable in the CFG by up to n forward expansions
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class MethodTraversal(val iterableOnce: IterableOnce[Method]) extends AnyVal {
.not(_.hasLabel(NodeTypes.LOCAL))
.cast[Expression]

@Doc(info = "Control flow graph nodes")
@Doc(info = "Control flow graph nodes. This include the method itself as entry and the method return node as exit.")
def cfgNode: Traversal[CfgNode] =
traversal.flatMap(_.cfgNode)

Expand Down