FindSeq returns the first occurrence of a sequence of two statements in g, and a boolean indicating if such a primitive was found.
(g graph.Directed, dom cfg.DominatorTree)
| 61 | // FindSeq returns the first occurrence of a sequence of two statements in g, |
| 62 | // and a boolean indicating if such a primitive was found. |
| 63 | func FindSeq(g graph.Directed, dom cfg.DominatorTree) (prim Seq, ok bool) { |
| 64 | // Range through entry node candidates. |
| 65 | for _, entry := range g.Nodes() { |
| 66 | // Verify that entry has one successor (exit). |
| 67 | entrySuccs := g.From(entry) |
| 68 | if len(entrySuccs) != 1 { |
| 69 | continue |
| 70 | } |
| 71 | prim.Entry = entry |
| 72 | |
| 73 | // Select exit node candidate. |
| 74 | prim.Exit = entrySuccs[0] |
| 75 | if prim.IsValid(g, dom) { |
| 76 | return prim, true |
| 77 | } |
| 78 | } |
| 79 | return Seq{}, false |
| 80 | } |
| 81 | |
| 82 | // IsValid reports whether the entry and exit node candidates of prim form a |
| 83 | // valid sequence of two statements in g. |