diff --git a/Cargo.toml b/Cargo.toml index faaff386e6..7e6a30ab8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,8 @@ serde_derive = "1.0.75" tempdir = "*" faerie = "0.6.0" target-lexicon = { version = "0.2.0", default-features = false } +pretty_env_logger = "0.2.5" +file-per-thread-logger = "0.1.1" [dev-dependencies] wabt = "0.7" diff --git a/src/main.rs b/src/main.rs index 25a3ec1441..d4b3b5aa60 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,6 +42,8 @@ extern crate wasmtime_environ; extern crate wasmtime_execute; #[macro_use] extern crate serde_derive; +extern crate file_per_thread_logger; +extern crate pretty_env_logger; extern crate tempdir; #[cfg(test)] @@ -65,14 +67,16 @@ use tempdir::TempDir; use wasmtime_environ::{Module, ModuleEnvironment}; use wasmtime_execute::{compile_and_link_module, execute, finish_instantiation, Instance}; +static LOG_FILENAME_PREFIX: &str = "cranelift.dbg."; + const USAGE: &str = " Wasm to Cranelift IL translation utility. Takes a binary WebAssembly module and returns its functions in Cranelift IL format. The translation is dependent on the environment chosen. Usage: - wasmtime [-mop] ... - wasmtime [-mop] ... --function= + wasmtime [-mopd] ... + wasmtime [-mopd] ... --function= wasmtime --help | --version Options: @@ -81,6 +85,7 @@ Options: --function= name of function to run -h, --help print this help message --version print the Cranelift version + -d, --debug enable debug output on stderr/stdout "; #[derive(Deserialize, Debug, Clone)] @@ -88,6 +93,7 @@ struct Args { arg_file: Vec, flag_memory: bool, flag_optimize: bool, + flag_debug: bool, flag_function: Option, } @@ -115,6 +121,12 @@ fn main() { flag_builder.enable("enable_verifier").unwrap(); } + if args.flag_debug { + pretty_env_logger::init(); + } else { + file_per_thread_logger::initialize(LOG_FILENAME_PREFIX); + } + // Enable optimization if requested. if args.flag_optimize { flag_builder.set("opt_level", "best").unwrap();