forked from mirrors/gecko-dev
This is the first time we pin a specific Cranelift commit hash to use in Gecko. The target-lexicon hack is removed and instead we introduce a vendor patch for cranelift-codegen/cranelift-wasm themselves. Notable changes happen in top-level Cargo.toml, .cargo/config.in and js/src/wasm/cranelift/Cargo.toml; the rest has been generated by `mach vendor rust`. Differential Revision: https://phabricator.services.mozilla.com/D27316 --HG-- extra : moz-landing-system : lando
56 lines
1.5 KiB
Rust
56 lines
1.5 KiB
Rust
extern crate wasmparser;
|
|
|
|
use std::env;
|
|
use std::fs::File;
|
|
use std::io;
|
|
use std::io::prelude::*;
|
|
use std::str;
|
|
use wasmparser::Parser;
|
|
use wasmparser::ParserState;
|
|
use wasmparser::WasmDecoder;
|
|
|
|
fn main() {
|
|
let args = env::args().collect::<Vec<_>>();
|
|
if args.len() != 2 {
|
|
println!("Usage: {} in.wasm", args[0]);
|
|
return;
|
|
}
|
|
|
|
let buf: Vec<u8> = read_wasm(&args[1]).unwrap();
|
|
let mut parser = Parser::new(&buf);
|
|
loop {
|
|
let state = parser.read();
|
|
match *state {
|
|
ParserState::ExportSectionEntry {
|
|
field,
|
|
ref kind,
|
|
index,
|
|
} => {
|
|
println!(
|
|
"ExportSectionEntry {{ field: \"{}\", kind: {:?}, index: {} }}",
|
|
field, kind, index
|
|
);
|
|
}
|
|
ParserState::ImportSectionEntry {
|
|
module,
|
|
field,
|
|
ref ty,
|
|
} => {
|
|
println!(
|
|
"ImportSectionEntry {{ module: \"{}\", field: \"{}\", ty: {:?} }}",
|
|
module, field, ty
|
|
);
|
|
}
|
|
ParserState::EndWasm => break,
|
|
ParserState::Error(err) => panic!("Error: {:?}", err),
|
|
_ => println!("{:?}", state),
|
|
}
|
|
}
|
|
}
|
|
|
|
fn read_wasm(file: &str) -> io::Result<Vec<u8>> {
|
|
let mut data = Vec::new();
|
|
let mut f = File::open(file)?;
|
|
f.read_to_end(&mut data)?;
|
|
Ok(data)
|
|
}
|