mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-15 23:18:48 +00:00
Use clap::Parser
This commit is contained in:
70
bin/fuzz.rs
70
bin/fuzz.rs
@@ -1,58 +1,90 @@
|
||||
use clap::{crate_authors, crate_description, crate_version, load_yaml, App};
|
||||
use clap::Parser;
|
||||
|
||||
extern crate kecc;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(name = "fuzz", version, author, about)]
|
||||
struct FuzzCli {
|
||||
/// Fuzzes C AST Printer
|
||||
#[clap(short, long)]
|
||||
print: bool,
|
||||
|
||||
/// Fuzzes irgen
|
||||
#[clap(short, long)]
|
||||
irgen: bool,
|
||||
|
||||
/// Fuzzes irparse
|
||||
#[clap(long)]
|
||||
irparse: bool,
|
||||
|
||||
/// Performs simplify-cfg
|
||||
#[clap(long = "simplify-cfg")]
|
||||
simplify_cfg: bool,
|
||||
|
||||
/// Performs mem2reg
|
||||
#[clap(long)]
|
||||
mem2reg: bool,
|
||||
|
||||
/// Performs deadcode elimination
|
||||
#[clap(long)]
|
||||
deadcode: bool,
|
||||
|
||||
/// Performs gvn
|
||||
#[clap(long)]
|
||||
gvn: bool,
|
||||
|
||||
/// Fuzzes irgen, optimize and asmgen pipeline
|
||||
#[clap(long = "end-to-end")]
|
||||
end_to_end: bool,
|
||||
|
||||
/// Sets the input file to use
|
||||
input: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let yaml = load_yaml!("fuzz_cli.yml");
|
||||
#[allow(deprecated)]
|
||||
let matches = App::from_yaml(yaml)
|
||||
.version(crate_version!())
|
||||
.about(crate_description!())
|
||||
.author(crate_authors!(", "))
|
||||
.get_matches();
|
||||
let matches = FuzzCli::parse();
|
||||
let input = matches.input;
|
||||
|
||||
let input = matches.value_of("INPUT").unwrap();
|
||||
|
||||
if matches.is_present("print") {
|
||||
if matches.print {
|
||||
kecc::test_write_c(Path::new(&input));
|
||||
return;
|
||||
}
|
||||
|
||||
if matches.is_present("irgen") {
|
||||
if matches.irgen {
|
||||
kecc::test_irgen(Path::new(&input));
|
||||
return;
|
||||
}
|
||||
|
||||
if matches.is_present("irparse") {
|
||||
if matches.irparse {
|
||||
kecc::test_irparse(Path::new(&input));
|
||||
return;
|
||||
}
|
||||
|
||||
if matches.is_present("simplify-cfg") {
|
||||
if matches.simplify_cfg {
|
||||
todo!("test simplify-cfg");
|
||||
}
|
||||
|
||||
if matches.is_present("mem2erg") {
|
||||
if matches.mem2reg {
|
||||
todo!("test mem2reg");
|
||||
}
|
||||
|
||||
if matches.is_present("deadcode") {
|
||||
if matches.deadcode {
|
||||
todo!("test deadcode");
|
||||
}
|
||||
|
||||
if matches.is_present("gvn") {
|
||||
if matches.gvn {
|
||||
todo!("test gvn");
|
||||
}
|
||||
|
||||
if matches.is_present("end-to-end") {
|
||||
if matches.end_to_end {
|
||||
kecc::test_end_to_end(Path::new(&input));
|
||||
return;
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
Path::new(input).extension(),
|
||||
Path::new(&input).extension(),
|
||||
Some(std::ffi::OsStr::new("ir"))
|
||||
);
|
||||
kecc::test_asmgen(Path::new(&input));
|
||||
|
||||
Reference in New Issue
Block a user