From 5dd60420d572b0ef9461dd9ee4597cebe6d42226 Mon Sep 17 00:00:00 2001 From: Simon Popugaev Date: Mon, 15 Apr 2024 14:08:06 +0300 Subject: [PATCH] wave support --- .gitignore | 2 + Cargo.lock | 868 +++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 8 +- src/lib.rs | 6 + src/wave/mod.rs | 189 +++++++++++ 5 files changed, 1066 insertions(+), 7 deletions(-) create mode 100644 src/wave/mod.rs diff --git a/.gitignore b/.gitignore index e69de29..d81f12e 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +/.idea diff --git a/Cargo.lock b/Cargo.lock index 5deb9db..950e8d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,18 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "ansi_term" version = "0.12.1" @@ -17,12 +29,57 @@ version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +[[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.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "colored-diff" version = "0.2.3" @@ -34,6 +91,124 @@ dependencies = [ "itertools", ] +[[package]] +name = "cranelift-bforest" +version = "0.104.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b85034ffd0efe2f8c0ba73a55a021cd936e3f8526fa24adb50f168874a6b1db7" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.104.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6fc9bfd532123a1778ad154c03741c99028e983c3c053cd6a5d177cab3965e" +dependencies = [ + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-control", + "cranelift-entity", + "cranelift-isle", + "gimli", + "hashbrown 0.14.3", + "log", + "regalloc2", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.104.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea93c920184d2d79555c0dde829717180902f69b9983e30b121bbd88288c5e2f" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.104.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca5378154333193d6eb859514e0062c0c044f98acf8ff067d43aaaaa4e098ce6" + +[[package]] +name = "cranelift-control" +version = "0.104.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d95f6f71863046b42c2e960b1156c86bae2b13842be90349103959a0db9a3c30" +dependencies = [ + "arbitrary", +] + +[[package]] +name = "cranelift-entity" +version = "0.104.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18e625456002617a44c8fbdf276b624639f75e6d11b83c62e64ab8659e352dd5" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "cranelift-frontend" +version = "0.104.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c74dde8da13ac38556bafb9c26c2842ec68964cfbe0d07ae40ef879bab7cbbba" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.104.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5683957e3c8fe5da47d0f23f185b86fb9826b2a10767a7df4ca1fb1dedf16e5e" + +[[package]] +name = "cranelift-native" +version = "0.104.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b90167a436f69c210a68a8244c4078b918f9f01339c3c8a7322e72e5b3632a8" +dependencies = [ + "cranelift-codegen", + "libc", + "target-lexicon", +] + +[[package]] +name = "cranelift-wasm" +version = "0.104.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "073fa9fbb4c28804245b9daaa74975d712082deab0deebea1d92c3d43593cc91" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "itertools", + "log", + "smallvec", + "wasmparser 0.118.2", + "wasmtime-types", +] + +[[package]] +name = "crc32fast" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +dependencies = [ + "cfg-if", +] + [[package]] name = "diff" version = "0.1.13" @@ -52,12 +227,54 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "encoding_rs" +version = "0.8.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +dependencies = [ + "cfg-if", +] + [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +dependencies = [ + "fallible-iterator", + "indexmap", + "stable_deref_trait", +] + [[package]] name = "golem-wasm-ast" version = "0.0.0" @@ -66,17 +283,42 @@ dependencies = [ "leb128", "mappable-rc", "pretty_assertions", - "wasm-encoder", + "wasm-encoder 0.41.2", "wasm-metadata", - "wasmparser", + "wasm-wave", + "wasmparser 0.121.2", "wasmprinter", ] +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash", +] + [[package]] name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" [[package]] name = "indexmap" @@ -85,7 +327,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.3", "serde", ] @@ -110,12 +352,119 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "logos" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c000ca4d908ff18ac99b93a062cb8958d331c3220719c52e77cb19cc6ac5d2c1" +dependencies = [ + "logos-derive", +] + +[[package]] +name = "logos-codegen" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc487311295e0002e452025d6b580b77bb17286de87b57138f3b5db711cded68" +dependencies = [ + "beef", + "fnv", + "proc-macro2", + "quote", + "regex-syntax", + "syn", +] + +[[package]] +name = "logos-derive" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbfc0d229f1f42d790440136d941afd806bc9e949e2bcb8faa813b0f00d1267e" +dependencies = [ + "logos-codegen", +] + +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + [[package]] name = "mappable-rc" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "204651f31b0a6a7b2128d2b92c372cd94607b210c3a6b6e542c57a8cfd4db996" +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "crc32fast", + "hashbrown 0.14.3", + "indexmap", + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + [[package]] name = "pretty_assertions" version = "1.4.0" @@ -135,6 +484,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "psm" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" +dependencies = [ + "cc", +] + [[package]] name = "quote" version = "1.0.35" @@ -144,6 +502,44 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regalloc2" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad156d539c879b7a24a363a2016d77961786e71f48f2e2fc8302a92abd2429a6" +dependencies = [ + "hashbrown 0.13.2", + "log", + "rustc-hash", + "slice-group-by", + "smallvec", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustix" +version = "0.38.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.16" @@ -187,6 +583,12 @@ dependencies = [ "serde", ] +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + [[package]] name = "smallvec" version = "1.13.1" @@ -202,6 +604,18 @@ dependencies = [ "smallvec", ] +[[package]] +name = "sptr" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "syn" version = "2.0.48" @@ -213,12 +627,59 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "target-lexicon" +version = "0.12.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasm-encoder" +version = "0.38.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad2b51884de9c7f4fe2fd1043fccb8dcad4b1e29558146ee57a144d15779f3f" +dependencies = [ + "leb128", +] + [[package]] name = "wasm-encoder" version = "0.41.2" @@ -240,8 +701,31 @@ dependencies = [ "serde_derive", "serde_json", "spdx", - "wasm-encoder", - "wasmparser", + "wasm-encoder 0.41.2", + "wasmparser 0.121.2", +] + +[[package]] +name = "wasm-wave" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "132211e87e40f5470a159f6f44aa87c37f0e24321c42cb1d957d18de1ff576cd" +dependencies = [ + "indexmap", + "logos", + "thiserror", + "wasmtime", + "wit-parser", +] + +[[package]] +name = "wasmparser" +version = "0.118.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77f1154f1ab868e2a01d9834a805faca7bf8b50d041b4ca714d005d0dab1c50c" +dependencies = [ + "indexmap", + "semver", ] [[package]] @@ -262,9 +746,255 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60e73986a6b7fdfedb7c5bf9e7eb71135486507c8fbc4c0c42cffcb6532988b7" dependencies = [ "anyhow", - "wasmparser", + "wasmparser 0.121.2", +] + +[[package]] +name = "wasmtime" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2788dbd0a2f9786cfae5590d2ca6103c82e0fd6ce0b192107e472bcf367ec180" +dependencies = [ + "anyhow", + "bincode", + "bumpalo", + "cfg-if", + "encoding_rs", + "indexmap", + "libc", + "log", + "object", + "once_cell", + "paste", + "serde", + "serde_derive", + "serde_json", + "target-lexicon", + "wasmparser 0.118.2", + "wasmtime-component-macro", + "wasmtime-component-util", + "wasmtime-cranelift", + "wasmtime-environ", + "wasmtime-jit", + "wasmtime-runtime", + "wasmtime-winch", + "windows-sys", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced200bb566dd3e3b044bafc837f978233a6f220f627e29605b4b35c222817fd" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-component-macro" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7f911378d94bfed1360d971f084aa73840d0ea26fc892ed4be0b7da278dc15" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn", + "wasmtime-component-util", + "wasmtime-wit-bindgen", + "wit-parser", ] +[[package]] +name = "wasmtime-component-util" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05ad8115f66c9f061c79e5d45a26288229749e013630aa32596750ef0f9e9807" + +[[package]] +name = "wasmtime-cranelift" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac4bed315d4299d46db5217509f7a7d6e0313c8c8d06cf76cb4cf0a8ce0fa3ee" +dependencies = [ + "anyhow", + "cfg-if", + "cranelift-codegen", + "cranelift-control", + "cranelift-entity", + "cranelift-frontend", + "cranelift-native", + "cranelift-wasm", + "gimli", + "log", + "object", + "target-lexicon", + "thiserror", + "wasmparser 0.118.2", + "wasmtime-cranelift-shared", + "wasmtime-environ", + "wasmtime-versioned-export-macros", +] + +[[package]] +name = "wasmtime-cranelift-shared" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "473a4abcf1df827f85e150b970c95e2c6c52f5b2fbb967b730eb1d52aac24dfb" +dependencies = [ + "anyhow", + "cranelift-codegen", + "cranelift-control", + "cranelift-native", + "gimli", + "object", + "target-lexicon", + "wasmtime-environ", +] + +[[package]] +name = "wasmtime-environ" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eacc3e408248e0eb4da5daa60a0948f91432124b494b887557fcafd04fe1f5c" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli", + "indexmap", + "log", + "object", + "serde", + "serde_derive", + "target-lexicon", + "thiserror", + "wasm-encoder 0.38.1", + "wasmparser 0.118.2", + "wasmprinter", + "wasmtime-component-util", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167290150d5ed13918ca400bc7e0b9ebb915a1066fb61dd7c1d079e0b22b28c0" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "gimli", + "log", + "object", + "rustix", + "serde", + "serde_derive", + "target-lexicon", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-runtime", + "windows-sys", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58b8bf27c96c254626746b8f1893819e19d0cd4182041377c783ae62e624d821" +dependencies = [ + "cfg-if", + "libc", + "windows-sys", +] + +[[package]] +name = "wasmtime-runtime" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6248d4e41dad5da93c3e7b88878ca98cae3a07397fe19adc23a9a506db007ed" +dependencies = [ + "anyhow", + "cc", + "cfg-if", + "encoding_rs", + "indexmap", + "libc", + "log", + "mach", + "memfd", + "memoffset", + "paste", + "psm", + "rustix", + "sptr", + "wasm-encoder 0.38.1", + "wasmtime-asm-macros", + "wasmtime-environ", + "wasmtime-versioned-export-macros", + "wasmtime-wmemcheck", + "windows-sys", +] + +[[package]] +name = "wasmtime-types" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c47002670e3d0dbfab240a672b8f6890493a9f9a3cd19fa5006fd5e5ede3b0f6" +dependencies = [ + "cranelift-entity", + "serde", + "serde_derive", + "thiserror", + "wasmparser 0.118.2", +] + +[[package]] +name = "wasmtime-versioned-export-macros" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e04682ce587aa8fa9311d3c95148381f08a1db274ad6bcd3553f7c97c8c2debb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "wasmtime-winch" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d752d7e08654b106f299e1900fe9ef9fa400138d1e1c7adf848b8fb4f31c5466" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "object", + "target-lexicon", + "wasmparser 0.118.2", + "wasmtime-cranelift-shared", + "wasmtime-environ", + "winch-codegen", +] + +[[package]] +name = "wasmtime-wit-bindgen" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af5fbb1adaadad70271fe18a3f938741edb2b5178bf2fc164ab20544018626b8" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wit-parser", +] + +[[package]] +name = "wasmtime-wmemcheck" +version = "17.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8425f923a58d18de2912d569c59bfa94bbd789074a459d018c62531d5111037c" + [[package]] name = "winapi" version = "0.3.9" @@ -287,8 +1017,134 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "winch-codegen" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1744366f80ea8121569f5e9c403beaebabcbfc089a6a3634c048019f8ef425f0" +dependencies = [ + "anyhow", + "cranelift-codegen", + "gimli", + "regalloc2", + "smallvec", + "target-lexicon", + "wasmparser 0.118.2", + "wasmtime-environ", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + +[[package]] +name = "wit-parser" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "316b36a9f0005f5aa4b03c39bc3728d045df136f8c13a73b7db4510dec725e08" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", +] + [[package]] name = "yansi" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index c5d5f07..dad2825 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ wasmparser = { version = "0.121.2", optional = true } wasm-encoder = { version = "0.41.2", optional = true } wasm-metadata = { version = "0.10.20", optional = true } leb128 = { version = "0.2.5", optional = true } +wasm-wave = { version = "=0.4.0", optional = true } [dev-dependencies] colored-diff = "0.2.3" @@ -19,7 +20,7 @@ pretty_assertions = "1.4.0" wasmprinter = "0.2.80" [features] -default = ["parser", "writer", "component", "metadata", "analysis"] +default = ["parser", "writer", "component", "metadata", "analysis", "wave"] # Support building up the WASM AST by parsing a binary WASM module or component using the wasmparser library parser = ["dep:wasmparser", "dep:leb128"] @@ -36,5 +37,10 @@ metadata = ["dep:wasm-metadata"] # Enables some higher level analysis features built on top of the WASM AST analysis = ["component"] +# Wave format representation +wave = ["dep:wasm-wave"] + + + [lib] path = "src/lib.rs" diff --git a/src/lib.rs b/src/lib.rs index 2f9d8e5..dbc3fea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,6 +65,12 @@ mod customization; #[cfg(feature = "metadata")] pub mod metadata; +/// Wave format support for types. +/// +/// This module is optional and can be enabled with the `metadata` feature flag. It is enabled by default. +#[cfg(feature = "wave")] +pub mod wave; + pub use customization::*; /// An index space defines one of the possible indexes various WASM nodes can belong to. diff --git a/src/wave/mod.rs b/src/wave/mod.rs new file mode 100644 index 0000000..757b9a2 --- /dev/null +++ b/src/wave/mod.rs @@ -0,0 +1,189 @@ +use crate::analysis::{AnalysedFunction, AnalysedType}; +use std::borrow::Cow; +use std::fmt::Display; +use wasm_wave::wasm::{DisplayType, WasmFunc, WasmType, WasmTypeKind}; + +impl WasmType for AnalysedType { + fn kind(&self) -> WasmTypeKind { + match self { + AnalysedType::Bool => WasmTypeKind::Bool, + AnalysedType::S8 => WasmTypeKind::S8, + AnalysedType::U8 => WasmTypeKind::U8, + AnalysedType::S16 => WasmTypeKind::S16, + AnalysedType::U16 => WasmTypeKind::U16, + AnalysedType::S32 => WasmTypeKind::S32, + AnalysedType::U32 => WasmTypeKind::U32, + AnalysedType::S64 => WasmTypeKind::S64, + AnalysedType::U64 => WasmTypeKind::U64, + AnalysedType::F32 => WasmTypeKind::Float32, + AnalysedType::F64 => WasmTypeKind::Float64, + AnalysedType::Chr => WasmTypeKind::Char, + AnalysedType::Str => WasmTypeKind::String, + AnalysedType::List(_) => WasmTypeKind::List, + AnalysedType::Tuple(_) => WasmTypeKind::Tuple, + AnalysedType::Record(_) => WasmTypeKind::Record, + AnalysedType::Flags(_) => WasmTypeKind::Flags, + AnalysedType::Enum(_) => WasmTypeKind::Enum, + AnalysedType::Option(_) => WasmTypeKind::Option, + AnalysedType::Result { .. } => WasmTypeKind::Result, + AnalysedType::Variant(_) => WasmTypeKind::Variant, + AnalysedType::Resource { .. } => WasmTypeKind::Unsupported, + } + } + + fn list_element_type(&self) -> Option { + if let AnalysedType::List(ty) = self { + Some(*ty.clone()) + } else { + None + } + } + + fn record_fields(&self) -> Box, Self)> + '_> { + if let AnalysedType::Record(fields) = self { + Box::new( + fields + .iter() + .map(|(name, ty)| (Cow::Borrowed(name.as_str()), ty.clone())), + ) + } else { + Box::new(std::iter::empty()) + } + } + + fn tuple_element_types(&self) -> Box + '_> { + if let AnalysedType::Tuple(types) = self { + Box::new(types.clone().into_iter()) + } else { + Box::new(std::iter::empty()) + } + } + + fn variant_cases(&self) -> Box, Option)> + '_> { + if let AnalysedType::Variant(cases) = self { + Box::new( + cases + .iter() + .map(|(name, ty)| (Cow::Borrowed(name.as_str()), ty.clone())), + ) + } else { + Box::new(std::iter::empty()) + } + } + + fn enum_cases(&self) -> Box> + '_> { + if let AnalysedType::Enum(cases) = self { + Box::new(cases.iter().map(|name| Cow::Borrowed(name.as_str()))) + } else { + Box::new(std::iter::empty()) + } + } + + fn option_some_type(&self) -> Option { + if let AnalysedType::Option(ty) = self { + Some(*ty.clone()) + } else { + None + } + } + + fn result_types(&self) -> Option<(Option, Option)> { + if let AnalysedType::Result { ok, error } = self { + Some(( + ok.as_ref().map(|t| *t.clone()), + error.as_ref().map(|t| *t.clone()), + )) + } else { + None + } + } + + fn flags_names(&self) -> Box> + '_> { + if let AnalysedType::Flags(names) = self { + Box::new(names.iter().map(|name| Cow::Borrowed(name.as_str()))) + } else { + Box::new(std::iter::empty()) + } + } +} + +impl WasmFunc for AnalysedFunction { + type Type = AnalysedType; + + fn params(&self) -> Box + '_> { + Box::new(self.params.iter().map(|p| p.typ.clone())) + } + + fn param_names(&self) -> Box> + '_> { + Box::new(self.params.iter().map(|p| Cow::Borrowed(p.name.as_str()))) + } + + fn results(&self) -> Box + '_> { + Box::new(self.results.iter().map(|r| r.typ.clone())) + } + + fn result_names(&self) -> Box> + '_> { + let names: Option>> = self + .results + .iter() + .map(|r| r.name.as_ref().map(|n| Cow::Borrowed(n.as_str()))) + .collect(); + + match names { + Some(names) => Box::new(names.into_iter()), + None => Box::new(std::iter::empty()), + } + } +} + +/// Copy of DisplayFunc with additional name filed. +/// DisplayFunc is always using func for name +pub struct DisplayNamedFunc { + pub name: String, + pub func: T, +} + +impl Display for DisplayNamedFunc { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(&self.name)?; + f.write_str("(")?; + let mut param_names = self.func.param_names(); + for (idx, ty) in self.func.params().enumerate() { + if idx != 0 { + f.write_str(", ")?; + } + if let Some(name) = param_names.next() { + write!(f, "{name}: ")?; + } + DisplayType(&ty).fmt(f)? + } + f.write_str(")")?; + + let results = self.func.results().collect::>(); + if results.is_empty() { + return Ok(()); + } + + let mut result_names = self.func.result_names(); + if results.len() == 1 { + let ty = DisplayType(&results.into_iter().next().unwrap()).to_string(); + if let Some(name) = result_names.next() { + write!(f, " -> ({name}: {ty})") + } else { + write!(f, " -> {ty}") + } + } else { + f.write_str(" -> (")?; + for (idx, ty) in results.into_iter().enumerate() { + if idx != 0 { + f.write_str(", ")?; + } + if let Some(name) = result_names.next() { + write!(f, "{name}: ")?; + } + DisplayType(&ty).fmt(f)?; + } + f.write_str(")") + } + } +}