Do a full compile in 'cton-util wasm'.
This removes the `optimize` option, as one can do that with `--set`, eg. `--set opt_level=best`. And it adds an option to print the compilation output.
This commit is contained in:
@@ -30,13 +30,16 @@ Usage:
|
|||||||
cton-util cat <file>...
|
cton-util cat <file>...
|
||||||
cton-util filecheck [-v] <file>
|
cton-util filecheck [-v] <file>
|
||||||
cton-util print-cfg <file>...
|
cton-util print-cfg <file>...
|
||||||
cton-util wasm [-cvo] [--set <set>]... [--isa <isa>] <file>...
|
cton-util wasm [-ctvp] [--set <set>]... [--isa <isa>] <file>...
|
||||||
cton-util --help | --version
|
cton-util --help | --version
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-v, --verbose be more verbose
|
-v, --verbose be more verbose
|
||||||
-c, --check checks the correctness of Cretonne IL translated from WebAssembly
|
-t, --just-decode
|
||||||
-o, --optimize runs otpimization passes on translated WebAssembly functions
|
just decode WebAssembly to Cretonne IL
|
||||||
|
-c, --check-translation
|
||||||
|
just checks the correctness of Cretonne IL translated from WebAssembly
|
||||||
|
-p, --print print the resulting Cretonne IL
|
||||||
-h, --help print this help message
|
-h, --help print this help message
|
||||||
--set=<set> configure Cretonne settings
|
--set=<set> configure Cretonne settings
|
||||||
--isa=<isa> specify the Cretonne ISA
|
--isa=<isa> specify the Cretonne ISA
|
||||||
@@ -52,8 +55,9 @@ struct Args {
|
|||||||
cmd_print_cfg: bool,
|
cmd_print_cfg: bool,
|
||||||
cmd_wasm: bool,
|
cmd_wasm: bool,
|
||||||
arg_file: Vec<String>,
|
arg_file: Vec<String>,
|
||||||
flag_check: bool,
|
flag_just_decode: bool,
|
||||||
flag_optimize: bool,
|
flag_check_translation: bool,
|
||||||
|
flag_print: bool,
|
||||||
flag_verbose: bool,
|
flag_verbose: bool,
|
||||||
flag_set: Vec<String>,
|
flag_set: Vec<String>,
|
||||||
flag_isa: String,
|
flag_isa: String,
|
||||||
@@ -86,8 +90,9 @@ fn cton_util() -> CommandResult {
|
|||||||
wasm::run(
|
wasm::run(
|
||||||
args.arg_file,
|
args.arg_file,
|
||||||
args.flag_verbose,
|
args.flag_verbose,
|
||||||
args.flag_optimize,
|
args.flag_just_decode,
|
||||||
args.flag_check,
|
args.flag_check_translation,
|
||||||
|
args.flag_print,
|
||||||
args.flag_set,
|
args.flag_set,
|
||||||
args.flag_isa,
|
args.flag_isa,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use cton_wasm::{translate_module, DummyRuntime, WasmRuntime};
|
|||||||
use cton_reader::{parse_options, Location};
|
use cton_reader::{parse_options, Location};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use cretonne::Context;
|
use cretonne::Context;
|
||||||
use cretonne::verifier;
|
|
||||||
use cretonne::settings::{self, FlagsOrIsa};
|
use cretonne::settings::{self, FlagsOrIsa};
|
||||||
use cretonne::isa::{self, TargetIsa};
|
use cretonne::isa::{self, TargetIsa};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
@@ -54,8 +53,9 @@ enum OwnedFlagsOrIsa {
|
|||||||
pub fn run(
|
pub fn run(
|
||||||
files: Vec<String>,
|
files: Vec<String>,
|
||||||
flag_verbose: bool,
|
flag_verbose: bool,
|
||||||
flag_optimize: bool,
|
flag_just_decode: bool,
|
||||||
flag_check: bool,
|
flag_check_translation: bool,
|
||||||
|
flag_print: bool,
|
||||||
flag_set: Vec<String>,
|
flag_set: Vec<String>,
|
||||||
flag_isa: String,
|
flag_isa: String,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
@@ -87,8 +87,9 @@ pub fn run(
|
|||||||
let name = String::from(path.as_os_str().to_string_lossy());
|
let name = String::from(path.as_os_str().to_string_lossy());
|
||||||
handle_module(
|
handle_module(
|
||||||
flag_verbose,
|
flag_verbose,
|
||||||
flag_optimize,
|
flag_just_decode,
|
||||||
flag_check,
|
flag_check_translation,
|
||||||
|
flag_print,
|
||||||
path.to_path_buf(),
|
path.to_path_buf(),
|
||||||
name,
|
name,
|
||||||
&fisa,
|
&fisa,
|
||||||
@@ -99,8 +100,9 @@ pub fn run(
|
|||||||
|
|
||||||
fn handle_module(
|
fn handle_module(
|
||||||
flag_verbose: bool,
|
flag_verbose: bool,
|
||||||
flag_optimize: bool,
|
flag_just_decode: bool,
|
||||||
flag_check: bool,
|
flag_check_translation: bool,
|
||||||
|
flag_print: bool,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
name: String,
|
name: String,
|
||||||
fisa: &FlagsOrIsa,
|
fisa: &FlagsOrIsa,
|
||||||
@@ -157,41 +159,40 @@ fn handle_module(
|
|||||||
terminal.fg(term::color::GREEN).unwrap();
|
terminal.fg(term::color::GREEN).unwrap();
|
||||||
vprintln!(flag_verbose, "ok");
|
vprintln!(flag_verbose, "ok");
|
||||||
terminal.reset().unwrap();
|
terminal.reset().unwrap();
|
||||||
if flag_check {
|
if flag_just_decode {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
terminal.fg(term::color::MAGENTA).unwrap();
|
terminal.fg(term::color::MAGENTA).unwrap();
|
||||||
|
if flag_check_translation {
|
||||||
vprint!(flag_verbose, "Checking... ");
|
vprint!(flag_verbose, "Checking... ");
|
||||||
terminal.reset().unwrap();
|
} else {
|
||||||
for func in &translation.functions {
|
vprint!(flag_verbose, "Compiling... ");
|
||||||
verifier::verify_function(func, *fisa).map_err(|err| {
|
|
||||||
pretty_verifier_error(func, fisa.isa, err)
|
|
||||||
})?;
|
|
||||||
}
|
}
|
||||||
terminal.fg(term::color::GREEN).unwrap();
|
|
||||||
vprintln!(flag_verbose, " ok");
|
|
||||||
terminal.reset().unwrap();
|
|
||||||
}
|
|
||||||
if flag_optimize {
|
|
||||||
terminal.fg(term::color::MAGENTA).unwrap();
|
|
||||||
vprint!(flag_verbose, "Optimizing... ");
|
|
||||||
terminal.reset().unwrap();
|
terminal.reset().unwrap();
|
||||||
for func in &translation.functions {
|
for func in &translation.functions {
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
context.func = func.clone();
|
context.func = func.clone();
|
||||||
|
if flag_check_translation {
|
||||||
context.verify(*fisa).map_err(|err| {
|
context.verify(*fisa).map_err(|err| {
|
||||||
pretty_verifier_error(&context.func, fisa.isa, err)
|
pretty_verifier_error(&context.func, fisa.isa, err)
|
||||||
})?;
|
})?;
|
||||||
context.flowgraph();
|
continue;
|
||||||
context.compute_loop_analysis();
|
}
|
||||||
context.licm(*fisa).map_err(|err| {
|
if let Some(isa) = fisa.isa {
|
||||||
pretty_error(&context.func, fisa.isa, err)
|
context.compile(isa).map_err(|err| {
|
||||||
})?;
|
|
||||||
context.simple_gvn(*fisa).map_err(|err| {
|
|
||||||
pretty_error(&context.func, fisa.isa, err)
|
pretty_error(&context.func, fisa.isa, err)
|
||||||
})?;
|
})?;
|
||||||
|
} else {
|
||||||
|
return Err(String::from("compilation requires a target isa"));
|
||||||
|
}
|
||||||
|
if flag_print {
|
||||||
|
vprintln!(flag_verbose, "");
|
||||||
|
println!("{}", context.func.display(fisa.isa));
|
||||||
|
vprintln!(flag_verbose, "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
terminal.fg(term::color::GREEN).unwrap();
|
terminal.fg(term::color::GREEN).unwrap();
|
||||||
vprintln!(flag_verbose, "ok");
|
vprintln!(flag_verbose, "ok");
|
||||||
terminal.reset().unwrap();
|
terminal.reset().unwrap();
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user