public void Traverse(CallGraph cgraph, Procedure rootProc) { var q = new Queue <Procedure>(); q.Enqueue(rootProc); while (q.Count > 0) { var proc = q.Dequeue(); if (visited.Contains(proc)) { continue; } visited.Add(proc); Debug.Print("Node {0}", proc.Name); visited.Add(proc); var n = Render(proc); foreach (var pred in cgraph.CallerProcedures(proc).Where(p => p != rootProc)) { Debug.Print("Edge {0} - {1}", pred.Name, proc.Name); graph.AddEdge(pred.Name, proc.Name); } foreach (var succ in cgraph.Callees(proc)) { q.Enqueue(succ); } } }
public void BlockCloner_CloneCall() { var call = new CallInstruction(new ProcedureConstant(arch.PointerType, procCalling), new CallSite(0, 0)); var block = new Block(procCalling, procCalling.EntryAddress, "test"); var stmOld = new Statement(42, call, block); callgraph.AddEdge(stmOld, procCalling); var cloner = new BlockCloner(null, procCalling, callgraph); cloner.Statement = stmOld; cloner.StatementNew = new Statement(42, null, block); var newCall = (CallInstruction)call.Accept(cloner); cloner.StatementNew.Instruction = newCall; Assert.AreEqual(call.Callee, newCall.Callee); Assert.AreEqual(2, callgraph.CallerStatements(procCalling).Count(), "Should've added a call to the callgraph"); Assert.AreEqual(1, callgraph.Callees(cloner.Statement).Count()); Assert.AreEqual(1, callgraph.Callees(cloner.StatementNew).Count()); }
public void Traverse(CallGraph cgraph, Procedure rootProc) { var q = new Queue<Procedure>(); q.Enqueue(rootProc); while (q.Count > 0) { var proc = q.Dequeue(); if (visited.Contains(proc)) continue; visited.Add(proc); Debug.Print("Node {0}", proc.Name); visited.Add(proc); Render(proc); foreach (var pred in cgraph.CallerProcedures(proc).Where(p => p != rootProc)) { Debug.Print("Edge {0} - {1}", pred.Name, proc.Name); graph.AddEdge(pred.Name, proc.Name); } foreach (var succ in cgraph.Callees(proc)) { q.Enqueue(succ); } } }
public ICollection <Procedure> Successors(Procedure node) { var succs = new List <Procedure>(cg.Callees(node)); return(succs); }