Update to wasmparser 0.29.2.
This commit is contained in:
@@ -12,15 +12,15 @@ use crate::translation_utils::{
|
||||
type_to_type, FuncIndex, Global, GlobalIndex, GlobalInit, Memory, MemoryIndex, SignatureIndex,
|
||||
Table, TableElementType, TableIndex,
|
||||
};
|
||||
use core::str::from_utf8;
|
||||
use cranelift_codegen::ir::{self, AbiParam, Signature};
|
||||
use cranelift_entity::EntityRef;
|
||||
use std::vec::Vec;
|
||||
use wasmparser::{
|
||||
self, CodeSectionReader, Data, DataSectionReader, Element, ElementSectionReader, Export,
|
||||
ExportSectionReader, ExternalKind, FuncType, FunctionSectionReader, GlobalSectionReader,
|
||||
GlobalType, ImportSectionEntryType, ImportSectionReader, MemorySectionReader, MemoryType,
|
||||
Operator, TableSectionReader, TypeSectionReader,
|
||||
self, CodeSectionReader, Data, DataKind, DataSectionReader, Element, ElementKind,
|
||||
ElementSectionReader, Export, ExportSectionReader, ExternalKind, FuncType,
|
||||
FunctionSectionReader, GlobalSectionReader, GlobalType, ImportSectionEntryType,
|
||||
ImportSectionReader, MemorySectionReader, MemoryType, Operator, TableSectionReader,
|
||||
TypeSectionReader,
|
||||
};
|
||||
|
||||
/// Parses the Type section of the wasm module.
|
||||
@@ -65,12 +65,8 @@ pub fn parse_import_section<'data>(
|
||||
|
||||
for entry in imports {
|
||||
let import = entry?;
|
||||
|
||||
// The input has already been validated, so we should be able to
|
||||
// assume valid UTF-8 and use `from_utf8_unchecked` if performance
|
||||
// becomes a concern here.
|
||||
let module_name = from_utf8(import.module).unwrap();
|
||||
let field_name = from_utf8(import.field).unwrap();
|
||||
let module_name = import.module;
|
||||
let field_name = import.field;
|
||||
|
||||
match import.ty {
|
||||
ImportSectionEntryType::Function(sig) => {
|
||||
@@ -232,13 +228,12 @@ pub fn parse_export_section<'data>(
|
||||
// The input has already been validated, so we should be able to
|
||||
// assume valid UTF-8 and use `from_utf8_unchecked` if performance
|
||||
// becomes a concern here.
|
||||
let name = from_utf8(field).unwrap();
|
||||
let index = index as usize;
|
||||
match *kind {
|
||||
ExternalKind::Function => environ.declare_func_export(FuncIndex::new(index), name),
|
||||
ExternalKind::Table => environ.declare_table_export(TableIndex::new(index), name),
|
||||
ExternalKind::Memory => environ.declare_memory_export(MemoryIndex::new(index), name),
|
||||
ExternalKind::Global => environ.declare_global_export(GlobalIndex::new(index), name),
|
||||
ExternalKind::Function => environ.declare_func_export(FuncIndex::new(index), field),
|
||||
ExternalKind::Table => environ.declare_table_export(TableIndex::new(index), field),
|
||||
ExternalKind::Memory => environ.declare_memory_export(MemoryIndex::new(index), field),
|
||||
ExternalKind::Global => environ.declare_global_export(GlobalIndex::new(index), field),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,29 +255,35 @@ pub fn parse_element_section<'data>(
|
||||
environ.reserve_table_elements(elements.get_count());
|
||||
|
||||
for entry in elements {
|
||||
let Element {
|
||||
let Element { kind, items } = entry?;
|
||||
if let ElementKind::Active {
|
||||
table_index,
|
||||
init_expr,
|
||||
items,
|
||||
} = entry?;
|
||||
let mut init_expr_reader = init_expr.get_binary_reader();
|
||||
let (base, offset) = match init_expr_reader.read_operator()? {
|
||||
Operator::I32Const { value } => (None, value as u32 as usize),
|
||||
Operator::GetGlobal { global_index } => (Some(GlobalIndex::from_u32(global_index)), 0),
|
||||
ref s => panic!("unsupported init expr in element section: {:?}", s),
|
||||
};
|
||||
let items_reader = items.get_items_reader()?;
|
||||
let mut elems = Vec::with_capacity(cast::usize(items_reader.get_count()));
|
||||
for item in items_reader {
|
||||
let x = item?;
|
||||
elems.push(FuncIndex::from_u32(x));
|
||||
} = kind
|
||||
{
|
||||
let mut init_expr_reader = init_expr.get_binary_reader();
|
||||
let (base, offset) = match init_expr_reader.read_operator()? {
|
||||
Operator::I32Const { value } => (None, value as u32 as usize),
|
||||
Operator::GetGlobal { global_index } => {
|
||||
(Some(GlobalIndex::from_u32(global_index)), 0)
|
||||
}
|
||||
ref s => panic!("unsupported init expr in element section: {:?}", s),
|
||||
};
|
||||
let items_reader = items.get_items_reader()?;
|
||||
let mut elems = Vec::with_capacity(cast::usize(items_reader.get_count()));
|
||||
for item in items_reader {
|
||||
let x = item?;
|
||||
elems.push(FuncIndex::from_u32(x));
|
||||
}
|
||||
environ.declare_table_elements(
|
||||
TableIndex::from_u32(table_index),
|
||||
base,
|
||||
offset,
|
||||
elems.into_boxed_slice(),
|
||||
)
|
||||
} else {
|
||||
panic!("unsupported passive elements section");
|
||||
}
|
||||
environ.declare_table_elements(
|
||||
TableIndex::from_u32(table_index),
|
||||
base,
|
||||
offset,
|
||||
elems.into_boxed_slice(),
|
||||
)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -309,23 +310,29 @@ pub fn parse_data_section<'data>(
|
||||
environ.reserve_data_initializers(data.get_count());
|
||||
|
||||
for entry in data {
|
||||
let Data {
|
||||
let Data { kind, data } = entry?;
|
||||
if let DataKind::Active {
|
||||
memory_index,
|
||||
init_expr,
|
||||
data,
|
||||
} = entry?;
|
||||
let mut init_expr_reader = init_expr.get_binary_reader();
|
||||
let (base, offset) = match init_expr_reader.read_operator()? {
|
||||
Operator::I32Const { value } => (None, value as u32 as usize),
|
||||
Operator::GetGlobal { global_index } => (Some(GlobalIndex::from_u32(global_index)), 0),
|
||||
ref s => panic!("unsupported init expr in data section: {:?}", s),
|
||||
};
|
||||
environ.declare_data_initialization(
|
||||
MemoryIndex::from_u32(memory_index),
|
||||
base,
|
||||
offset,
|
||||
data,
|
||||
);
|
||||
} = kind
|
||||
{
|
||||
let mut init_expr_reader = init_expr.get_binary_reader();
|
||||
let (base, offset) = match init_expr_reader.read_operator()? {
|
||||
Operator::I32Const { value } => (None, value as u32 as usize),
|
||||
Operator::GetGlobal { global_index } => {
|
||||
(Some(GlobalIndex::from_u32(global_index)), 0)
|
||||
}
|
||||
ref s => panic!("unsupported init expr in data section: {:?}", s),
|
||||
};
|
||||
environ.declare_data_initialization(
|
||||
MemoryIndex::from_u32(memory_index),
|
||||
base,
|
||||
offset,
|
||||
data,
|
||||
);
|
||||
} else {
|
||||
panic!("unsupported passive data section");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user