2 // Compute the forward partition of the chosen function
4 // Run with graph ... | return-paths | subg-fwd -a functionname
5 // or graph ... | subg-fwd
9 // Find the immediate parent subgraph of this object
10 graph_t find_owner(obj_t o, graph_t g)
13 for (g1 = fstsubg(g); g1; g1 = nxtsubg(g1))
14 if(isIn(g1,o)) return g1;
20 graph_t sg = subg ($, sprintf("incoming-%s", ARGV[0]));
21 graph_t returns = graph("return-edges", ""); // Temporary graph to hold return edges
22 graph_t target, g, g2;
29 // find the ep corresponding to ARG[0]
30 for (g = fstsubg($G); g; g = nxtsubg(g)) {
31 if(g.fun == ARGV[0]) {
40 printf(2, "Function %s not found\n", ARGV[0]);
45 // Preserve external functions
50 // Move unused return edges into a separate graph so they don't get followed
52 for (e = fstout($); e; e = nxtout(e))
53 if (e.op == "ret" && !isIn(sg, e.head)) {
59 // Recover elided return edge for this target node
60 N [op == "target" && indegree == 1] {
62 e = fstin(n); // each target node can only have one return edge
63 e = edge(copy(sg, e.tail), $, "recovered"); // clone should work here, but doesn't
67 // Copy relevant nodes
71 g = find_owner($, $G);
73 subnode (copy(sg, g), $);