summaryrefslogtreecommitdiffstats
path: root/third_party/rust/parity-wasm/examples/roundtrip.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/parity-wasm/examples/roundtrip.rs')
-rw-r--r--third_party/rust/parity-wasm/examples/roundtrip.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/third_party/rust/parity-wasm/examples/roundtrip.rs b/third_party/rust/parity-wasm/examples/roundtrip.rs
new file mode 100644
index 0000000000..b3b951912a
--- /dev/null
+++ b/third_party/rust/parity-wasm/examples/roundtrip.rs
@@ -0,0 +1,27 @@
+extern crate parity_wasm;
+
+use std::env;
+
+fn main() {
+ let args = env::args().collect::<Vec<_>>();
+ if args.len() != 3 {
+ println!("Usage: {} in.wasm out.wasm", args[0]);
+ return;
+ }
+
+ let module = match parity_wasm::deserialize_file(&args[1])
+ .expect("Failed to load module")
+ .parse_names()
+ .and_then(|module| module.parse_reloc())
+ {
+ Ok(m) => m,
+ Err((errors, m)) => {
+ for (index, error) in errors.into_iter() {
+ println!("Custom section #{} parse error: {:?}", index, error);
+ }
+ m
+ }
+ };
+
+ parity_wasm::serialize_to_file(&args[2], module).expect("Failed to write module");
+}