diff --git a/.gitmodules b/.gitmodules index 47afbeb..ed714f0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "tests/spec"] - path = tests/spec - url = https://github.com/WebAssembly/spec.git +[submodule "tests/testsuite"] + path = tests/testsuite + url = git@github.com:WebAssembly/testsuite.git diff --git a/Cargo.lock b/Cargo.lock index 68f215b..4385552 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,6 +83,12 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "cc" version = "1.0.79" @@ -135,15 +141,6 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" -[[package]] -name = "cmake" -version = "0.1.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" -dependencies = [ - "cc", -] - [[package]] name = "colorchoice" version = "1.0.0" @@ -188,12 +185,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "glob" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" - [[package]] name = "hashbrown" version = "0.12.3" @@ -274,12 +265,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - [[package]] name = "lazy_static" version = "1.4.0" @@ -437,12 +422,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - [[package]] name = "scopeguard" version = "1.2.0" @@ -455,34 +434,6 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" -[[package]] -name = "serde" -version = "1.0.164" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" - -[[package]] -name = "serde_derive" -version = "1.0.164" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.49", -] - -[[package]] -name = "serde_json" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" -dependencies = [ - "itoa", - "ryu", - "serde", -] - [[package]] name = "smallvec" version = "1.13.1" @@ -585,29 +536,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" -[[package]] -name = "wabt" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b5f5d6984ca42df66280baa8a15ac188a173ddaf4580b574a98931c01920e7" -dependencies = [ - "serde", - "serde_derive", - "serde_json", - "wabt-sys", -] - -[[package]] -name = "wabt-sys" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b064c81821100adb4b71923cecfc67fef083db21c3bbd454b0162c7ffe63eeaa" -dependencies = [ - "cc", - "cmake", - "glob", -] - [[package]] name = "wasker" version = "0.1.0" @@ -618,8 +546,8 @@ dependencies = [ "inkwell", "log", "pretty-hex", - "wabt", "wasmparser", + "wast 70.0.2", "wat", ] @@ -632,6 +560,15 @@ dependencies = [ "leb128", ] +[[package]] +name = "wasm-encoder" +version = "0.41.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "972f97a5d8318f908dded23594188a90bcd09365986b1163e66d70170e5287ae" +dependencies = [ + "leb128", +] + [[package]] name = "wasmparser" version = "0.102.0" @@ -651,7 +588,20 @@ dependencies = [ "leb128", "memchr", "unicode-width", - "wasm-encoder", + "wasm-encoder 0.32.0", +] + +[[package]] +name = "wast" +version = "70.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3d5061300042ff5065123dae1e27d00c03f567d34a2937c8472255148a216dc" +dependencies = [ + "bumpalo", + "leb128", + "memchr", + "unicode-width", + "wasm-encoder 0.41.2", ] [[package]] @@ -660,7 +610,7 @@ version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53253d920ab413fca1c7dc2161d601c79b4fdf631d0ba51dd4343bf9b556c3f6" dependencies = [ - "wast", + "wast 64.0.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index ff10090..132d96c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,5 @@ wasmparser = "0.102.0" clap = { version = "4.4.3", features = ["derive"]} log = "0.4.20" env_logger = "0.10.0" -wabt = "0.9.0" pretty-hex = "0.3.0" +wast = "70.0.2" diff --git a/tests/spec b/tests/spec deleted file mode 160000 index 724b3e7..0000000 --- a/tests/spec +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 724b3e7fc8338ef7b4acbbf5d834b4948f030bf5 diff --git a/tests/spec.rs b/tests/spec.rs index f41ddd2..087b434 100644 --- a/tests/spec.rs +++ b/tests/spec.rs @@ -1,50 +1,86 @@ use std::io::Read; use std::{fs::File, io::Write}; -use wabt::script::{Command, CommandKind, ScriptParser}; -use wasker::compiler; +use wasker::compiler::{self, compile_wasm}; +use wast::{ + core::{HeapType, NanPattern, WastRetCore}, + lexer::Lexer, + parser::ParseBuffer, + token::Span, + QuoteWat, + Wast, + WastDirective, + WastExecute, + WastInvoke, + WastRet, + Wat, +}; -fn _run_spec_test(testname: &str) { - let path = "./tests/spec/test/core"; +fn run_spec_test(testname: &str) { + let path = "./tests/testsuite"; - // read wast + // Read Wast let mut wat = String::new(); let wat_path = std::path::Path::new(path).join(format!("{}.wast", testname)); println!("open file: {:?}", wat_path); let mut file = std::fs::File::open(wat_path).expect("error open file"); file.read_to_string(&mut wat).expect("cannot read file"); - // parse - let mut parser = ScriptParser::::from_str(&wat).expect("error get parser"); - while let Some(Command { kind, .. }) = parser.next().expect("cannot parse next") { - match kind { - CommandKind::Module { module, name } => { - // Convert the module into the binary representation and check the magic number. - let module_binary = module.into_vec(); - assert_eq!(&module_binary[0..4], &[0, 97, 115, 109]); + // Parse Wast + let mut lexer = Lexer::new(&wat); + lexer.allow_confusing_unicode(true); + let parse_buffer = match ParseBuffer::new_with_lexer(lexer) { + Ok(buffer) => buffer, + Err(error) => { + panic!( + "failed to create ParseBuffer : {}", + error + ) + } + }; + let wast = match wast::parser::parse::(&parse_buffer) { + Ok(wast) => wast, + Err(error) => { + panic!( + "failed to parse `.wast` spec test file {} for: {}", + testname, + error + ) + } + }; - // Output wasm for debug - let mut file = File::create("tmp.wasm").expect("cannot open file"); - file.write_all(&module_binary) - .expect("fail to write binary"); - file.flush().expect("fail to flush"); + // Execute + for directive in wast.directives { + match directive { + WastDirective::Wat(mut wat) => { + // Get Wasm binary + let wasm = wat.encode().expect("failed to encode wat"); + assert_eq!(wasm[0..4], [0, 97, 115, 109]); - // Compile test - println!("Compile Module {:?}", name); + // Compile with Wasker let args = compiler::Args { - input_file: "tmp.wasm".into(), + input_file: "dummy.wasm".into(), output_file: "/tmp/wasm.o".into(), }; - compiler::compile_wasm(&module_binary, &args).expect("compile failed"); + compile_wasm(&wasm, &args).expect("failed to Wasker compile"); + } + WastDirective::AssertReturn { span:_, exec:_, results:_ } => { + } + WastDirective::AssertInvalid { span:_, module:_, message:_ } => { } - _ => { - // TODO: support assertion + WastDirective::AssertTrap { span:_, exec:_, message:_ } => { + } + WastDirective::AssertMalformed { span:_, module:_, message:_ } => { + } + WastDirective::Invoke(_invoke) => { + } + _other => { } } } } -macro_rules! _spec_test { +macro_rules! spec_test { ($testname:ident, $fname:expr) => { #[test] #[allow(non_snake_case)] @@ -54,6 +90,8 @@ macro_rules! _spec_test { }; } +spec_test!(i64, "i64"); + /* spec_test!(address, "address"); spec_test!(align, "align"); @@ -86,7 +124,6 @@ spec_test!(float_misc, "float_misc"); spec_test!(forward, "forward"); spec_test!(func_ptrs, "func_ptrs"); spec_test!(i32, "i32"); -spec_test!(i64, "i64"); spec_test!(r#if, "if"); spec_test!(inline_module, "inline-module"); spec_test!(int_exprs, "int_exprs"); diff --git a/tests/testsuite b/tests/testsuite new file mode 160000 index 0000000..83f0863 --- /dev/null +++ b/tests/testsuite @@ -0,0 +1 @@ +Subproject commit 83f0863c9f52050590dd47a4647d5c5ef1f2fdf9