diff options
author | Alon Zakai <azakai@google.com> | 2023-05-16 11:03:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-16 11:03:45 -0700 |
commit | 972e659bf59740c3ee44129812f95bec143d01a6 (patch) | |
tree | f86d70fa692a45e3dfbf951b0d1af06204d4ecf7 /test/lit/merge/renamings.wat.second | |
parent | 44cd751d9feda7c4b4b6c9d6af1e71541b90abac (diff) | |
download | binaryen-972e659bf59740c3ee44129812f95bec143d01a6.tar.gz binaryen-972e659bf59740c3ee44129812f95bec143d01a6.tar.bz2 binaryen-972e659bf59740c3ee44129812f95bec143d01a6.zip |
Reintroduce wasm-merge (#5709)
We used to have a wasm-merge tool but removed it for a lack of use cases. Recently
use cases have been showing up in the wasm GC space and elsewhere, as people are
using more diverse toolchains together, for example a project might build some C++
code alongside some wasm GC code. Merging those wasm files together can allow
for nice optimizations like inlining and better DCE etc., so it makes sense to have a
tool for merging.
Background:
* Removal: #1969
* Requests:
* wasm-merge - why it has been deleted #2174
* Compiling and linking wat files #2276
* wasm-link? #2767
This PR is a compete rewrite of wasm-merge, not a restoration of the original
codebase. The original code was quite messy (my fault), and also, since then
we've added multi-memory and multi-table which makes things a lot simpler.
The linking semantics are as described in the "wasm-link" issue #2767 : all we do
is merge normal wasm files together and connect imports and export. That is, we
have a graph of modules and their names, and each import to a module name can
be resolved to that module. Basically, like a JS bundler would do for JS, or, in other
words, we do the same operations as JS code would do to glue wasm modules
together at runtime, but at compile time. See the README update in this PR for a
concrete example.
There are no plans to do more than that simple bundling, so this should not
really overlap with wasm-ld's use cases.
This should be fairly fast as it works in linear time on the total input code. However,
it won't be as fast as wasm-ld, of course, as it does build Binaryen IR for each
module. An advantage to working on Binaryen IR is that we can easily do some
global DCE after merging, and further optimizations are possible later.
Diffstat (limited to 'test/lit/merge/renamings.wat.second')
-rw-r--r-- | test/lit/merge/renamings.wat.second | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/test/lit/merge/renamings.wat.second b/test/lit/merge/renamings.wat.second new file mode 100644 index 000000000..da02e0438 --- /dev/null +++ b/test/lit/merge/renamings.wat.second @@ -0,0 +1,123 @@ +(module + (type $array (array (mut (ref null func)))) + + (tag $foo (param f32)) + + (tag $other (param f64)) + + (memory $foo 50 60) + + (memory $other 70 80) + + (data $other (i32.const 3) "ghi") + + (data $bar (i32.const 4) "jkl") + + (table $foo 50 60 funcref) + + (table $other 70 80 funcref) + + (elem $other (ref null func) $foo $other) + + (elem $bar (ref null func) $other $foo) + + (global $other i32 (i32.const 3)) + + (global $bar i32 (i32.const 4)) + + (export "foo" (func $foo)) + + (export "other" (func $other)) + + (export "keepalive" (func $uses.second)) + + ;; Also test having a different name for the export as for the internal + ;; thing it refers to, to test we don't assume they are identical. + (export "other-b" (func $other)) + + (func $foo + (drop + (i32.const 3) + ) + ) + + (func $other + (drop + (i32.const 4) + ) + ) + + (func $uses.second (param $array (ref $array)) + ;; Tags. + (try + (do) + (catch $foo + (drop + (pop f32) + ) + ) + ) + (try + (do) + (catch $other + (drop + (pop f64) + ) + ) + ) + + ;; Memories + (drop + (i32.load $foo + (i32.const 3) + ) + ) + (drop + (i32.load $other + (i32.const 4) + ) + ) + + ;; Data segments + (data.drop $other) + (data.drop $bar) + + ;; Tables + (drop + (table.get $foo + (i32.const 3) + ) + ) + (drop + (table.get $other + (i32.const 4) + ) + ) + + ;; Element segments + (array.init_elem $array $other + (local.get $array) + (i32.const 7) + (i32.const 8) + (i32.const 9) + ) + (array.init_elem $array $bar + (local.get $array) + (i32.const 10) + (i32.const 11) + (i32.const 12) + ) + + ;; Globals + (drop + (global.get $other) + ) + (drop + (global.get $bar) + ) + + ;; Functions. + (call $foo) + (call $other) + ) +) |