1use crate::utils::read_to_string;
7use anyhow::Result;
8use clap::Parser;
9use cranelift_codegen::cfg_printer::CFGPrinter;
10use cranelift_reader::parse_functions;
11use std::path::{Path, PathBuf};
12
13#[derive(Parser)]
15pub struct Options {
16 #[arg(required = true)]
18 files: Vec<PathBuf>,
19}
20
21pub 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
31fn 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}