-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
clif-util.rs
136 lines (114 loc) · 3.33 KB
/
clif-util.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
use clap::Parser;
use std::path::PathBuf;
mod bugpoint;
mod cat;
mod compile;
mod disasm;
mod interpret;
mod print_cfg;
mod run;
mod utils;
#[cfg(feature = "souper-harvest")]
mod souper_harvest;
#[cfg(feature = "wasm")]
mod wasm;
/// Cranelift code generator utility.
#[derive(Parser)]
enum Commands {
Test(TestOptions),
Run(run::Options),
Interpret(interpret::Options),
Cat(cat::Options),
PrintCfg(print_cfg::Options),
Compile(compile::Options),
Pass(PassOptions),
Bugpoint(bugpoint::Options),
#[cfg(feature = "wasm")]
Wasm(wasm::Options),
#[cfg(not(feature = "wasm"))]
Wasm(CompiledWithoutSupportOptions),
#[cfg(feature = "souper-harvest")]
SouperHarvest(souper_harvest::Options),
#[cfg(not(feature = "souper-harvest"))]
SouperHarvest(CompiledWithoutSupportOptions),
}
/// Run Cranelift tests
#[derive(Parser)]
struct TestOptions {
/// Be more verbose
#[arg(short, long)]
verbose: bool,
/// Print pass timing report for test
#[arg(short = 'T')]
time_passes: bool,
/// Specify an input file to be used. Use '-' for stdin.
#[arg(required = true)]
files: Vec<PathBuf>,
}
/// Run specified pass(es) on an input file.
#[derive(Parser)]
struct PassOptions {
/// Be more verbose
#[arg(short, long)]
verbose: bool,
/// Print pass timing report for test
#[arg(short = 'T')]
time_passes: bool,
/// Specify an input file to be used. Use '-' for stdin.
file: PathBuf,
/// Specify the target architecture.
target: String,
/// Specify pass(es) to be run on the input file
#[arg(required = true)]
passes: Vec<String>,
}
/// (Compiled without support for this subcommand)
#[derive(Parser)]
struct CompiledWithoutSupportOptions {}
fn main() -> anyhow::Result<()> {
pretty_env_logger::init();
match Commands::parse() {
Commands::Cat(c) => cat::run(&c)?,
Commands::Run(r) => run::run(&r)?,
Commands::Interpret(i) => interpret::run(&i)?,
Commands::PrintCfg(p) => print_cfg::run(&p)?,
Commands::Compile(c) => compile::run(&c)?,
Commands::Bugpoint(b) => bugpoint::run(&b)?,
#[cfg(feature = "wasm")]
Commands::Wasm(w) => wasm::run(&w)?,
#[cfg(not(feature = "wasm"))]
Commands::Wasm(_) => anyhow::bail!("Error: clif-util was compiled without wasm support."),
#[cfg(feature = "souper-harvest")]
Commands::SouperHarvest(s) => souper_harvest::run(&s)?,
#[cfg(not(feature = "souper-harvest"))]
Commands::SouperHarvest(_) => anyhow::bail!(
"Error: clif-util was compiled without support for the `souper-harvest` \
subcommand",
),
Commands::Test(t) => {
cranelift_filetests::run(
t.verbose,
t.time_passes,
&t.files
.iter()
.map(|f| f.display().to_string())
.collect::<Vec<_>>(),
)?;
}
Commands::Pass(p) => {
cranelift_filetests::run_passes(
p.verbose,
p.time_passes,
&p.passes,
&p.target,
&p.file.display().to_string(),
)?;
}
}
Ok(())
}
#[test]
fn verify_cli() {
use clap::CommandFactory;
Commands::command().debug_assert()
}