(dot_file: &Path)
| 38 | } |
| 39 | |
| 40 | fn dot_parser(dot_file: &Path) -> eyre::Result<(Vec<DotNode>, Vec<DotEdge>)> { |
| 41 | let content = |
| 42 | std::fs::read_to_string(dot_file).context(format!("dot file open error: {dot_file:?}"))?; |
| 43 | let node_re = |
| 44 | Regex::new(r###"Node(0x[0-9a-fA-F]+) \[shape=record,label="\{(.+?)\}"];"###).unwrap(); |
| 45 | let mut nodes = Vec::new(); |
| 46 | for captures in node_re.captures_iter(&content) { |
| 47 | let id = &captures[1]; |
| 48 | let label = &captures[2]; |
| 49 | let node = DotNode::new(id, label); |
| 50 | nodes.push(node); |
| 51 | } |
| 52 | |
| 53 | let mut edges: Vec<DotEdge> = Vec::new(); |
| 54 | let edge_re = Regex::new(r###"Node(0x[0-9a-fA-F]+) -> Node(0x[0-9a-fA-F]+);"###).unwrap(); |
| 55 | for captures in edge_re.captures_iter(&content) { |
| 56 | let src = &captures[1]; |
| 57 | let dst = &captures[2]; |
| 58 | let edge = DotEdge::new(src, dst); |
| 59 | edges.push(edge) |
| 60 | } |
| 61 | Ok((nodes, edges)) |
| 62 | } |
| 63 | |
| 64 | pub struct CallGraph { |
| 65 | graph: Graph<String, u8, Directed>, |
no test coverage detected