[−][src]Trait wasmparser::WasmDecoder
Required methods
fn read(&mut self) -> &ParserState<'a>
fn push_input(&mut self, input: ParserInput)
fn read_with_input(&mut self, input: ParserInput) -> &ParserState<'a>
fn create_binary_reader<'b>(&mut self) -> BinaryReader<'b> where
'a: 'b,
'a: 'b,
fn last_state(&self) -> &ParserState<'a>
Implementors
impl<'a> WasmDecoder<'a> for Parser<'a>
[src]
fn read(&mut self) -> &ParserState<'a>
[src]
Reads next record from the WebAssembly binary data. The methods returns
reference to current state of the parser. See ParserState
num.
Examples
use wasmparser::WasmDecoder; let mut parser = wasmparser::Parser::new(data); { let state = parser.read(); println!("First state {:?}", state); } { let state = parser.read(); println!("Second state {:?}", state); }
fn push_input(&mut self, input: ParserInput)
[src]
fn create_binary_reader<'b>(&mut self) -> BinaryReader<'b> where
'a: 'b,
[src]
'a: 'b,
Creates a BinaryReader when current state is ParserState::BeginSection or ParserState::BeginFunctionBody.
Examples
use wasmparser::{WasmDecoder, Parser, ParserState}; let mut parser = Parser::new(data); let mut types = Vec::new(); let mut function_types = Vec::new(); let mut function_readers = Vec::new(); loop { match parser.read() { ParserState::Error(_) | ParserState::EndWasm => break, ParserState::TypeSectionEntry(ty) => { types.push(ty.clone()); } ParserState::FunctionSectionEntry(id) => { function_types.push(id.clone()); } ParserState::BeginFunctionBody {..} => { let reader = parser.create_binary_reader(); function_readers.push(reader); } _ => continue } } for (i, reader) in function_readers.iter_mut().enumerate() { // Access the function type through the types table. let ty = &types[function_types[i] as usize]; println!("\nFunction {} of type {:?}", i, ty); // Read the local declarations required by the function body. let local_decls_len = reader.read_local_count().unwrap(); let mut local_decls = Vec::with_capacity(local_decls_len); let mut local_count = ty.params.len(); for _ in 0..local_decls_len { let local_decl = reader.read_local_decl(&mut local_count).unwrap(); local_decls.push(local_decl); } println!("Function locals: vars {:?}; total {} ", local_decls, local_count); // Read the operations of the function body. while let Ok(ref op) = reader.read_operator() { println!(" {:?}", op); } }
fn read_with_input(&mut self, input: ParserInput) -> &ParserState<'a>
[src]
Reads next record from the WebAssembly binary data. It also allows to
control how parser will treat the next record(s). The method accepts the
ParserInput
parameter that allows e.g. to skip section or function
operators. The methods returns reference to current state of the parser.
Examples
use wasmparser::WasmDecoder; let mut parser = wasmparser::Parser::new(data); let mut next_input = wasmparser::ParserInput::Default; loop { let state = parser.read_with_input(next_input); match *state { wasmparser::ParserState::EndWasm => break, wasmparser::ParserState::BeginWasm { .. } | wasmparser::ParserState::EndSection => next_input = wasmparser::ParserInput::Default, wasmparser::ParserState::BeginSection { ref code, .. } => { println!("Found section: {:?}", code); next_input = wasmparser::ParserInput::SkipSection; }, _ => unreachable!() } }
fn last_state(&self) -> &ParserState<'a>
[src]
impl<'a> WasmDecoder<'a> for ValidatingParser<'a>
[src]
fn read(&mut self) -> &ParserState<'a>
[src]
fn push_input(&mut self, input: ParserInput)
[src]
fn read_with_input(&mut self, input: ParserInput) -> &ParserState<'a>
[src]
fn create_binary_reader<'b>(&mut self) -> BinaryReader<'b> where
'a: 'b,
[src]
'a: 'b,