use rlx_opscope::dataflow::{decomposition_hint, repeated_flow_patterns_on};
fn main() -> std::io::Result<()> {
let path = std::env::args()
.nth(1)
.expect("usage: opscope-graph <dump.txt>");
let text = std::fs::read_to_string(&path)?;
let mut title = format!("graph {path}");
let mut ops: Vec<String> = Vec::new();
let mut inputs: Vec<Vec<usize>> = Vec::new();
for line in text.lines() {
let line = line.trim();
if line.is_empty() {
continue;
}
if let Some(rest) = line.strip_prefix('#') {
title = rest.trim().to_string(); continue;
}
let tok: Vec<&str> = line.split_whitespace().collect();
ops.push(tok[1].to_string());
inputs.push(tok[2..].iter().filter_map(|s| s.parse().ok()).collect());
}
println!("{title}\n{} nodes\n", ops.len());
let patterns = repeated_flow_patterns_on(&ops, &inputs, 2, 6, 2);
println!(
"{:>5} {:>4} {:>5} repeated dataflow cone → decomposition candidate",
"score", "×", "depth"
);
println!("{}", "-".repeat(100));
for p in patterns.iter().take(14) {
println!(
"{:>5} {:>4} {:>5} {}",
p.score(),
p.count,
p.depth,
p.tree
);
println!("{:>17} {}", "", decomposition_hint(p));
}
Ok(())
}