* Update to clap 3.0 This commit migrates all CLI commands internally used in this project from structopt/clap2 to clap 3. The intent here is to ensure that we're using maintained versions of the dependencies as structopt and clap 2 are less maintained nowadays. Most transitions were pretty straightforward and mostly dealing with structopt/clap3 differences. * Fix a number of `cargo deny` errors This commit fixes a few errors around duplicate dependencies which arose from the prior update to clap3. This also uses a new feature in `deny.toml`, `skip-tree`, which allows having a bit more targeted ignores for skips of duplicate version checks. This showed a few more locations in Wasmtime itself where we could update some dependencies.
49 lines
1.1 KiB
Rust
49 lines
1.1 KiB
Rust
//! The `print-cfg` sub-command.
|
|
//!
|
|
//! Read a series of Cranelift IR files and print their control flow graphs
|
|
//! in graphviz format.
|
|
|
|
use crate::utils::read_to_string;
|
|
use anyhow::Result;
|
|
use clap::Parser;
|
|
use cranelift_codegen::cfg_printer::CFGPrinter;
|
|
use cranelift_reader::parse_functions;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
/// Prints out cfg in GraphViz Dot format
|
|
#[derive(Parser)]
|
|
pub struct Options {
|
|
/// Specify an input file to be used. Use '-' for stdin.
|
|
#[clap(required = true)]
|
|
files: Vec<PathBuf>,
|
|
|
|
/// Enable debug output on stderr/stdout
|
|
#[clap(short)]
|
|
debug: bool,
|
|
}
|
|
|
|
pub fn run(options: &Options) -> Result<()> {
|
|
crate::handle_debug_flag(options.debug);
|
|
for (i, f) in options.files.iter().enumerate() {
|
|
if i != 0 {
|
|
println!();
|
|
}
|
|
print_cfg(f)?
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
fn print_cfg(path: &Path) -> Result<()> {
|
|
let buffer = read_to_string(path)?;
|
|
let items = parse_functions(&buffer)?;
|
|
|
|
for (idx, func) in items.into_iter().enumerate() {
|
|
if idx != 0 {
|
|
println!();
|
|
}
|
|
print!("{}", CFGPrinter::new(&func));
|
|
}
|
|
|
|
Ok(())
|
|
}
|