use clap::ArgMatches;
use crate::toolchain_config::ToolchainConfig;
use crate::tools::run_codegen_block_ir_to_string;
pub fn handle_ir_fn_to_block(matches: &ArgMatches, config: &Option<ToolchainConfig>) {
let input_file = matches.get_one::<String>("ir_input_file").unwrap();
let input_path = std::path::Path::new(input_file);
let top = matches
.get_one::<String>("ir_top")
.expect("--top must be specified");
let tool_path = match config.as_ref().and_then(|c| c.tool_path.as_deref()) {
Some(p) => p,
None => {
eprintln!("ir-fn-to-block requires a toolchain configuration with a `tool_path` entry");
std::process::exit(1);
}
};
let temp_dir = tempfile::TempDir::new().unwrap();
let block_ir_path = temp_dir.path().join("output.block.ir");
let block_ir = run_codegen_block_ir_to_string(input_path, top, tool_path, &block_ir_path);
println!("{}", block_ir);
}