diff options
-rw-r--r-- | scripts/test/spectest.js | 14 | ||||
-rw-r--r-- | scripts/test/wasm2js.py | 25 | ||||
-rw-r--r-- | src/tools/wasm2js.cpp | 49 | ||||
-rw-r--r-- | test/nonspec-bulk-memory.wast (renamed from test/bulk-memory.wast) | 0 | ||||
-rw-r--r-- | test/nonspec-bulk-memory.wast.from-wast (renamed from test/bulk-memory.wast.from-wast) | 0 | ||||
-rw-r--r-- | test/nonspec-bulk-memory.wast.fromBinary (renamed from test/bulk-memory.wast.fromBinary) | 0 | ||||
-rw-r--r-- | test/nonspec-bulk-memory.wast.fromBinary.noDebugInfo (renamed from test/bulk-memory.wast.fromBinary.noDebugInfo) | 0 |
7 files changed, 67 insertions, 21 deletions
diff --git a/scripts/test/spectest.js b/scripts/test/spectest.js index 3c4bac1b5..ede13479e 100644 --- a/scripts/test/spectest.js +++ b/scripts/test/spectest.js @@ -2,19 +2,19 @@ export function print() { console.log(); } export function print_i32(arg) { - console.log(arg, ' : i32'); + console.log(arg, ': i32'); } export function print_f32(arg) { - console.log(arg, ' : f32'); + console.log(arg, ': f32'); } export function print_f64(arg) { - console.log(arg, ' : f64'); + console.log(arg, ': f64'); } export function print_i32_f32(arg0, arg1) { - console.log(arg0, ' : i32'); - console.log(arg1, ' : f32'); + console.log(arg0, ': i32'); + console.log(arg1, ': f32'); } export function print_f64_f64(arg0, arg1) { - console.log(arg0, ' : f64'); - console.log(arg1, ' : f64'); + console.log(arg0, ': f64'); + console.log(arg1, ': f64'); } diff --git a/scripts/test/wasm2js.py b/scripts/test/wasm2js.py index fec0d26db..97320445b 100644 --- a/scripts/test/wasm2js.py +++ b/scripts/test/wasm2js.py @@ -43,7 +43,8 @@ def test_wasm2js_output(): print('..', os.path.basename(t)) - all_out = [] + all_js = [] + all_out = '' for module, asserts in support.split_wast(t): support.write_wast('split.wast', module, asserts) @@ -58,21 +59,21 @@ def test_wasm2js_output(): cmd += ['--emscripten'] if 'deterministic' in t: cmd += ['--deterministic'] - out = support.run_command(cmd) - all_out.append(out) + js = support.run_command(cmd) + all_js.append(js) if not shared.NODEJS and not shared.MOZJS: print('No JS interpreters. Skipping spec tests.') continue - open('a.2asm.mjs', 'w').write(out) + open('a.2asm.mjs', 'w').write(js) cmd += ['--allow-asserts'] - out = support.run_command(cmd) + js = support.run_command(cmd) # also verify it passes pass-debug verifications shared.with_pass_debug(lambda: support.run_command(cmd)) - open('a.2asm.asserts.mjs', 'w').write(out) + open('a.2asm.asserts.mjs', 'w').write(js) # verify asm.js is valid js, note that we're using --experimental-modules # to enable ESM syntax and we're also passing a custom loader to handle the @@ -87,9 +88,15 @@ def test_wasm2js_output(): cmd = node[:] cmd.append('a.2asm.asserts.mjs') out = support.run_command(cmd, expected_err='', err_ignore='ExperimentalWarning') - shared.fail_if_not_identical(out, '') - - shared.fail_if_not_identical_to_file(''.join(all_out), expected_file) + all_out += out + + shared.fail_if_not_identical_to_file(''.join(all_js), expected_file) + expected_out = os.path.join(shared.get_test_dir('spec'), 'expected-output', os.path.basename(t) + '.log') + if os.path.exists(expected_out): + expected_out = open(expected_out).read() + else: + expected_out = '' + shared.fail_if_not_identical(all_out, expected_out) def test_asserts_output(): diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp index 34ceaf357..b1fc45146 100644 --- a/src/tools/wasm2js.cpp +++ b/src/tools/wasm2js.cpp @@ -563,6 +563,11 @@ private: Element& e, Name testFuncName, Name asmModule); + Ref emitInvokeFunc(Builder& wasmBuilder, + Element& e, + Name testFuncName, + Name asmModule); + bool isInvokeHandled(Element& e); bool isAssertHandled(Element& e); void fixCalls(Ref asmjs, Name asmModule); @@ -690,6 +695,28 @@ Ref AssertionEmitter::emitAssertTrapFunc(Builder& wasmBuilder, return outerFunc; } +Ref AssertionEmitter::emitInvokeFunc(Builder& wasmBuilder, + Element& e, + Name testFuncName, + Name asmModule) { + Expression* body = sexpBuilder.parseExpression(e); + std::unique_ptr<Function> testFunc( + wasmBuilder.makeFunction(testFuncName, + std::vector<NameType>{}, + body->type, + std::vector<NameType>{}, + body)); + Ref jsFunc = processFunction(testFunc.get()); + fixCalls(jsFunc, asmModule); + emitFunction(jsFunc); + return jsFunc; +} + +bool AssertionEmitter::isInvokeHandled(Element& e) { + return e.isList() && e.size() >= 2 && e[0]->isStr() && + e[0]->str() == Name("invoke"); +} + bool AssertionEmitter::isAssertHandled(Element& e) { return e.isList() && e.size() >= 2 && e[0]->isStr() && (e[0]->str() == Name("assert_return") || @@ -796,19 +823,31 @@ void AssertionEmitter::emit() { emitWasm(wasm, out, flags, options.passOptions, funcName); continue; } - if (!isAssertHandled(e)) { + if (!isInvokeHandled(e) && !isAssertHandled(e)) { std::cerr << "skipping " << e << std::endl; continue; } Name testFuncName(IString(("check" + std::to_string(i)).c_str(), false)); + bool isInvoke = (e[0]->str() == Name("invoke")); bool isReturn = (e[0]->str() == Name("assert_return")); bool isReturnNan = (e[0]->str() == Name("assert_return_nan")); - Element& testOp = *e[1]; + Element* assertOp; + // An assertion of an invoke has the invoke inside the assert. + if (isAssertHandled(e)) { + assertOp = e[1]; + } else { + assertOp = &e; + } // Replace "invoke" with "call" - testOp[0]->setString(IString("call"), false, false); + (*assertOp)[0]->setString(IString("call"), false, false); // Need to claim dollared to get string as function target - testOp[1]->setString(testOp[1]->str(), /*dollared=*/true, false); - + (*assertOp)[1]->setString((*assertOp)[1]->str(), /*dollared=*/true, false); + if (isInvoke) { + emitInvokeFunc(wasmBuilder, e, testFuncName, asmModule); + out << testFuncName.str << "();\n"; + continue; + } + // Otherwise, this is some form of assertion. if (isReturn) { emitAssertReturnFunc(wasmBuilder, e, testFuncName, asmModule); } else if (isReturnNan) { diff --git a/test/bulk-memory.wast b/test/nonspec-bulk-memory.wast index 91f8c23a2..91f8c23a2 100644 --- a/test/bulk-memory.wast +++ b/test/nonspec-bulk-memory.wast diff --git a/test/bulk-memory.wast.from-wast b/test/nonspec-bulk-memory.wast.from-wast index 1d78b8e15..1d78b8e15 100644 --- a/test/bulk-memory.wast.from-wast +++ b/test/nonspec-bulk-memory.wast.from-wast diff --git a/test/bulk-memory.wast.fromBinary b/test/nonspec-bulk-memory.wast.fromBinary index 9120c43e6..9120c43e6 100644 --- a/test/bulk-memory.wast.fromBinary +++ b/test/nonspec-bulk-memory.wast.fromBinary diff --git a/test/bulk-memory.wast.fromBinary.noDebugInfo b/test/nonspec-bulk-memory.wast.fromBinary.noDebugInfo index 060667104..060667104 100644 --- a/test/bulk-memory.wast.fromBinary.noDebugInfo +++ b/test/nonspec-bulk-memory.wast.fromBinary.noDebugInfo |