prints to logger

This commit is contained in:
NikVolf
2017-05-05 15:51:08 +03:00
parent cb4f16d453
commit 8fca2a9eb6
5 changed files with 45 additions and 11 deletions

View File

@ -5,6 +5,9 @@ authors = ["NikVolf <nikvolf@gmail.com>"]
[dependencies] [dependencies]
parity-wasm = { git="https://github.com/nikvolf/parity-wasm" } parity-wasm = { git="https://github.com/nikvolf/parity-wasm" }
log = "0.3"
env_logger = "0.4"
lazy_static = "0.2"
[lib] [lib]

View File

@ -1,8 +1,13 @@
extern crate parity_wasm; extern crate parity_wasm;
extern crate env_logger;
#[macro_use] extern crate log;
#[macro_use] extern crate lazy_static;
mod optimizer; mod optimizer;
mod gas; mod gas;
mod symbols; mod symbols;
mod logger;
pub use optimizer::optimize; pub use optimizer::optimize;
pub use gas::inject_gas_counter; pub use gas::inject_gas_counter;
pub use logger::init_log;

26
src/logger.rs Normal file
View File

@ -0,0 +1,26 @@
extern crate log;
use std::env;
use log::LogLevelFilter;
use env_logger::LogBuilder;
lazy_static! {
static ref LOG_DUMMY: bool = {
let mut builder = LogBuilder::new();
builder.filter(None, LogLevelFilter::Info);
if let Ok(log) = env::var("RUST_LOG") {
builder.parse(&log);
}
if let Ok(_) = builder.init() {
println!("logger initialized");
}
true
};
}
/// Intialize log with default settings
pub fn init_log() {
let _ = *LOG_DUMMY;
}

View File

@ -41,7 +41,7 @@ pub fn optimize(
expand_symbols(module, &mut stay); expand_symbols(module, &mut stay);
for symbol in stay.iter() { for symbol in stay.iter() {
println!("symbol to stay: {:?}", symbol); trace!("symbol to stay: {:?}", symbol);
} }
// Keep track of referreable symbols to rewire calls/globals // Keep track of referreable symbols to rewire calls/globals
@ -62,7 +62,7 @@ pub fn optimize(
} else { } else {
type_section(module).expect("Code section to exist").types_mut().remove(index); type_section(module).expect("Code section to exist").types_mut().remove(index);
eliminated_types.push(old_index); eliminated_types.push(old_index);
println!("Eliminated type({})", old_index); trace!("Eliminated type({})", old_index);
} }
old_index += 1; old_index += 1;
} }
@ -85,7 +85,7 @@ pub fn optimize(
} else { } else {
remove = true; remove = true;
eliminated_funcs.push(top_funcs); eliminated_funcs.push(top_funcs);
println!("Eliminated import({}) func({}, {})", old_index, top_funcs, imports.entries()[index].field()); trace!("Eliminated import({}) func({}, {})", old_index, top_funcs, imports.entries()[index].field());
} }
top_funcs += 1; top_funcs += 1;
}, },
@ -95,7 +95,7 @@ pub fn optimize(
} else { } else {
remove = true; remove = true;
eliminated_globals.push(top_globals); eliminated_globals.push(top_globals);
println!("Eliminated import({}) global({}, {})", old_index, top_globals, imports.entries()[index].field()); trace!("Eliminated import({}) global({}, {})", old_index, top_globals, imports.entries()[index].field());
} }
top_globals += 1; top_globals += 1;
}, },
@ -127,7 +127,7 @@ pub fn optimize(
} else { } else {
globals.entries_mut().remove(index); globals.entries_mut().remove(index);
eliminated_globals.push(top_globals + old_index); eliminated_globals.push(top_globals + old_index);
println!("Eliminated global({})", top_globals + old_index); trace!("Eliminated global({})", top_globals + old_index);
} }
old_index += 1; old_index += 1;
} }
@ -146,7 +146,7 @@ pub fn optimize(
code_section(module).expect("Code section to exist").bodies_mut().remove(index); code_section(module).expect("Code section to exist").bodies_mut().remove(index);
eliminated_funcs.push(top_funcs + old_index); eliminated_funcs.push(top_funcs + old_index);
println!("Eliminated function({})", top_funcs + old_index); trace!("Eliminated function({})", top_funcs + old_index);
} }
old_index += 1; old_index += 1;
} }
@ -163,7 +163,7 @@ pub fn optimize(
if stay.contains(&Symbol::Export(old_index)) { if stay.contains(&Symbol::Export(old_index)) {
index += 1; index += 1;
} else { } else {
println!("Eliminated export({}, {})", old_index, exports.entries_mut()[index].field()); trace!("Eliminated export({}, {})", old_index, exports.entries_mut()[index].field());
exports.entries_mut().remove(index); exports.entries_mut().remove(index);
} }
old_index += 1; old_index += 1;
@ -251,7 +251,7 @@ pub fn update_call_index(opcodes: &mut elements::Opcodes, eliminated_indices: &[
}, },
&mut Call(ref mut call_index) => { &mut Call(ref mut call_index) => {
let totalle = eliminated_indices.iter().take_while(|i| (**i as u32) < *call_index).count(); let totalle = eliminated_indices.iter().take_while(|i| (**i as u32) < *call_index).count();
println!("rewired call {} -> call {}", *call_index, *call_index - totalle as u32); trace!("rewired call {} -> call {}", *call_index, *call_index - totalle as u32);
*call_index -= totalle as u32; *call_index -= totalle as u32;
}, },
_ => { }, _ => { },
@ -269,7 +269,7 @@ pub fn update_global_index(opcodes: &mut Vec<elements::Opcode>, eliminated_indic
}, },
&mut GetGlobal(ref mut index) | &mut SetGlobal(ref mut index) => { &mut GetGlobal(ref mut index) | &mut SetGlobal(ref mut index) => {
let totalle = eliminated_indices.iter().take_while(|i| (**i as u32) < *index).count(); let totalle = eliminated_indices.iter().take_while(|i| (**i as u32) < *index).count();
println!("rewired global {} -> global {}", *index, *index - totalle as u32); trace!("rewired global {} -> global {}", *index, *index - totalle as u32);
*index -= totalle as u32; *index -= totalle as u32;
}, },
_ => { }, _ => { },

View File

@ -75,7 +75,7 @@ pub fn expand_symbols(module: &elements::Module, set: &mut HashSet<Symbol>) {
Some(s) => s, Some(s) => s,
_ => { break; } _ => { break; }
}; };
println!("Processing symbol {:?}", next); trace!("Processing symbol {:?}", next);
match next { match next {
Export(idx) => { Export(idx) => {