diff options
-rw-r--r-- | README.md | 8 | ||||
-rwxr-xr-x | check.py | 5 | ||||
-rwxr-xr-x | emcc_to_wasm.js.sh | 19 | ||||
-rw-r--r-- | src/js/post.js | 2 |
4 files changed, 7 insertions, 27 deletions
@@ -96,13 +96,13 @@ Set `ASM2WASM_DEBUG=1` in the env to see debug info, about asm.js functions as t ### wasm.js -Run +Run Emscripten's `emcc` command, passing it an additional flag: ``` -./emcc_to_wasm.js.sh [.c or .cpp file] [whatever other emcc flags you want] +emcc -s 'BINARYEN="path-to-this-dir"' [whatever other emcc flags you want] ``` -That will call `emcc` and then emit `a.normal.js`, a normal asm.js build for comparison purposes, and `a.wasm.js`, which contains the entire polyfill (`asm2wasm` translator + `wasm.js` interpreter). +(Note the need for quotes on the path, and on the entire `BINARYEN=..` argument, due to how shell argument parsing works.) The `BINARYEN` flag tells it to emit code using `wasm.js`, and where to find `wasm.js` itself. The output `*.js` file will then contain the entire polyfill (`asm2wasm` translator + `wasm.js` interpreter). The asm.js code will be in `*.asm.js`. ### C/C++ Source => asm2wasm => WebAssembly @@ -114,7 +114,7 @@ emcc src.cpp -o a.html --separate-asm That will emit `a.html`, `a.js`, and `a.asm.js`. That last file is the asm.js module, which you can pass into `asm2wasm`. -For basic tests, that command should work, but in general you need a few more arguments to emcc, see emcc's usage in `emcc_to_wasm.js.sh`, specifically: +For basic tests, that command should work, but in general you need a few more arguments to emcc, see what emcc.py does when given the `BINARYEN` option, including: * `ALIASING_FUNCTION_POINTERS=0` because WebAssembly does not allow aliased function pointers (there is a single table). * `GLOBAL_BASE=1000` because WebAssembly lacks global variables, so `asm2wasm` maps them onto addresses in memory. This requires that you have some reserved space for those variables. With that argument, we reserve the area up to `1000`. @@ -159,15 +159,14 @@ for c in tests: extra = json.loads(open(emcc).read()) if os.path.exists('a.normal.js'): os.unlink('a.normal.js') for opts in [[], ['-O1'], ['-O2'], ['-O3'], ['-Oz']]: - command = ['./emcc_to_wasm.js.sh', os.path.join('test', c)] + opts + extra + command = ['emcc', '-o', 'a.wasm.js', '-s', 'BINARYEN="' + os.getcwd() + '"', os.path.join('test', c)] + opts + extra subprocess.check_call(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) print '....' + ' '.join(command) if post: - open('a.normal.js', 'a').write(post) open('a.wasm.js', 'a').write(post) else: print ' (no post)' - for which in ['normal', 'wasm']: + for which in ['wasm']: print '......', which try: args = json.loads(open(os.path.join('test', base + '.args')).read()) diff --git a/emcc_to_wasm.js.sh b/emcc_to_wasm.js.sh deleted file mode 100755 index 5e89f198e..000000000 --- a/emcc_to_wasm.js.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -set -e - -echo "calling emcc" -emcc -o a.html --separate-asm -g1 -s TOTAL_MEMORY=67108864 -s GLOBAL_BASE=1024 -s ALIASING_FUNCTION_POINTERS=0 $@ - -# we now have a.asm.js and a.js - -echo 'constructing a.normal.js' # just normal combination of the files. no wasm yet -cat src/templates/normal.js > a.normal.js -cat a.asm.js >> a.normal.js -cat a.js >> a.normal.js - -echo 'constructing a.wasm.js' # use wasm polyfill in place of asm.js THIS IS NOT A DRILL -cat src/templates/wasm.js > a.wasm.js -cat bin/wasm.js >> a.wasm.js -cat a.js >> a.wasm.js - diff --git a/src/js/post.js b/src/js/post.js index 2ecec51aa..45d850f10 100644 --- a/src/js/post.js +++ b/src/js/post.js @@ -22,7 +22,7 @@ wasmJS._free(temp); // Generate memory XXX TODO get the right size - var theBuffer = Module['buffer'] = new ArrayBuffer(64*1024*1024); + var theBuffer = Module['buffer'] = new ArrayBuffer(Module['providedTotalMemory'] || 64*1024*1024); // Information for the instance of the module. var info = wasmJS['info'] = { |