Exemplo n.º 1
0
  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;
  }
Exemplo n.º 2
0
  private void createInitalNodesAndFlow(
      final Map<PDGNode, Node> pdg2cfg, final ModRefCandidates modref, final PDG pdg) {
    final Node nEntry = createNOPNode(pdg.entry);
    this.entry = nEntry;
    pdg2cfg.put(pdg.entry, nEntry);
    final Node nExit = createNOPNode(pdg.exit);
    this.exit = nExit;
    pdg2cfg.put(pdg.exit, nExit);

    for (final PDGField fref : pdg.getFieldReads()) {
      if (!fref.field.isStatic()) {
        final SSAInstruction instr = pdg.getInstruction(fref.node);
        final ModRefFieldCandidate refCand = modref.createRefCandidate(pdg.cgNode, instr);
        final Node n = createNode(refCand, fref.accfield, Node.Kind.READ);
        pdg2cfg.put(fref.accfield, n);
      }
    }

    for (final PDGField fmod : pdg.getFieldWrites()) {
      if (!fmod.field.isStatic()) {
        final SSAInstruction instr = pdg.getInstruction(fmod.node);
        final ModRefFieldCandidate refCand = modref.createModCandidate(pdg.cgNode, instr);
        final Node n = createNode(refCand, fmod.accfield, Node.Kind.WRITE);
        pdg2cfg.put(fmod.accfield, n);
      }
    }

    for (final PDGNode pn : pdg.vertexSet()) {
      if (pn.getPdgId() == pdg.getId() && !pdg2cfg.containsKey(pn)) {
        final Node n = createNOPNode(pn);
        pdg2cfg.put(pn, n);
      }
    }

    for (final PDGEdge e : pdg.edgeSet()) {
      if (e.kind == PDGEdge.Kind.CONTROL_FLOW || e.kind == PDGEdge.Kind.CONTROL_FLOW_EXC) {
        final Node from = pdg2cfg.get(e.from);
        final Node to = pdg2cfg.get(e.to);
        addEdge(from, to);
      }
    }
  }