Expose CFG predecessors only as an iterator.

Define two public iterator types in the flowgraph module, PredIter and
SuccIter, which are by-value iterators over an EBB's predecessors and
successors respectively.

Provide matching pred_iter() and succ_iter() methods for inspecting the
CFG. Remove the get_predecessors() method which returned a slice.

Update the uses of get_predecessors(), none of which depended on it
being a slice.

This abstraction makes it possible to change the internal representation
of the CFG.
This commit is contained in:
Jakob Stoklund Olesen
2017-11-22 09:13:04 -08:00
parent 7956084121
commit 92f378de76
12 changed files with 61 additions and 54 deletions

View File

@@ -933,9 +933,8 @@ impl<'a> Verifier<'a> {
return err!(ebb, "cfg had unexpected successor(s) {:?}", excess_succs);
}
expected_preds.extend(self.expected_cfg.get_predecessors(ebb).iter().map(|&(_,
inst)| inst));
got_preds.extend(cfg.get_predecessors(ebb).iter().map(|&(_, inst)| inst));
expected_preds.extend(self.expected_cfg.pred_iter(ebb).map(|(_, inst)| inst));
got_preds.extend(cfg.pred_iter(ebb).map(|(_, inst)| inst));
let missing_preds: Vec<Inst> = expected_preds.difference(&got_preds).cloned().collect();
if !missing_preds.is_empty() {