private static PDGNode[] getAllNodesSorted(SDGBuilder builder, IProgressMonitor progress) throws CancelException { ArrayList<PDGNode> nodes = new ArrayList<PDGNode>(); for (PDG pdg : builder.getAllPDGs()) { for (PDGNode node : pdg.vertexSet()) { if (node.getPdgId() == pdg.getId()) { nodes.add(node); } } } PDGNode[] copy = new PDGNode[nodes.size()]; copy = nodes.toArray(copy); progress.worked(1); MonitorUtil.throwExceptionIfCanceled(progress); Arrays.sort( copy, new Comparator<PDGNode>() { public int compare(PDGNode o1, PDGNode o2) { return o1.getId() - o2.getId(); } }); progress.worked(1); MonitorUtil.throwExceptionIfCanceled(progress); return copy; }
private static Map<PDGNode, SDGNode> convertNodes( SDG sdg, PDGNode[] nodes, SDGBuilder b, IProgressMonitor progress) throws CancelException { Map<PDGNode, SDGNode> map = new HashMap<PDGNode, SDGNode>(nodes.length); int i = 0; for (PDGNode node : nodes) { SDGNode snode = convertNode(b, node); sdg.addVertex(snode); map.put(node, snode); if (i++ % 100 == 0) { progress.worked(1); MonitorUtil.throwExceptionIfCanceled(progress); } } return map; }
public static SDG convert(SDGBuilder b, IProgressMonitor progress) throws CancelException { SDG sdg = new SDG(PrettyWalaNames.methodName(b.getEntry())); progress.subTask("Building utility edges"); addUtilityEdges(b); progress.worked(1); MonitorUtil.throwExceptionIfCanceled(progress); progress.done(); progress.subTask("Sorting all nodes by their id"); PDGNode allNodes[] = getAllNodesSorted(b, progress); progress.done(); progress.subTask("Inserting " + allNodes.length + " nodes"); Map<PDGNode, SDGNode> pdg2sdg = convertNodes(sdg, allNodes, b, progress); progress.done(); progress.subTask("Inserting edges for " + allNodes.length + " nodes"); for (int i = 0; i < allNodes.length; i++) { addEdgesForNode(sdg, allNodes[i], pdg2sdg, b); if (i % 100 == 0) { progress.worked(1); MonitorUtil.throwExceptionIfCanceled(progress); } } sdg.setNode2Instr(b.getPDGNode2IIndex()); sdg.setEntryToCGNode(b.getEntryNode2CGNode()); progress.done(); return sdg; }