Generate some output for filecheck testing
(func: &Function, domtree: &DominatorTree)
| 117 | |
| 118 | // Generate some output for filecheck testing |
| 119 | fn filecheck_text(func: &Function, domtree: &DominatorTree) -> Result<String, fmt::Error> { |
| 120 | let mut s = String::new(); |
| 121 | |
| 122 | write!(s, "cfg_postorder:")?; |
| 123 | for &block in domtree.cfg_postorder() { |
| 124 | write!(s, " {block}")?; |
| 125 | } |
| 126 | writeln!(s)?; |
| 127 | |
| 128 | // Compute and print out a pre-order of the dominator tree. |
| 129 | writeln!(s, "domtree_preorder {{")?; |
| 130 | let mut stack = Vec::new(); |
| 131 | stack.extend(func.layout.entry_block()); |
| 132 | while let Some(block) = stack.pop() { |
| 133 | write!(s, " {block}:")?; |
| 134 | let i = stack.len(); |
| 135 | for ch in domtree.children(block) { |
| 136 | write!(s, " {ch}")?; |
| 137 | stack.push(ch); |
| 138 | } |
| 139 | writeln!(s)?; |
| 140 | // Reverse the children we just pushed so we'll pop them in order. |
| 141 | stack[i..].reverse(); |
| 142 | } |
| 143 | writeln!(s, "}}")?; |
| 144 | |
| 145 | Ok(s) |
| 146 | } |