clif-util: add the souper-to-peepmatic subcommand (#2200)

This adds a subcommand to the `clif-util` CLI for exposing the Souper->Peepmatic
translation machinery that was introduced in #2192.
This commit is contained in:
Nick Fitzgerald
2020-09-14 13:19:54 -07:00
committed by GitHub
parent cb306fd514
commit 43d2799fa2
2 changed files with 68 additions and 0 deletions

View File

@@ -29,6 +29,9 @@ mod print_cfg;
mod run;
mod utils;
#[cfg(feature = "peepmatic-souper")]
mod souper_to_peepmatic;
#[cfg(feature = "wasm")]
mod wasm;
@@ -50,6 +53,15 @@ fn add_single_input_file_arg<'a>() -> clap::Arg<'a, 'a> {
.help("Specify a file to be used. Use '-' for stdin.")
}
fn add_output_arg<'a>() -> clap::Arg<'a, 'a> {
Arg::with_name("output")
.required(true)
.default_value("-")
.value_name("output")
.short("o")
.help("Specify output file to be used. Use '-' for stdout.")
}
fn add_pass_arg<'a>() -> clap::Arg<'a, 'a> {
Arg::with_name("pass")
.required(true)
@@ -247,6 +259,12 @@ fn main() {
.arg(add_set_flag())
.arg(add_target_flag())
.arg(add_verbose_flag()),
)
.subcommand(
SubCommand::with_name("souper-to-peepmatic")
.about("Convert Souper optimizations into Peepmatic DSL.")
.arg(add_single_input_file_arg())
.arg(add_output_arg()),
);
let res_util = match app_cmds.get_matches().subcommand() {
@@ -362,6 +380,24 @@ fn main() {
rest_cmd.is_present("verbose"),
)
}
("souper-to-peepmatic", Some(rest_cmd)) => {
#[cfg(feature = "peepmatic-souper")]
{
use std::path::Path;
souper_to_peepmatic::run(
Path::new(rest_cmd.value_of("single-file").unwrap()),
Path::new(rest_cmd.value_of("output").unwrap()),
)
}
#[cfg(not(feature = "peepmatic-souper"))]
{
Err(
"Error: clif-util was compiled without suport for the `souper-to-peepmatic` \
subcommand"
.into(),
)
}
}
_ => Err("Invalid subcommand.".to_owned()),
};