diff options
-rw-r--r-- | CMakeLists.txt | 27 | ||||
-rwxr-xr-x | auto_update_tests.py | 32 | ||||
-rwxr-xr-x | check.py | 108 | ||||
-rwxr-xr-x | scripts/support.py | 57 | ||||
-rw-r--r-- | src/tools/wasm-as.cpp | 2 | ||||
-rw-r--r-- | src/tools/wasm-opt.cpp | 105 | ||||
-rw-r--r-- | src/tools/wasm-shell.cpp (renamed from src/tools/binaryen-shell.cpp) | 47 | ||||
m--------- | test/waterfall | 0 |
8 files changed, 233 insertions, 145 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cff081c7..38b2df763 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,16 +109,27 @@ ELSE() ENDIF() TARGET_LINK_LIBRARIES(binaryen asmjs ${all_passes} support) -SET(binaryen-shell_SOURCES - src/tools/binaryen-shell.cpp +SET(wasm-shell_SOURCES + src/tools/wasm-shell.cpp src/wasm.cpp ) -ADD_EXECUTABLE(binaryen-shell - ${binaryen-shell_SOURCES}) -TARGET_LINK_LIBRARIES(binaryen-shell asmjs emscripten-optimizer ${all_passes} support) -SET_PROPERTY(TARGET binaryen-shell PROPERTY CXX_STANDARD 11) -SET_PROPERTY(TARGET binaryen-shell PROPERTY CXX_STANDARD_REQUIRED ON) -INSTALL(TARGETS binaryen-shell DESTINATION bin) +ADD_EXECUTABLE(wasm-shell + ${wasm-shell_SOURCES}) +TARGET_LINK_LIBRARIES(wasm-shell asmjs emscripten-optimizer ${all_passes} support) +SET_PROPERTY(TARGET wasm-shell PROPERTY CXX_STANDARD 11) +SET_PROPERTY(TARGET wasm-shell PROPERTY CXX_STANDARD_REQUIRED ON) +INSTALL(TARGETS wasm-shell DESTINATION bin) + +SET(wasm-opt_SOURCES + src/tools/wasm-opt.cpp + src/wasm.cpp +) +ADD_EXECUTABLE(wasm-opt + ${wasm-opt_SOURCES}) +TARGET_LINK_LIBRARIES(wasm-opt asmjs emscripten-optimizer ${all_passes} support) +SET_PROPERTY(TARGET wasm-opt PROPERTY CXX_STANDARD 11) +SET_PROPERTY(TARGET wasm-opt PROPERTY CXX_STANDARD_REQUIRED ON) +INSTALL(TARGETS wasm-opt DESTINATION bin) SET(asm2wasm_SOURCES src/tools/asm2wasm.cpp diff --git a/auto_update_tests.py b/auto_update_tests.py index 8e33e1517..75396655e 100755 --- a/auto_update_tests.py +++ b/auto_update_tests.py @@ -2,6 +2,8 @@ import os, sys, subprocess, difflib +from scripts.support import run_command, split_wast + print '[ processing and updating testcases... ]\n' for asm in sorted(os.listdir('test')): @@ -19,7 +21,7 @@ for asm in sorted(os.listdir('test')): print '..', asm, wasm print ' ', ' '.join(cmd) actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() - open(os.path.join('test', wasm), 'w').write(actual) + with open(os.path.join('test', wasm), 'w') as o: o.write(actual) for dot_s_dir in ['dot_s', 'llvm_autogenerated']: for s in sorted(os.listdir(os.path.join('test', dot_s_dir))): @@ -35,7 +37,7 @@ for dot_s_dir in ['dot_s', 'llvm_autogenerated']: assert err == '', 'bad err:' + err expected_file = os.path.join('test', dot_s_dir, wasm) - open(expected_file, 'w').write(actual) + with open(expected_file, 'w') as o: o.write(actual) ''' for wasm in ['address.wast']:#os.listdir(os.path.join('test', 'spec')): @@ -54,24 +56,28 @@ for t in sorted(os.listdir(os.path.join('test', 'print'))): if t.endswith('.wast'): print '..', t wasm = os.path.basename(t).replace('.wast', '') - cmd = [os.path.join('bin', 'binaryen-shell'), os.path.join('test', 'print', t), '--print'] + cmd = [os.path.join('bin', 'wasm-shell'), os.path.join('test', 'print', t), '--print'] print ' ', ' '.join(cmd) actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() - open(os.path.join('test', 'print', wasm + '.txt'), 'w').write(actual) - cmd = [os.path.join('bin', 'binaryen-shell'), os.path.join('test', 'print', t), '--print-minified'] + with open(os.path.join('test', 'print', wasm + '.txt'), 'w') as o: o.write(actual) + cmd = [os.path.join('bin', 'wasm-shell'), os.path.join('test', 'print', t), '--print-minified'] print ' ', ' '.join(cmd) actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() - open(os.path.join('test', 'print', wasm + '.minified.txt'), 'w').write(actual) + with open(os.path.join('test', 'print', wasm + '.minified.txt'), 'w') as o: o.write(actual) for t in sorted(os.listdir(os.path.join('test', 'passes'))): if t.endswith('.wast'): print '..', t passname = os.path.basename(t).replace('.wast', '') opts = ['-O'] if passname == 'O' else ['--' + p for p in passname.split('_')] - cmd = [os.path.join('bin', 'binaryen-shell')] + opts + [os.path.join('test', 'passes', t), '--print'] - print ' ', ' '.join(cmd) - actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() - open(os.path.join('test', 'passes', passname + '.txt'), 'w').write(actual) + t = os.path.join('test', 'passes', t) + actual = '' + for module, asserts in split_wast(t): + assert len(asserts) == 0 + with open('split.wast', 'w') as o: o.write(module) + cmd = [os.path.join('bin', 'wasm-opt')] + opts + ['split.wast', '--print'] + actual += run_command(cmd) + with open(os.path.join('test', 'passes', passname + '.txt'), 'w') as o: o.write(actual) print '\n[ checking binary format testcases... ]\n' @@ -89,7 +95,7 @@ for wast in sorted(os.listdir('test')): subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert os.path.exists('a.wast') actual = open('a.wast').read() - open(os.path.join('test', wast + '.fromBinary'), 'w').write(actual) + with open(os.path.join('test', wast + '.fromBinary'), 'w') as o: o.write(actual) print '\n[ checking example testcases... ]\n' @@ -104,7 +110,7 @@ for t in sorted(os.listdir(os.path.join('test', 'example'))): continue print ' (will check trace in ', t, ')' src = 'trace.cpp' - open(src, 'w').write(out) + with open(src, 'w') as o: o.write(out) expected = os.path.join('test', 'example', t + '.txt') else: src = os.path.join('test', 'example', t) @@ -132,7 +138,7 @@ for t in sorted(os.listdir(os.path.join('test', 'example'))): proc = subprocess.Popen([output_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE) actual, err = proc.communicate() assert proc.returncode == 0, [proc.returncode, actual, err] - open(expected, 'w').write(actual) + with open(expected, 'w') as o: o.write(actual) finally: os.remove(output_file) if sys.platform == 'darwin': @@ -17,7 +17,7 @@ import os, shutil, sys, subprocess, difflib, json, time, urllib2 import scripts.storage -import scripts.support +from scripts.support import run_command, split_wast interpreter = None requested = [] @@ -73,7 +73,7 @@ def fetch_waterfall(): os.mkdir(WATERFALL_BUILD_DIR) subprocess.check_call(['tar', '-xf', os.path.abspath(fullname)], cwd=WATERFALL_BUILD_DIR) print '(noting local revision)' - open(os.path.join('test', 'local-revision'), 'w').write(rev) + with open(os.path.join('test', 'local-revision'), 'w') as o: o.write(rev) has_vanilla_llvm = False @@ -155,13 +155,6 @@ def delete_from_orbit(filename): # removes a file if it exists, using any and al except: pass -def run_command(cmd, expected_status=0, stderr=None): - print 'executing: ', ' '.join(cmd) - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=stderr) - out, err = proc.communicate() - if proc.returncode != expected_status: raise Exception(('run_command failed', err)) - return out - def fail(actual, expected): raise Exception("incorrect output, diff:\n\n%s" % ( ''.join([a.rstrip()+'\n' for a in difflib.unified_diff(expected.split('\n'), actual.split('\n'), fromfile='expected', tofile='actual')])[:] @@ -193,50 +186,6 @@ if not has_vanilla_emcc: # check utilities -def split_wast(wast): - # .wast files can contain multiple modules, and assertions for each one. - # this splits out a wast into [(module, assertions), ..] - # we ignore module invalidity tests here. - wast = open(wast).read() - ret = [] - def to_end(j): - depth = 1 - while depth > 0 and j < len(wast): - if wast[j] == '"': - j = wast.find('"', j + 1) - elif wast[j] == '(': - depth += 1 - elif wast[j] == ')': - depth -= 1 - elif wast[j] == ';' and wast[j+1] == ';': - j = wast.find('\n', j) - j += 1 - return j - i = 0 - while i >= 0: - start = wast.find('(', i) - if start >= 0 and wast[start+1] == ';': - # block comment - i = wast.find(';)', start+2) - assert i > 0, wast[start:] - i += 2 - continue - skip = wast.find(';', i) - if skip >= 0 and skip < start and skip + 1 < len(wast): - if wast[skip+1] == ';': - i = wast.find('\n', i) + 1 - continue - if start < 0: break - i = to_end(start + 1) - chunk = wast[start:i] - if chunk.startswith('(module'): - ret += [(chunk, [])] - elif chunk.startswith('(assert_invalid'): - continue - elif chunk.startswith(('(assert', '(invoke')): - ret[-1][1].append(chunk) - return ret - def binary_format_check(wast, verify_final_result=True): # checks we can convert the wast to binary and back @@ -254,7 +203,7 @@ def binary_format_check(wast, verify_final_result=True): assert os.path.exists('ab.wast') # make sure it is a valid wast - cmd = [os.path.join('bin', 'binaryen-shell'), 'ab.wast'] + cmd = [os.path.join('bin', 'wasm-shell'), 'ab.wast'] print ' ', ' '.join(cmd) subprocess.check_call(cmd, stdout=subprocess.PIPE) @@ -270,11 +219,11 @@ def minify_check(wast, verify_final_result=True): # checks we can parse minified output print ' (minify check)' - cmd = [os.path.join('bin', 'binaryen-shell'), wast, '--print-minified'] + cmd = [os.path.join('bin', 'wasm-opt'), wast, '--print-minified'] print ' ', ' '.join(cmd) - subprocess.check_call([os.path.join('bin', 'binaryen-shell'), wast, '--print-minified'], stdout=open('a.wasm', 'w'), stderr=subprocess.PIPE) + subprocess.check_call([os.path.join('bin', 'wasm-opt'), wast, '--print-minified'], stdout=open('a.wasm', 'w'), stderr=subprocess.PIPE) assert os.path.exists('a.wasm') - subprocess.check_call([os.path.join('bin', 'binaryen-shell'), 'a.wasm', '--print-minified'], stdout=open('b.wasm', 'w'), stderr=subprocess.PIPE) + subprocess.check_call([os.path.join('bin', 'wasm-opt'), 'a.wasm', '--print-minified'], stdout=open('b.wasm', 'w'), stderr=subprocess.PIPE) assert os.path.exists('b.wasm') if verify_final_result: expected = open('a.wasm').read() @@ -301,23 +250,28 @@ for e in executables: assert e in err, 'Expected help to contain program name, got:\n%s' % err assert len(err.split('\n')) > 8, 'Expected some help, got:\n%s' % err -print '\n[ checking binaryen-shell -o notation... ]\n' +print '\n[ checking wasm-opt -o notation... ]\n' wast = os.path.join('test', 'hello_world.wast') delete_from_orbit('a.wast') -cmd = [os.path.join('bin', 'binaryen-shell'), wast, '-o', 'a.wast'] +cmd = [os.path.join('bin', 'wasm-opt'), wast, '-o', 'a.wast'] run_command(cmd) fail_if_not_identical(open('a.wast').read(), open(wast).read()) -print '\n[ checking binaryen-shell passes... ]\n' +print '\n[ checking wasm-opt passes... ]\n' for t in sorted(os.listdir(os.path.join('test', 'passes'))): if t.endswith('.wast'): print '..', t passname = os.path.basename(t).replace('.wast', '') opts = ['-O'] if passname == 'O' else ['--' + p for p in passname.split('_')] - cmd = [os.path.join('bin', 'binaryen-shell')] + opts + [os.path.join('test', 'passes', t), '--print'] - actual = run_command(cmd) + t = os.path.join('test', 'passes', t) + actual = '' + for module, asserts in split_wast(t): + assert len(asserts) == 0 + with open('split.wast', 'w') as o: o.write(module) + cmd = [os.path.join('bin', 'wasm-opt')] + opts + ['split.wast', '--print'] + actual += run_command(cmd) fail_if_not_identical(actual, open(os.path.join('test', 'passes', passname + '.txt')).read()) print '[ checking asm2wasm testcases... ]\n' @@ -350,7 +304,7 @@ for asm in tests: # verify in wasm if interpreter: # remove imports, spec interpreter doesn't know what to do with them - subprocess.check_call([os.path.join('bin', 'binaryen-shell'), '--remove-imports', '--print', wasm], stdout=open('ztemp.wast', 'w'), stderr=subprocess.PIPE) + subprocess.check_call([os.path.join('bin', 'wasm-opt'), '--remove-imports', wasm], stdout=open('ztemp.wast', 'w'), stderr=subprocess.PIPE) proc = subprocess.Popen([interpreter, 'ztemp.wast'], stderr=subprocess.PIPE) out, err = proc.communicate() if proc.returncode != 0: @@ -370,28 +324,28 @@ for asm in tests: raise Exception('wasm interpreter error: ' + err) # failed to pretty-print raise Exception('wasm interpreter error') -print '\n[ checking binaryen-shell parsing & printing... ]\n' +print '\n[ checking wasm-opt parsing & printing... ]\n' for t in sorted(os.listdir(os.path.join('test', 'print'))): if t.endswith('.wast'): print '..', t wasm = os.path.basename(t).replace('.wast', '') - cmd = [os.path.join('bin', 'binaryen-shell'), os.path.join('test', 'print', t), '--print'] + cmd = [os.path.join('bin', 'wasm-opt'), os.path.join('test', 'print', t), '--print'] print ' ', ' '.join(cmd) actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() fail_if_not_identical(actual, open(os.path.join('test', 'print', wasm + '.txt')).read()) - cmd = [os.path.join('bin', 'binaryen-shell'), os.path.join('test', 'print', t), '--print-minified'] + cmd = [os.path.join('bin', 'wasm-opt'), os.path.join('test', 'print', t), '--print-minified'] print ' ', ' '.join(cmd) actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() fail_if_not_identical(actual.strip(), open(os.path.join('test', 'print', wasm + '.minified.txt')).read().strip()) -print '\n[ checking binaryen-shell testcases... ]\n' +print '\n[ checking wasm-opt testcases... ]\n' for t in tests: if t.endswith('.wast') and not t.startswith('spec'): print '..', t t = os.path.join('test', t) - cmd = [os.path.join('bin', 'binaryen-shell'), t, '--print'] + cmd = [os.path.join('bin', 'wasm-opt'), t, '--print'] actual = run_command(cmd) actual = actual.replace('printing before:\n', '') @@ -402,7 +356,7 @@ for t in tests: binary_format_check(t) minify_check(t) -print '\n[ checking binaryen-shell spec testcases... ]\n' +print '\n[ checking wasm-shell spec testcases... ]\n' if len(requested) == 0: BLACKLIST = [] @@ -416,8 +370,8 @@ for t in spec_tests: wast = os.path.join('test', t) def run_spec_test(wast): - print ' run binaryen-shell on', wast - cmd = [os.path.join('bin', 'binaryen-shell'), wast] + print ' run wasm-shell on', wast + cmd = [os.path.join('bin', 'wasm-shell'), wast] return run_command(cmd, stderr=subprocess.PIPE) def check_expected(actual, expected): @@ -458,7 +412,7 @@ for t in spec_tests: for module, asserts in split_wast(wast): print ' testing split module', split_num split_num += 1 - open('split.wast', 'w').write(module + '\n' + '\n'.join(asserts)) + with open('split.wast', 'w') as o: o.write(module + '\n' + '\n'.join(asserts)) run_spec_test('split.wast') # before binary stuff - just check it's still ok split out result_wast = binary_format_check('split.wast', verify_final_result=False) # add the asserts, and verify that the test still passes @@ -547,8 +501,8 @@ for dot_s_dir in ['dot_s', 'llvm_autogenerated']: cmd = [os.path.join('bin', 's2wasm'), full, '--global-base=1024'] + stack_alloc run_command(cmd) - # run binaryen-shell on the .wast to verify that it parses - cmd = [os.path.join('bin', 'binaryen-shell'), expected_file] + # run wasm-shell on the .wast to verify that it parses + cmd = [os.path.join('bin', 'wasm-shell'), expected_file] run_command(cmd) print '\n[ running linker tests... ]\n' @@ -609,7 +563,7 @@ if torture: import test.waterfall.src.execute_files as execute_files unexpected_result_count += execute_files.run( - runner=os.path.abspath(os.path.join('bin', 'binaryen-shell')), + runner=os.path.abspath(os.path.join('bin', 'wasm-shell')), files=os.path.abspath(os.path.join(s2wasm_torture_out, '*.wast')), fails=os.path.abspath(os.path.join('test', 's2wasm_known_binaryen_shell_test_failures.txt')), out='', @@ -673,7 +627,7 @@ for t in sorted(os.listdir(os.path.join('test', 'example'))): continue print ' (will check trace in ', t, ')' src = 'trace.cpp' - open(src, 'w').write(out) + with open(src, 'w') as o: o.write(out) expected = os.path.join('test', 'example', t + '.txt') else: src = os.path.join('test', 'example', t) @@ -751,7 +705,7 @@ if has_emcc: asm = open('a.wasm.asm.js').read() asm = asm.replace('"almost asm"', '"use asm"; var not_in_asm = [].length + (true || { x: 5 }.x);') asm = asm.replace("'almost asm'", '"use asm"; var not_in_asm = [].length + (true || { x: 5 }.x);') - open('a.wasm.asm.js', 'w').write(asm) + with open('a.wasm.asm.js', 'w') as o: o.write(asm) if method == 'interpret-asm2wasm': os.unlink('a.wasm.wast') # we should not need the .wast if not success: diff --git a/scripts/support.py b/scripts/support.py index a99fb7604..2d4318980 100755 --- a/scripts/support.py +++ b/scripts/support.py @@ -87,3 +87,60 @@ def untar(tarfile, outdir): finally: if os.path.isdir(tmpdir): shutil.rmtree(tmpdir) + + +def split_wast(wast): + # .wast files can contain multiple modules, and assertions for each one. + # this splits out a wast into [(module, assertions), ..] + # we ignore module invalidity tests here. + wast = open(wast).read() + ret = [] + + def to_end(j): + depth = 1 + while depth > 0 and j < len(wast): + if wast[j] == '"': + j = wast.find('"', j + 1) + elif wast[j] == '(': + depth += 1 + elif wast[j] == ')': + depth -= 1 + elif wast[j] == ';' and wast[j + 1] == ';': + j = wast.find('\n', j) + j += 1 + return j + + i = 0 + while i >= 0: + start = wast.find('(', i) + if start >= 0 and wast[start + 1] == ';': + # block comment + i = wast.find(';)', start + 2) + assert i > 0, wast[start:] + i += 2 + continue + skip = wast.find(';', i) + if skip >= 0 and skip < start and skip + 1 < len(wast): + if wast[skip + 1] == ';': + i = wast.find('\n', i) + 1 + continue + if start < 0: + break + i = to_end(start + 1) + chunk = wast[start:i] + if chunk.startswith('(module'): + ret += [(chunk, [])] + elif chunk.startswith('(assert_invalid'): + continue + elif chunk.startswith(('(assert', '(invoke')): + ret[-1][1].append(chunk) + return ret + + +def run_command(cmd, expected_status=0, stderr=None): + print 'executing: ', ' '.join(cmd) + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=stderr) + out, err = proc.communicate() + if proc.returncode != expected_status: + raise Exception(('run_command failed', err)) + return out diff --git a/src/tools/wasm-as.cpp b/src/tools/wasm-as.cpp index e2425b24a..376c1288c 100644 --- a/src/tools/wasm-as.cpp +++ b/src/tools/wasm-as.cpp @@ -56,7 +56,7 @@ int main(int argc, const char *argv[]) { Module wasm; - try{ + try { if (options.debug) std::cerr << "s-parsing..." << std::endl; SExpressionParser parser(const_cast<char*>(input.c_str())); Element& root = *parser.root; diff --git a/src/tools/wasm-opt.cpp b/src/tools/wasm-opt.cpp new file mode 100644 index 000000000..d6e7d3bd6 --- /dev/null +++ b/src/tools/wasm-opt.cpp @@ -0,0 +1,105 @@ +/* + * Copyright 2016 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 WebAssembly optimizer, loads code, optionally runs passes on it, +// then writes it. +// + +#include <memory> + +#include "pass.h" +#include "support/command-line.h" +#include "support/file.h" +#include "wasm-printing.h" +#include "wasm-s-parser.h" +#include "wasm-validator.h" + +using namespace wasm; + +// +// main +// + +int main(int argc, const char* argv[]) { + Name entry; + std::vector<std::string> passes; + + Options options("wasm-opt", "Optimize .wast files"); + options + .add("--output", "-o", "Output file (stdout if not specified)", + Options::Arguments::One, + [](Options* o, const std::string& argument) { + o->extra["output"] = argument; + Colors::disable(); + }) + .add("", "-O", "execute default optimization passes", + Options::Arguments::Zero, + [&passes](Options*, const std::string&) { + passes.push_back("O"); + }) + .add_positional("INFILE", Options::Arguments::One, + [](Options* o, const std::string& argument) { + o->extra["infile"] = argument; + }); + for (const auto& p : PassRegistry::get()->getRegisteredNames()) { + options.add( + std::string("--") + p, "", PassRegistry::get()->getPassDescription(p), + Options::Arguments::Zero, + [&passes, p](Options*, const std::string&) { passes.push_back(p); }); + } + options.parse(argc, argv); + + auto input(read_file<std::string>(options.extra["infile"], Flags::Text, options.debug ? Flags::Debug : Flags::Release)); + + Module wasm; + + try { + if (options.debug) std::cerr << "s-parsing..." << std::endl; + SExpressionParser parser(const_cast<char*>(input.c_str())); + Element& root = *parser.root; + if (options.debug) std::cerr << "w-parsing..." << std::endl; + SExpressionWasmBuilder builder(wasm, *root[0]); + } catch (ParseException& p) { + p.dump(std::cerr); + Fatal() << "error in parsing input"; + } + + if (!WasmValidator().validate(wasm)) { + Fatal() << "error in validating input"; + } + + if (passes.size() > 0) { + if (options.debug) std::cerr << "running passes...\n"; + PassRunner passRunner(&wasm); + if (options.debug) passRunner.setDebug(true); + for (auto& passName : passes) { + if (passName == "O") { + passRunner.addDefaultOptimizationPasses(); + } else { + passRunner.add(passName); + } + } + passRunner.run(); + assert(WasmValidator().validate(wasm)); + } + + if (options.extra.count("output") > 0) { + if (options.debug) std::cerr << "writing..." << std::endl; + Output output(options.extra["output"], Flags::Text, options.debug ? Flags::Debug : Flags::Release); + WasmPrinter::printModule(&wasm, output.getStream()); + } +} diff --git a/src/tools/binaryen-shell.cpp b/src/tools/wasm-shell.cpp index 79c01c5bf..72e8e13ba 100644 --- a/src/tools/binaryen-shell.cpp +++ b/src/tools/wasm-shell.cpp @@ -169,44 +169,21 @@ static void run_asserts(size_t* i, bool* checked, Module* wasm, int main(int argc, const char* argv[]) { Name entry; - std::vector<std::string> passes; - Options options("binaryen-shell", "Execute .wast files"); + Options options("wasm-shell", "Execute .wast files"); options - .add("--output", "-o", "Output file (stdout if not specified)", - Options::Arguments::One, - [](Options* o, const std::string& argument) { - o->extra["output"] = argument; - Colors::disable(); - }) .add( "--entry", "-e", "call the entry point after parsing the module", Options::Arguments::One, [&entry](Options*, const std::string& argument) { entry = argument; }) - .add("", "-O", "execute default optimization passes", - Options::Arguments::Zero, - [&passes](Options*, const std::string&) { - passes.push_back("O"); - }) .add_positional("INFILE", Options::Arguments::One, [](Options* o, const std::string& argument) { o->extra["infile"] = argument; }); - for (const auto& p : PassRegistry::get()->getRegisteredNames()) { - options.add( - std::string("--") + p, "", PassRegistry::get()->getPassDescription(p), - Options::Arguments::Zero, - [&passes, p](Options*, const std::string&) { passes.push_back(p); }); - } options.parse(argc, argv); auto input(read_file<std::vector<char>>(options.extra["infile"], Flags::Text, options.debug ? Flags::Debug : Flags::Release)); - std::unique_ptr<Output> output; - if (options.extra.count("output") > 0) { - output = wasm::make_unique<Output>(options.extra["output"], Flags::Text, options.debug ? Flags::Debug : Flags::Release); - } - bool checked = false; try { @@ -226,29 +203,7 @@ int main(int argc, const char* argv[]) { builder = wasm::make_unique<SExpressionWasmBuilder>(wasm, *root[i]); i++; assert(WasmValidator().validate(wasm)); - - MixedArena moreModuleAllocations; - - if (passes.size() > 0) { - if (options.debug) std::cerr << "running passes...\n"; - PassRunner passRunner(&wasm); - if (options.debug) passRunner.setDebug(true); - for (auto& passName : passes) { - if (passName == "O") { - passRunner.addDefaultOptimizationPasses(); - } else { - passRunner.add(passName); - } - } - passRunner.run(); - assert(WasmValidator().validate(wasm)); - } - run_asserts(&i, &checked, &wasm, &root, &builder, entry); - - if (output) { - WasmPrinter::printModule(&wasm, output->getStream()); - } } else { run_asserts(&i, &checked, nullptr, &root, nullptr, entry); } diff --git a/test/waterfall b/test/waterfall -Subproject cba60ec0417d7d6a741ab42de0f46eee79e4f1e +Subproject bc52e2063dd1bd06df64b7dfeceeb6e00437b90 |