IsValid reports whether the entry and exit node candidates of prim form a valid sequence of two statements in g. Control flow graph: entry ↓ exit
(g graph.Directed, dom cfg.DominatorTree)
| 88 | // ↓ |
| 89 | // exit |
| 90 | func (prim Seq) IsValid(g graph.Directed, dom cfg.DominatorTree) bool { |
| 91 | // Dominator sanity check. |
| 92 | entry, exit := prim.Entry, prim.Exit |
| 93 | if !dom.Dominates(entry, exit) { |
| 94 | return false |
| 95 | } |
| 96 | |
| 97 | // Verify that entry has one successor (exit). |
| 98 | entrySuccs := g.From(entry) |
| 99 | if len(entrySuccs) != 1 || !g.HasEdgeFromTo(entry, exit) { |
| 100 | return false |
| 101 | } |
| 102 | |
| 103 | // Verify that exit has one predecessor (entry). |
| 104 | exitPreds := g.To(exit) |
| 105 | return len(exitPreds) == 1 |
| 106 | } |