forked from kozorizki/binaryen
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.
52 lines
1.8 KiB
Python
Executable File
52 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright 2022 WebAssembly Community Group participants
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
"""A test case update script for lit help checks.
|
|
"""
|
|
|
|
import os
|
|
import subprocess
|
|
|
|
import test.shared as shared
|
|
|
|
script_dir = os.path.dirname(__file__)
|
|
root_dir = os.path.dirname(script_dir)
|
|
test_dir = os.path.join(root_dir, 'test', 'lit', 'help')
|
|
|
|
TOOLS = ['wasm-opt', 'wasm-as', 'wasm-dis', 'wasm2js', 'wasm-ctor-eval',
|
|
'wasm-shell', 'wasm-reduce', 'wasm-metadce', 'wasm-split',
|
|
'wasm-fuzz-types', 'wasm-emscripten-finalize', 'wasm-merge']
|
|
|
|
|
|
def main():
|
|
for tool in TOOLS:
|
|
tool_path = os.path.join(shared.options.binaryen_bin, tool)
|
|
command = [tool_path, '--help']
|
|
print(command)
|
|
output = subprocess.check_output(command).decode('utf-8')
|
|
with open(os.path.join(test_dir, tool + '.test'), 'w') as out:
|
|
out.write(f';; RUN: {tool} --help | filecheck %s' + os.linesep)
|
|
first = True
|
|
for line in output.splitlines():
|
|
if first:
|
|
out.write(f';; CHECK: {line}'.strip() + os.linesep)
|
|
first = False
|
|
else:
|
|
out.write(f';; CHECK-NEXT: {line}'.strip() + os.linesep)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|