mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-04-24 22:32:20 +00:00
add example
This commit is contained in:
parent
ad83ad17ee
commit
5b2cd9c4c6
28
examples/opt_imports.rs
Normal file
28
examples/opt_imports.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
extern crate pwasm_utils as utils;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args = env::args().collect::<Vec<_>>();
|
||||||
|
if args.len() != 3 {
|
||||||
|
println!("Usage: {} input_file.wasm output_file.wasm", args[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loading module
|
||||||
|
let mut module = utils::Module::from_elements(
|
||||||
|
&parity_wasm::deserialize_file(&args[1]).expect("Module deserialization to succeed")
|
||||||
|
).expect("Failed to parse parity-wasm format");
|
||||||
|
|
||||||
|
let mut delete_types = Vec::new();
|
||||||
|
for type_ in module.types.iter() {
|
||||||
|
if type_.link_count() == 0 {
|
||||||
|
delete_types.push(type_.order().expect("type in list should have index"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.types.delete(&delete_types[..]);
|
||||||
|
|
||||||
|
parity_wasm::serialize_to_file(&args[2],
|
||||||
|
module.generate().expect("Failed to generate valid format")
|
||||||
|
).expect("Module serialization to succeed")
|
||||||
|
}
|
@ -410,7 +410,8 @@ impl Module {
|
|||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate(&self) -> Result<elements::Module, Error> {
|
/// Generate raw format representation.
|
||||||
|
pub fn generate(&self) -> Result<elements::Module, Error> {
|
||||||
use self::ImportedOrDeclared::*;
|
use self::ImportedOrDeclared::*;
|
||||||
|
|
||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
|
@ -32,7 +32,7 @@ pub use gas::inject_gas_counter;
|
|||||||
pub use optimizer::{optimize, Error as OptimizerError};
|
pub use optimizer::{optimize, Error as OptimizerError};
|
||||||
pub use pack::{pack_instance, Error as PackingError};
|
pub use pack::{pack_instance, Error as PackingError};
|
||||||
pub use runtime_type::inject_runtime_type;
|
pub use runtime_type::inject_runtime_type;
|
||||||
pub use graph::{Module, parse, generate};
|
pub use graph::{Module, parse as graph_parse, generate as graph_generate};
|
||||||
pub use ref_list::{RefList, Entry, EntryRef, DeleteTransaction};
|
pub use ref_list::{RefList, Entry, EntryRef, DeleteTransaction};
|
||||||
|
|
||||||
pub struct TargetSymbols {
|
pub struct TargetSymbols {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user