| 825 | } |
| 826 | |
| 827 | fn verify(layout: &mut Layout, blocks: &[(Block, &[Inst])]) { |
| 828 | // Check that blocks are inserted and instructions belong the right places. |
| 829 | // Check forward linkage with iterators. |
| 830 | // Check that layout sequence numbers are strictly monotonic. |
| 831 | { |
| 832 | let mut block_iter = layout.blocks(); |
| 833 | for &(block, insts) in blocks { |
| 834 | assert!(layout.is_block_inserted(block)); |
| 835 | assert_eq!(block_iter.next(), Some(block)); |
| 836 | |
| 837 | let mut seq = 0; |
| 838 | let mut inst_iter = layout.block_insts(block); |
| 839 | for &inst in insts { |
| 840 | assert_eq!(layout.inst_block(inst), Some(block)); |
| 841 | assert_eq!(inst_iter.next(), Some(inst)); |
| 842 | assert!(layout.insts[inst].seq > seq); |
| 843 | seq = layout.insts[inst].seq; |
| 844 | } |
| 845 | assert_eq!(inst_iter.next(), None); |
| 846 | } |
| 847 | assert_eq!(block_iter.next(), None); |
| 848 | } |
| 849 | |
| 850 | // Check backwards linkage with a cursor. |
| 851 | let mut cur = LayoutCursor::new(layout); |
| 852 | for &(block, insts) in blocks.into_iter().rev() { |
| 853 | assert_eq!(cur.prev_block(), Some(block)); |
| 854 | for &inst in insts.into_iter().rev() { |
| 855 | assert_eq!(cur.prev_inst(), Some(inst)); |
| 856 | } |
| 857 | assert_eq!(cur.prev_inst(), None); |
| 858 | } |
| 859 | assert_eq!(cur.prev_block(), None); |
| 860 | } |
| 861 | |
| 862 | #[test] |
| 863 | fn append_block() { |