cranelift-wasm: upgrade to wasmparser 0.39.1 (#1068)
Uses new SectionContent api, which is simpler than matching on SectionCode and then getting the right reader, & avoids possible panics
This commit is contained in:
@@ -11,7 +11,7 @@ keywords = ["webassembly", "wasm"]
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmparser = { version = "0.37.0", default-features = false }
|
wasmparser = { version = "0.39.1", default-features = false }
|
||||||
cranelift-codegen = { path = "../cranelift-codegen", version = "0.43.1", default-features = false }
|
cranelift-codegen = { path = "../cranelift-codegen", version = "0.43.1", default-features = false }
|
||||||
cranelift-entity = { path = "../cranelift-entity", version = "0.43.1", default-features = false }
|
cranelift-entity = { path = "../cranelift-entity", version = "0.43.1", default-features = false }
|
||||||
cranelift-frontend = { path = "../cranelift-frontend", version = "0.43.1", default-features = false }
|
cranelift-frontend = { path = "../cranelift-frontend", version = "0.43.1", default-features = false }
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crate::sections_translator::{
|
|||||||
parse_name_section, parse_start_section, parse_table_section, parse_type_section,
|
parse_name_section, parse_start_section, parse_table_section, parse_type_section,
|
||||||
};
|
};
|
||||||
use cranelift_codegen::timing;
|
use cranelift_codegen::timing;
|
||||||
use wasmparser::{CustomSectionKind, ModuleReader, SectionCode};
|
use wasmparser::{CustomSectionContent, ModuleReader, SectionContent};
|
||||||
|
|
||||||
/// Translate a sequence of bytes forming a valid Wasm binary into a list of valid Cranelift IR
|
/// Translate a sequence of bytes forming a valid Wasm binary into a list of valid Cranelift IR
|
||||||
/// [`Function`](cranelift_codegen::ir::Function).
|
/// [`Function`](cranelift_codegen::ir::Function).
|
||||||
@@ -20,83 +20,73 @@ pub fn translate_module<'data>(
|
|||||||
|
|
||||||
while !reader.eof() {
|
while !reader.eof() {
|
||||||
let section = reader.read()?;
|
let section = reader.read()?;
|
||||||
match section.code {
|
match section.content()? {
|
||||||
SectionCode::Type => {
|
SectionContent::Type(types) => {
|
||||||
let types = section.get_type_section_reader()?;
|
|
||||||
parse_type_section(types, environ)?;
|
parse_type_section(types, environ)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionCode::Import => {
|
SectionContent::Import(imports) => {
|
||||||
let imports = section.get_import_section_reader()?;
|
|
||||||
parse_import_section(imports, environ)?;
|
parse_import_section(imports, environ)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionCode::Function => {
|
SectionContent::Function(functions) => {
|
||||||
let functions = section.get_function_section_reader()?;
|
|
||||||
parse_function_section(functions, environ)?;
|
parse_function_section(functions, environ)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionCode::Table => {
|
SectionContent::Table(tables) => {
|
||||||
let tables = section.get_table_section_reader()?;
|
|
||||||
parse_table_section(tables, environ)?;
|
parse_table_section(tables, environ)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionCode::Memory => {
|
SectionContent::Memory(memories) => {
|
||||||
let memories = section.get_memory_section_reader()?;
|
|
||||||
parse_memory_section(memories, environ)?;
|
parse_memory_section(memories, environ)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionCode::Global => {
|
SectionContent::Global(globals) => {
|
||||||
let globals = section.get_global_section_reader()?;
|
|
||||||
parse_global_section(globals, environ)?;
|
parse_global_section(globals, environ)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionCode::Export => {
|
SectionContent::Export(exports) => {
|
||||||
let exports = section.get_export_section_reader()?;
|
|
||||||
parse_export_section(exports, environ)?;
|
parse_export_section(exports, environ)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionCode::Start => {
|
SectionContent::Start(start) => {
|
||||||
let start = section.get_start_section_content()?;
|
|
||||||
parse_start_section(start, environ)?;
|
parse_start_section(start, environ)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionCode::Element => {
|
SectionContent::Element(elements) => {
|
||||||
let elements = section.get_element_section_reader()?;
|
|
||||||
parse_element_section(elements, environ)?;
|
parse_element_section(elements, environ)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionCode::Code => {
|
SectionContent::Code(code) => {
|
||||||
let code = section.get_code_section_reader()?;
|
|
||||||
parse_code_section(code, environ)?;
|
parse_code_section(code, environ)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionCode::Data => {
|
SectionContent::Data(data) => {
|
||||||
let data = section.get_data_section_reader()?;
|
|
||||||
parse_data_section(data, environ)?;
|
parse_data_section(data, environ)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionCode::DataCount => {
|
SectionContent::DataCount(_) => {
|
||||||
return Err(WasmError::InvalidWebAssembly {
|
return Err(WasmError::InvalidWebAssembly {
|
||||||
message: "don't know how to handle the data count section yet",
|
message: "don't know how to handle the data count section yet",
|
||||||
offset: reader.current_position(),
|
offset: reader.current_position(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionCode::Custom {
|
SectionContent::Custom {
|
||||||
kind: CustomSectionKind::Name,
|
name,
|
||||||
name: _,
|
binary,
|
||||||
} => {
|
content,
|
||||||
let names = section.get_name_section_reader()?;
|
} => match content {
|
||||||
|
Some(CustomSectionContent::Name(names)) => {
|
||||||
parse_name_section(names, environ)?;
|
parse_name_section(names, environ)?;
|
||||||
}
|
}
|
||||||
|
_ => {
|
||||||
SectionCode::Custom { name, kind: _ } => {
|
let mut reader = binary.clone();
|
||||||
let mut reader = section.get_binary_reader();
|
|
||||||
let len = reader.bytes_remaining();
|
let len = reader.bytes_remaining();
|
||||||
let payload = reader.read_bytes(len)?;
|
let payload = reader.read_bytes(len)?;
|
||||||
environ.custom_section(name, payload)?;
|
environ.custom_section(name, payload)?;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user