diff --git a/codegen/luajit/Cargo.toml b/codegen/luajit/Cargo.toml index 22c2b62..2f5396e 100644 --- a/codegen/luajit/Cargo.toml +++ b/codegen/luajit/Cargo.toml @@ -4,7 +4,7 @@ version = "0.12.0" edition = "2021" [dependencies] -wasmparser = "0.99.0" +wasmparser = "0.107.0" [dependencies.wasm-ast] path = "../../wasm-ast" diff --git a/codegen/luajit/src/translator.rs b/codegen/luajit/src/translator.rs index 496f42a..327f3a4 100644 --- a/codegen/luajit/src/translator.rs +++ b/codegen/luajit/src/translator.rs @@ -107,8 +107,8 @@ fn write_table_list(wasm: &Module, w: &mut dyn Write) -> Result<()> { for (i, table) in table.iter().enumerate() { let index = offset + i; - let min = table.initial; - let max = table.maximum.unwrap_or(0xFFFF); + let min = table.ty.initial; + let max = table.ty.maximum.unwrap_or(0xFFFF); writeln!( w, @@ -155,6 +155,8 @@ fn write_element_list(list: &[Element], type_info: &TypeInfo, w: &mut dyn Write) unimplemented!("passive elements not supported") }; + let index = index.unwrap_or(0); + writeln!(w, "\tdo")?; writeln!(w, "\t\tlocal target = TABLE_LIST[{index}].data")?; write!(w, "\t\tlocal offset = ")?; diff --git a/codegen/luau/Cargo.toml b/codegen/luau/Cargo.toml index a6679bf..9295065 100644 --- a/codegen/luau/Cargo.toml +++ b/codegen/luau/Cargo.toml @@ -4,7 +4,7 @@ version = "0.12.0" edition = "2021" [dependencies] -wasmparser = "0.99.0" +wasmparser = "0.107.0" [dependencies.wasm-ast] path = "../../wasm-ast" diff --git a/codegen/luau/src/translator.rs b/codegen/luau/src/translator.rs index 7dbb21c..2174b4d 100644 --- a/codegen/luau/src/translator.rs +++ b/codegen/luau/src/translator.rs @@ -107,8 +107,8 @@ fn write_table_list(wasm: &Module, w: &mut dyn Write) -> Result<()> { for (i, table) in table.iter().enumerate() { let index = offset + i; - let min = table.initial; - let max = table.maximum.unwrap_or(0xFFFF); + let min = table.ty.initial; + let max = table.ty.maximum.unwrap_or(0xFFFF); writeln!( w, @@ -155,6 +155,8 @@ fn write_element_list(list: &[Element], type_info: &TypeInfo, w: &mut dyn Write) unimplemented!("passive elements not supported") }; + let index = index.unwrap_or(0); + writeln!(w, "\tdo")?; writeln!(w, "\t\tlocal target = TABLE_LIST[{index}].data")?; write!(w, "\t\tlocal offset = ")?; @@ -243,9 +245,7 @@ fn write_localize_used( .iter() .any(|g| g.ty.content_type == ValType::I64); - let has_element_i64 = wasm.element_section().iter().any(|e| e.ty == ValType::I64); - - if has_global_i64 || has_element_i64 { + if has_global_i64 { loc_set.insert(("i64", "ZERO")); loc_set.insert(("i64", "ONE")); loc_set.insert(("i64", "from_u32")); diff --git a/dev-test/Cargo.toml b/dev-test/Cargo.toml index d5aa747..7a12085 100644 --- a/dev-test/Cargo.toml +++ b/dev-test/Cargo.toml @@ -8,15 +8,15 @@ publish = false cargo-fuzz = true [dependencies] -libfuzzer-sys = "0.4.0" -wasm-smith = "0.12.0" +libfuzzer-sys = "0.4.6" +wasm-smith = "0.12.10" wasm-ast = { path = "../wasm-ast" } codegen-luajit = { path = "../codegen/luajit" } codegen-luau = { path = "../codegen/luau" } [dev-dependencies] -test-generator = "0.3.0" -wast = "52.0.2" +test-generator = "0.3.1" +wast = "60.0.0" [[bin]] name = "luajit_translate" diff --git a/wasm-ast/Cargo.toml b/wasm-ast/Cargo.toml index 6cc1543..090b986 100644 --- a/wasm-ast/Cargo.toml +++ b/wasm-ast/Cargo.toml @@ -4,4 +4,4 @@ version = "0.12.0" edition = "2021" [dependencies] -wasmparser = "0.99.0" +wasmparser = "0.107.0" diff --git a/wasm-ast/src/module.rs b/wasm-ast/src/module.rs index 48f4933..3d8a19c 100644 --- a/wasm-ast/src/module.rs +++ b/wasm-ast/src/module.rs @@ -2,8 +2,7 @@ use std::collections::HashMap; use wasmparser::{ BlockType, Data, Element, Export, ExternalKind, FunctionBody, Global, Import, LocalsReader, - MemoryType, Name, NameSectionReader, Parser, Payload, Result, TableType, Type, TypeRef, - ValType, + MemoryType, Name, NameSectionReader, Parser, Payload, Result, Table, Type, TypeRef, ValType, }; #[derive(PartialEq, Eq, Clone, Copy)] @@ -58,7 +57,7 @@ pub struct Module<'a> { type_section: Vec, import_section: Vec>, func_section: Vec, - table_section: Vec, + table_section: Vec>, memory_section: Vec, global_section: Vec>, export_section: Vec>, @@ -173,7 +172,7 @@ impl<'a> Module<'a> { } #[must_use] - pub fn table_section(&self) -> &[TableType] { + pub fn table_section(&self) -> &[Table] { &self.table_section } @@ -256,7 +255,9 @@ impl<'a> TypeInfo<'a> { } pub(crate) fn by_type_index(&self, index: usize) -> (usize, usize) { - let Type::Func(ty) = &self.type_list[index]; + let Type::Func(ty) = &self.type_list[index] else { + unreachable!("type at func index must be a func type"); + }; (ty.params().len(), ty.results().len()) }