Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/cranelift/src/print_cfg.rs
1691 views
1
//! The `print-cfg` sub-command.
2
//!
3
//! Read a series of Cranelift IR files and print their control flow graphs
4
//! in graphviz format.
5
6
use crate::utils::read_to_string;
7
use anyhow::Result;
8
use clap::Parser;
9
use cranelift_codegen::cfg_printer::CFGPrinter;
10
use cranelift_reader::parse_functions;
11
use std::path::{Path, PathBuf};
12
13
/// Prints out cfg in GraphViz Dot format
14
#[derive(Parser)]
15
pub struct Options {
16
/// Specify an input file to be used. Use '-' for stdin.
17
#[arg(required = true)]
18
files: Vec<PathBuf>,
19
}
20
21
pub fn run(options: &Options) -> Result<()> {
22
for (i, f) in options.files.iter().enumerate() {
23
if i != 0 {
24
println!();
25
}
26
print_cfg(f)?
27
}
28
Ok(())
29
}
30
31
fn print_cfg(path: &Path) -> Result<()> {
32
let buffer = read_to_string(path)?;
33
let items = parse_functions(&buffer)?;
34
35
for (idx, func) in items.into_iter().enumerate() {
36
if idx != 0 {
37
println!();
38
}
39
print!("{}", CFGPrinter::new(&func));
40
}
41
42
Ok(())
43
}
44
45