Skip to content

Binaryen stack branch support #4528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,10 @@ def check(input_file):
pass
if use_closure_compiler:
logging.warning('closure compiler is known to have issues with binaryen (FIXME)')
# for simplicity, we always have a mem init file, which may also be imported into the wasm module.
# * if we also supported js mem inits we'd have 4 modes
# * and js mem inits are useful for avoiding a side file, but the wasm module avoids that anyhow
memory_init_file = True

if shared.Settings.CYBERDWARF:
newargs.append('-g')
Expand Down Expand Up @@ -1609,7 +1613,11 @@ def repl(m):
if DEBUG:
# Copy into temp dir as well, so can be run there too
shared.safe_copy(memfile, os.path.join(shared.get_emscripten_temp_dir(), os.path.basename(memfile)))
return 'memoryInitializer = "%s";' % os.path.basename(memfile)
if not shared.Settings.BINARYEN:
return 'memoryInitializer = "%s";' % os.path.basename(memfile)
else:
# with wasm, we may have the mem init file in the wasm binary already
return 'memoryInitializer = Module["wasmJSMethod"].indexOf("asmjs") >= 0 || Module["wasmJSMethod"].indexOf("interpret-asm2wasm") >= 0 ? "%s" : null;' % os.path.basename(memfile)
src = re.sub(shared.JS.memory_initializer_pattern, repl, open(final).read(), count=1)
open(final + '.mem.js', 'w').write(src)
final += '.mem.js'
Expand Down Expand Up @@ -1944,15 +1952,23 @@ def do_minify(): # minifies the code. this is also when we do certain optimizati
combined.close()
# finish compiling to WebAssembly, using asm2wasm, if we didn't already emit WebAssembly directly using the wasm backend.
if not shared.Settings.WASM_BACKEND:
cmd = [os.path.join(binaryen_bin, 'asm2wasm'), asm_target, '--mapped-globals=' + wasm_text_target + '.mappedGlobals', '--total-memory=' + str(shared.Settings.TOTAL_MEMORY)]
cmd = [os.path.join(binaryen_bin, 'asm2wasm'), asm_target, '--total-memory=' + str(shared.Settings.TOTAL_MEMORY)]
if shared.Settings.BINARYEN_IMPRECISE:
cmd += ['--imprecise']
if opt_level == 0:
cmd += ['--no-opts']
# import mem init file if it exists, and if we will not be using asm.js as a binaryen method (as it needs the mem init file, of course)
import_mem_init = memory_init_file and os.path.exists(memfile) and 'asmjs' not in shared.Settings.BINARYEN_METHOD and 'interpret-asm2wasm' not in shared.Settings.BINARYEN_METHOD
if import_mem_init:
cmd += ['--mem-init=' + memfile]
logging.debug('asm2wasm (asm.js => WebAssembly): ' + ' '.join(cmd))
TimeLogger.update()
subprocess.check_call(cmd, stdout=open(wasm_text_target, 'w'))
log_time('asm2wasm')
if import_mem_init:
# remove and forget about the mem init file in later processing; it does not need to be prefetched in the html, etc.
os.unlink(memfile)
memory_init_file = False
if shared.Settings.BINARYEN_SCRIPTS:
binaryen_scripts = os.path.join(shared.Settings.BINARYEN_ROOT, 'scripts')
script_env = os.environ.copy()
Expand Down
2 changes: 1 addition & 1 deletion src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ else if (ENVIRONMENT_IS_SHELL) {
if (typeof read != 'undefined') {
Module['read'] = read;
} else {
Module['read'] = function read() { throw 'no read() available (jsc?)' };
Module['read'] = function read() { throw 'no read() available' };
}

Module['readBinary'] = function readBinary(f) {
Expand Down
8 changes: 6 additions & 2 deletions tests/fuzz/csmith_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ def try_js(args=[]):

def execute_js(engine):
print '(run in %s)' % engine
js = shared.run_js(filename + '.js', engine=engine, check_timeout=True, assert_returncode=None)
try:
js = shared.run_js(filename + '.js', engine=engine, check_timeout=True, assert_returncode=None)
except:
print 'failed to run in primary'
return False
js = js.split('\n')[0] + '\n' # remove any extra printed stuff (node workarounds)
return correct1 == js or correct2 == js

Expand All @@ -168,7 +172,7 @@ def fail():
try:
js2 = shared.run_js(filename + '.js', stderr=PIPE, engine=engine2 + ['-w'], full_output=True, check_timeout=True, assert_returncode=None)
except:
print 'failed to run in secondary', js2
print 'failed to run in secondary'
break

# asm.js testing
Expand Down
1 change: 0 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7363,7 +7363,6 @@ def test_stack_overflow_check(self):
self.do_run(open(path_from_root('tests', 'stack_overflow.cpp'), 'r').read(), 'Stack overflow! Attempted to allocate')

@no_wasm
@no_emterpreter
def test_binaryen(self):
self.emcc_args += ['-s', 'BINARYEN=1', '-s', 'BINARYEN_METHOD="interpret-binary"']
self.do_run(open(path_from_root('tests', 'hello_world.c')).read(), 'hello, world!')
Expand Down
2 changes: 1 addition & 1 deletion tools/ports/binaryen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os, shutil, logging

TAG = 'version_11'
TAG = 'version_12'

def needed(settings, shared, ports):
if not settings.BINARYEN: return False
Expand Down