Update wasmparser to 0.59.0 (#2013)
This commit is intended to update wasmparser to 0.59.0. This primarily includes bytecodealliance/wasm-tools#40 which is a large update to how parsing and validation works. The impact on Wasmtime is pretty small at this time, but over time I'd like to refactor the internals here to lean more heavily on that upstream wasmparser refactoring. For now, though, the intention is to get on the train of wasmparser's latest `main` branch to ensure we get bug fixes and such. As part of this update a few other crates and such were updated. This is primarily to handle the new encoding of `ref.is_null` where the type is not part of the instruction encoding any more.
This commit is contained in:
@@ -24,7 +24,7 @@ smallvec = "1.0.0"
|
||||
staticvec = "0.10"
|
||||
thiserror = "1.0.9"
|
||||
typemap = "0.3"
|
||||
wasmparser = "0.58.0"
|
||||
wasmparser = "0.59.0"
|
||||
|
||||
[dev-dependencies]
|
||||
lazy_static = "1.2"
|
||||
|
||||
@@ -2130,7 +2130,7 @@ where
|
||||
WasmOperator::RefNull { ty: _ } => {
|
||||
return Err(Error::Microwasm("RefNull unimplemented".into()))
|
||||
}
|
||||
WasmOperator::RefIsNull { ty: _ } => {
|
||||
WasmOperator::RefIsNull => {
|
||||
return Err(Error::Microwasm("RefIsNull unimplemented".into()))
|
||||
}
|
||||
WasmOperator::I32Eqz => one(Operator::Eqz(Size::_32)),
|
||||
|
||||
@@ -10,7 +10,7 @@ use memoffset::offset_of;
|
||||
|
||||
use std::{convert::TryInto, mem};
|
||||
use thiserror::Error;
|
||||
use wasmparser::{FuncType, MemoryType, ModuleReader, SectionCode, Type};
|
||||
use wasmparser::{FuncType, MemoryType, Parser, Payload, Type};
|
||||
|
||||
pub trait AsValueType {
|
||||
const TYPE: Type;
|
||||
@@ -512,150 +512,58 @@ pub fn translate(data: &[u8]) -> Result<ExecutableModule, Error> {
|
||||
|
||||
/// Translate from a slice of bytes holding a wasm module.
|
||||
pub fn translate_only(data: &[u8]) -> Result<TranslatedModule, Error> {
|
||||
let mut reader = ModuleReader::new(data)?;
|
||||
let mut output = TranslatedModule::default();
|
||||
|
||||
reader.skip_custom_sections()?;
|
||||
if reader.eof() {
|
||||
return Ok(output);
|
||||
}
|
||||
let mut section = reader.read()?;
|
||||
|
||||
if let SectionCode::Type = section.code {
|
||||
let types_reader = section.get_type_section_reader()?;
|
||||
output.ctx.types = translate_sections::type_(types_reader)?;
|
||||
|
||||
reader.skip_custom_sections()?;
|
||||
if reader.eof() {
|
||||
return Ok(output);
|
||||
}
|
||||
section = reader.read()?;
|
||||
}
|
||||
|
||||
if let SectionCode::Import = section.code {
|
||||
let imports = section.get_import_section_reader()?;
|
||||
translate_sections::import(imports)?;
|
||||
|
||||
reader.skip_custom_sections()?;
|
||||
if reader.eof() {
|
||||
return Ok(output);
|
||||
}
|
||||
section = reader.read()?;
|
||||
}
|
||||
|
||||
if let SectionCode::Function = section.code {
|
||||
let functions = section.get_function_section_reader()?;
|
||||
output.ctx.func_ty_indices = translate_sections::function(functions)?;
|
||||
|
||||
reader.skip_custom_sections()?;
|
||||
if reader.eof() {
|
||||
return Ok(output);
|
||||
}
|
||||
section = reader.read()?;
|
||||
}
|
||||
|
||||
if let SectionCode::Table = section.code {
|
||||
let tables = section.get_table_section_reader()?;
|
||||
translate_sections::table(tables)?;
|
||||
|
||||
reader.skip_custom_sections()?;
|
||||
if reader.eof() {
|
||||
return Ok(output);
|
||||
}
|
||||
section = reader.read()?;
|
||||
}
|
||||
|
||||
if let SectionCode::Memory = section.code {
|
||||
let memories = section.get_memory_section_reader()?;
|
||||
let mem = translate_sections::memory(memories)?;
|
||||
|
||||
if mem.len() > 1 {
|
||||
return Err(Error::Input(
|
||||
"Multiple memory sections not yet implemented".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
if !mem.is_empty() {
|
||||
let mem = mem[0];
|
||||
if Some(mem.limits.initial) != mem.limits.maximum {
|
||||
return Err(Error::Input(
|
||||
"Custom memory limits not supported in lightbeam".to_string(),
|
||||
));
|
||||
for payload in Parser::new(0).parse_all(data) {
|
||||
match payload? {
|
||||
Payload::TypeSection(s) => output.ctx.types = translate_sections::type_(s)?,
|
||||
Payload::ImportSection(s) => translate_sections::import(s)?,
|
||||
Payload::FunctionSection(s) => {
|
||||
output.ctx.func_ty_indices = translate_sections::function(s)?;
|
||||
}
|
||||
output.memory = Some(mem);
|
||||
Payload::TableSection(s) => {
|
||||
translate_sections::table(s)?;
|
||||
}
|
||||
Payload::MemorySection(s) => {
|
||||
let mem = translate_sections::memory(s)?;
|
||||
|
||||
if mem.len() > 1 {
|
||||
return Err(Error::Input(
|
||||
"Multiple memory sections not yet implemented".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
if !mem.is_empty() {
|
||||
let mem = mem[0];
|
||||
if Some(mem.limits.initial) != mem.limits.maximum {
|
||||
return Err(Error::Input(
|
||||
"Custom memory limits not supported in lightbeam".to_string(),
|
||||
));
|
||||
}
|
||||
output.memory = Some(mem);
|
||||
}
|
||||
}
|
||||
Payload::GlobalSection(s) => {
|
||||
translate_sections::global(s)?;
|
||||
}
|
||||
Payload::ExportSection(s) => {
|
||||
translate_sections::export(s)?;
|
||||
}
|
||||
Payload::StartSection { func, .. } => {
|
||||
translate_sections::start(func)?;
|
||||
}
|
||||
Payload::ElementSection(s) => {
|
||||
translate_sections::element(s)?;
|
||||
}
|
||||
Payload::DataSection(s) => {
|
||||
translate_sections::data(s)?;
|
||||
}
|
||||
Payload::CodeSectionStart { .. }
|
||||
| Payload::CustomSection { .. }
|
||||
| Payload::Version { .. } => {}
|
||||
|
||||
other => unimplemented!("can't translate {:?}", other),
|
||||
}
|
||||
|
||||
reader.skip_custom_sections()?;
|
||||
if reader.eof() {
|
||||
return Ok(output);
|
||||
}
|
||||
section = reader.read()?;
|
||||
}
|
||||
|
||||
if let SectionCode::Global = section.code {
|
||||
let globals = section.get_global_section_reader()?;
|
||||
translate_sections::global(globals)?;
|
||||
|
||||
reader.skip_custom_sections()?;
|
||||
if reader.eof() {
|
||||
return Ok(output);
|
||||
}
|
||||
section = reader.read()?;
|
||||
}
|
||||
|
||||
if let SectionCode::Export = section.code {
|
||||
let exports = section.get_export_section_reader()?;
|
||||
translate_sections::export(exports)?;
|
||||
|
||||
reader.skip_custom_sections()?;
|
||||
if reader.eof() {
|
||||
return Ok(output);
|
||||
}
|
||||
section = reader.read()?;
|
||||
}
|
||||
|
||||
if let SectionCode::Start = section.code {
|
||||
let start = section.get_start_section_content()?;
|
||||
translate_sections::start(start)?;
|
||||
|
||||
reader.skip_custom_sections()?;
|
||||
if reader.eof() {
|
||||
return Ok(output);
|
||||
}
|
||||
section = reader.read()?;
|
||||
}
|
||||
|
||||
if let SectionCode::Element = section.code {
|
||||
let elements = section.get_element_section_reader()?;
|
||||
translate_sections::element(elements)?;
|
||||
|
||||
reader.skip_custom_sections()?;
|
||||
if reader.eof() {
|
||||
return Ok(output);
|
||||
}
|
||||
section = reader.read()?;
|
||||
}
|
||||
|
||||
if let SectionCode::Code = section.code {
|
||||
let code = section.get_code_section_reader()?;
|
||||
output.translated_code_section = Some(translate_sections::code(code, &output.ctx)?);
|
||||
|
||||
reader.skip_custom_sections()?;
|
||||
if reader.eof() {
|
||||
return Ok(output);
|
||||
}
|
||||
section = reader.read()?;
|
||||
}
|
||||
|
||||
if let SectionCode::Data = section.code {
|
||||
let data = section.get_data_section_reader()?;
|
||||
translate_sections::data(data)?;
|
||||
}
|
||||
|
||||
if !reader.eof() {
|
||||
return Err(Error::Input(
|
||||
"Unexpected data found after the end of the module".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(output)
|
||||
|
||||
@@ -108,6 +108,7 @@ impl binemit::RelocSink for UnimplementedRelocSink {
|
||||
}
|
||||
|
||||
/// Parses the Code section of the wasm module.
|
||||
#[allow(dead_code)]
|
||||
pub fn code(
|
||||
_code: CodeSectionReader,
|
||||
_translation_ctx: &SimpleContext,
|
||||
|
||||
Reference in New Issue
Block a user