diff options
-rwxr-xr-x | check.py | 44 | ||||
-rw-r--r-- | src/js/post.js | 14 |
2 files changed, 54 insertions, 4 deletions
@@ -143,14 +143,54 @@ for t in spec_tests: fail(actual, expected) print '\n[ checking example testcases... ]\n' - +''' subprocess.check_call(['g++', '-std=c++11', os.path.join('test', 'example', 'find_div0s.cpp'), '-Isrc', '-g']) actual = subprocess.Popen(['./a.out'], stdout=subprocess.PIPE).communicate()[0] expected = open(os.path.join('test', 'example', 'find_div0s.txt')).read() if actual != expected: fail(actual, expected) +''' +print '\n[ checking wasm.js methods... (need both emcc and nodejs in your path) ]\n' + +for method in [None, 'asm2wasm', 'wasm-s-parser', 'just-asm']: + for success in [1, 0]: + command = ['emcc', '-o', 'a.wasm.js', '-s', 'BINARYEN="' + os.getcwd() + '"', os.path.join('test', 'hello_world.c') ] + if method: + command += ['-s', 'BINARYEN_METHOD="' + method + '"'] + else: + method = 'wasm-s-parser' # this is the default + print method, ' : ', command, ' => ', success + subprocess.check_call(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + def break_cashew(): + 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) + if method == 'asm2wasm': + os.unlink('a.wasm.wast') # we should not need the .wast + if not success: + break_cashew() # we need cashew + elif method == 'wasm-s-parser': + os.unlink('a.wasm.asm.js') # we should not need the .asm.js + if not success: + os.unlink('a.wasm.wast.mappedGlobals') + elif method == 'just-asm': + os.unlink('a.wasm.wast') # we should not need the .wast + break_cashew() # we don't use cashew, so ok to break it + if not success: + os.unlink('a.wasm.js') + else: + 1/0 + proc = subprocess.Popen(['nodejs', 'a.wasm.js'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = proc.communicate() + if success: + assert proc.returncode == 0 + assert 'hello, world!' in out + else: + assert proc.returncode != 0 + assert 'hello, world!' not in out -print '\n[ checking wasm.js polyfill testcases... (need both emcc and nodejs in your path) ]\n' +print '\n[ checking wasm.js testcases... (need both emcc and nodejs in your path) ]\n' for c in tests: if c.endswith(('.c', '.cpp')): diff --git a/src/js/post.js b/src/js/post.js index 233a9c449..7703d4a84 100644 --- a/src/js/post.js +++ b/src/js/post.js @@ -1,5 +1,17 @@ function integrateWasmJS(Module) { + // wasm.js has several methods for creating the compiled code module here: + // * 'wasm-s-parser': load s-expression code from a .wast and create wasm + // * 'asm2wasm': load asm.js code and translate to wasm + // * 'just-asm': no wasm, just load the asm.js code and use that (good for testing) + // The method can be set at compile time (BINARYEN_METHOD), or runtime by setting Module['wasmJSMethod']. + var method = Module['wasmJSMethod'] || 'wasm-s-parser'; + assert(method == 'asm2wasm' || method == 'wasm-s-parser' || method == 'just-asm'); + + if (method == 'just-asm') { + eval(Module['read'](Module['asmjsCodeFile'])); + return; + } // wasm lacks globals, so asm2wasm maps them into locations in memory. that information cannot // be present in the wasm output of asm2wasm, so we store it in a side file. If we load asm2wasm @@ -137,8 +149,6 @@ function integrateWasmJS(Module) { }; // Prepare to generate wasm, using either asm2wasm or wasm-s-parser - var method = Module['wasmJSMethod'] || 'wasm-s-parser'; - assert(method == 'asm2wasm' || method == 'wasm-s-parser'); var code = Module['read'](method == 'asm2wasm' ? Module['asmjsCodeFile'] : Module['wasmCodeFile']); var temp = wasmJS['_malloc'](code.length + 1); wasmJS['writeAsciiToMemory'](code, temp); |