Skip to content

Commit

Permalink
Use binaryen --mem-max flag, and add testing (#4723)
Browse files Browse the repository at this point in the history
* use binaryen --mem-max flag, and add testing

* update binaryen tag
  • Loading branch information
kripken committed Nov 12, 2016
1 parent d986aa2 commit 4cf15ef
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,8 @@ def do_minify(): # minifies the code. this is also when we do certain optimizati
cmd += ['--mem-init=' + memfile]
if not shared.Settings.RELOCATABLE:
cmd += ['--mem-base=' + str(shared.Settings.GLOBAL_BASE)]
if shared.Settings.BINARYEN_MEM_MAX >= 0:
cmd += ['--mem-max=' + str(shared.Settings.BINARYEN_MEM_MAX)]
if shared.Building.is_wasm_only():
cmd += ['--wasm-only'] # this asm.js is code not intended to run as asm.js, it is only ever going to be wasm, an can contain special fastcomp-wasm support
logging.debug('asm2wasm (asm.js => WebAssembly): ' + ' '.join(cmd))
Expand Down
3 changes: 3 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@ var BINARYEN_IMPRECISE = 0; // Whether to apply imprecise/unsafe binaryen optimi
var BINARYEN_PASSES = ""; // A comma-separated list of passes to run in the binaryen optimizer,
// for example, "dce,precompute,vacuum".
// When set, this overrides the default passes we would normally run.
var BINARYEN_MEM_MAX = -1; // Set the maximum size of memory in the wasm module (in bytes).
// Without this, TOTAL_MEMORY is used (as it is used for the initial value),
// or if memory growth is enabled, no limit is set. This overrides both of those.
var BINARYEN_ROOT = ""; // Directory where we can find Binaryen. Will be automatically set for you,
// but you can set it to override if you are a Binaryen developer.

Expand Down
22 changes: 22 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -6981,6 +6981,28 @@ def test_binaryen_default_method(self):
self.assertContained('trying binaryen method: native-wasm', out) # native is the default
assert out.count('trying binaryen method') == 1, 'must not try any other method'

def test_binaryen_mem(self):
for args, expect_initial, expect_max in [
(['-s', 'TOTAL_MEMORY=20971520'], 320, 320),
(['-s', 'TOTAL_MEMORY=20971520', '-s', 'ALLOW_MEMORY_GROWTH=1'], 320, None),
(['-s', 'TOTAL_MEMORY=20971520', '-s', 'BINARYEN_MEM_MAX=41943040'], 320, 640),
(['-s', 'TOTAL_MEMORY=20971520', '-s', 'ALLOW_MEMORY_GROWTH=1', '-s', 'BINARYEN_MEM_MAX=41943040'], 320, 640),
]:
cmd = [PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'WASM=1', '-O2', '-s', 'BINARYEN_METHOD="interpret-s-expr"'] + args
print ' '.join(cmd)
subprocess.check_call(cmd)
wast = open('a.out.wast').read()
lines = wast.split('\n')
for line in lines:
if '(import "env" "memory" (memory ' in line:
parts = line.strip().replace('(', '').replace(')', '').split(' ')
print parts
assert parts[5] == str(expect_initial)
if not expect_max:
assert len(parts) == 6
else:
assert parts[6] == str(expect_max)

def test_wasm_targets(self):
for f in ['a.wasm', 'a.wast']:
process = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), '-o', f], stdout=PIPE, stderr=PIPE)
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_20'
TAG = 'version_21'

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

0 comments on commit 4cf15ef

Please sign in to comment.