Make progressbar optional

This commit is contained in:
Syrus Akbary 2018-12-05 23:29:27 -08:00
parent 36f70005c9
commit 27b4015373
2 changed files with 18 additions and 8 deletions

View File

@ -140,6 +140,7 @@ pub struct InstanceOptions {
pub mock_missing_globals: bool, pub mock_missing_globals: bool,
pub mock_missing_tables: bool, pub mock_missing_tables: bool,
pub use_emscripten: bool, pub use_emscripten: bool,
pub show_progressbar: bool,
pub isa: Box<TargetIsa>, pub isa: Box<TargetIsa>,
} }
@ -243,24 +244,32 @@ impl Instance {
let values: Vec<&Function> = Vec::from_iter(module.info.function_bodies.values()); let values: Vec<&Function> = Vec::from_iter(module.info.function_bodies.values());
// let isa: &TargetIsa = &*options.isa; // let isa: &TargetIsa = &*options.isa;
let progress_bar = ProgressBar::new(module.info.functions.len() as u64); let progress_bar_option = if options.show_progressbar {
progress_bar.set_style(ProgressStyle::default_bar() let progress_bar = ProgressBar::new(module.info.functions.len() as u64);
.template(&format!("{{spinner:.green}} {} [{{bar:40}}] {} {{msg}}", style("Compiling").bold(), style("{percent}%").bold().dim())) progress_bar.set_style(ProgressStyle::default_bar()
.progress_chars("=> ")); .template(&format!("{{spinner:.green}} {} [{{bar:40}}] {} {{msg}}", style("Compiling").bold(), style("{percent}%").bold().dim()))
.progress_chars("=> "));
Some(progress_bar)
} else {
None
};
let compiled_funcs: Vec<CompiledFunction> = values let compiled_funcs: Vec<CompiledFunction> = values
.par_iter() .par_iter()
.map(|function_body| -> CompiledFunction { .map(|function_body| -> CompiledFunction {
// let r = *Arc::from_raw(isa_ptr); // let r = *Arc::from_raw(isa_ptr);
let func = compile_function(&*options.isa, function_body).unwrap(); let func = compile_function(&*options.isa, function_body).unwrap();
progress_bar.inc(1); if let Some(ref progress_bar) = progress_bar_option {
progress_bar.inc(1);
};
func func
// unimplemented!() // unimplemented!()
}).collect(); }).collect();
progress_bar.set_style(ProgressStyle::default_bar() if let Some(ref progress_bar) = progress_bar_option {
.template(&format!("{} {{msg}}", style("[{elapsed_precise}]").bold().dim()))); progress_bar.set_style(ProgressStyle::default_bar()
// progress_bar.finish_with_message(&format!("{}", style("compiled, running now").bold())); .template(&format!("{} {{msg}}", style("[{elapsed_precise}]").bold().dim())));
};
for compiled_func in compiled_funcs.into_iter() { for compiled_func in compiled_funcs.into_iter() {
let CompiledFunction { let CompiledFunction {

View File

@ -71,6 +71,7 @@ pub fn instantiate(
mock_missing_globals: true, mock_missing_globals: true,
mock_missing_tables: true, mock_missing_tables: true,
use_emscripten: is_emscripten_module(&module), use_emscripten: is_emscripten_module(&module),
show_progressbar: true,
isa: isa, isa: isa,
}, },
)?; )?;