diff --git a/README.md b/README.md index 6d2d55b..ff1761f 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ cargo install pwasm-utils-cli --bin wasm-prune wasm-prune ``` -This will optimize WASM symbols tree to leave only those elements that are used by contract `_call` function entry. +This will optimize WASM symbols tree to leave only those elements that are used by contract `call` function entry. ## Gas counter (wasm-gas) diff --git a/cli/prune/main.rs b/cli/prune/main.rs index 658e249..50d40d5 100644 --- a/cli/prune/main.rs +++ b/cli/prune/main.rs @@ -8,7 +8,7 @@ use clap::{App, Arg}; fn main() { logger::init_log(); - let matches = App::new("wasm-opt") + let matches = App::new("wasm-prune") .arg(Arg::with_name("input") .index(1) .required(true) @@ -22,12 +22,12 @@ fn main() { .short("e") .takes_value(true) .value_name("functions") - .help("Comma-separated list of exported functions to keep. Default: _call")) + .help(&format!("Comma-separated list of exported functions to keep. Default: '{}'", utils::CALL_SYMBOL))) .get_matches(); let exports = matches .value_of("exports") - .unwrap_or("_call") + .unwrap_or(utils::CALL_SYMBOL) .split(',') .collect(); @@ -39,7 +39,7 @@ fn main() { // Invoke optimizer // Contract is supposed to have only these functions as public api // All other symbols not usable by this list is optimized away - utils::optimize(&mut module, exports).expect("Optimizer to finish without errors"); + utils::optimize(&mut module, exports).expect("Optimizer failed"); - parity_wasm::serialize_to_file(&output, module).unwrap(); + parity_wasm::serialize_to_file(&output, module).expect("Serialization failed"); } diff --git a/src/pack.rs b/src/pack.rs index e8a1096..85d4c2b 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -33,15 +33,15 @@ impl fmt::Display for Error { Error::NoTypeSection => write!(f, "No type section in the module"), Error::NoExportSection => write!(f, "No export section in the module"), Error::NoCodeSection => write!(f, "No code section inthe module"), - Error::InvalidCreateSignature => write!(f, "Exported symbol `deploy` has invalid signature, should be () -> ()"), - Error::InvalidCreateMember => write!(f, "Exported symbol `deploy` should be a function"), - Error::NoCreateSymbol => write!(f, "No exported `deploy` symbol"), + Error::InvalidCreateSignature => write!(f, "Exported symbol `{}` has invalid signature, should be () -> ()", CREATE_SYMBOL), + Error::InvalidCreateMember => write!(f, "Exported symbol `{}` should be a function", CREATE_SYMBOL), + Error::NoCreateSymbol => write!(f, "No exported `{}` symbol", CREATE_SYMBOL), Error::NoImportSection => write!(f, "No import section in the module"), } } } -/// If module has an exported "_create" function we want to pack it into "constructor". +/// If module has an exported "CREATE_SYMBOL" function we want to pack it into "constructor". /// `raw_module` is the actual contract code /// `ctor_module` is the constructor which should return `raw_module` pub fn pack_instance(raw_module: Vec, mut ctor_module: elements::Module) -> Result { @@ -49,7 +49,7 @@ pub fn pack_instance(raw_module: Vec, mut ctor_module: elements::Module) -> // Total number of constructor module import functions let ctor_import_functions = ctor_module.import_section().map(|x| x.functions()).unwrap_or(0); - // We need to find an internal ID of function witch is exported as "_create" + // We need to find an internal ID of function witch is exported as "CREATE_SYMBOL" // in order to find it in the Code section of the module let mut create_func_id = { let found_entry = ctor_module.export_section().ok_or(Error::NoExportSection)?.entries().iter() @@ -63,7 +63,7 @@ pub fn pack_instance(raw_module: Vec, mut ctor_module: elements::Module) -> // Calculates a function index within module's function section let function_internal_index = function_index - ctor_import_functions; - // Constructor should be of signature `func(i32)` (void), fail otherwise + // Constructor should be of signature `func()` (void), fail otherwise let type_id = ctor_module.function_section().ok_or(Error::NoCodeSection)? .entries().get(function_index - ctor_import_functions).ok_or(Error::MalformedModule)? .type_ref(); @@ -207,7 +207,7 @@ pub fn pack_instance(raw_module: Vec, mut ctor_module: elements::Module) -> &mut Section::Export(ref mut export_section) => { for entry in export_section.entries_mut().iter_mut() { if CREATE_SYMBOL == entry.field() { - // change _create export name into default _call + // change "CREATE_SYMBOL" export name into default "CALL_SYMBOL" *entry.field_mut() = CALL_SYMBOL.to_owned(); *entry.internal_mut() = elements::Internal::Function(last_function_index as u32); }