Skip to content

Commit a187a6a

Browse files
authored
Rename BINARYEN_MEM_MAX to WASM_MEM_MAX (#5803)
The name 'binaryen' is mostly an implementation detail of emscripten, and the user-facing feature is actually wasm output. Also introduces a settings-alias mechanism that we can use to canonicalize flag names for backward compatibility.
1 parent b237373 commit a187a6a

File tree

5 files changed

+44
-19
lines changed

5 files changed

+44
-19
lines changed

emcc.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,16 @@ def detect_fixed_language_mode(args):
694694
assert key != 'WASM_BACKEND', 'do not set -s WASM_BACKEND, instead set EMCC_WASM_BACKEND=1 in the environment'
695695
newargs = [arg for arg in newargs if arg is not '']
696696

697+
# Handle aliases in settings flags
698+
settings_aliases = {
699+
'BINARYEN_MEM_MAX': 'WASM_MEM_MAX',
700+
# TODO: change most (all?) other BINARYEN* names to WASM*
701+
}
702+
def setting_sub(s):
703+
key, rest = s.split('=', 1)
704+
return '='.join([settings_aliases.get(key, key), rest])
705+
settings_changes = map(setting_sub, settings_changes)
706+
697707
# Find input files
698708

699709
# These three arrays are used to store arguments of different types for
@@ -880,7 +890,7 @@ def check(input_file):
880890
key, value = change.split('=', 1)
881891

882892
# In those settings fields that represent amount of memory, translate suffixes to multiples of 1024.
883-
if key in ['TOTAL_STACK', 'TOTAL_MEMORY', 'GL_MAX_TEMP_BUFFER_SIZE', 'SPLIT_MEMORY', 'BINARYEN_MEM_MAX']:
893+
if key in ['TOTAL_STACK', 'TOTAL_MEMORY', 'GL_MAX_TEMP_BUFFER_SIZE', 'SPLIT_MEMORY', 'WASM_MEM_MAX']:
884894
value = str(shared.expand_byte_size_suffixes(value))
885895

886896
original_exported_response = False
@@ -1116,7 +1126,7 @@ def check(input_file):
11161126
else:
11171127
assert shared.Settings.TOTAL_MEMORY % (16*1024*1024) == 0, 'For asm.js, TOTAL_MEMORY must be a multiple of 16MB, was ' + str(shared.Settings.TOTAL_MEMORY)
11181128
assert shared.Settings.TOTAL_MEMORY >= shared.Settings.TOTAL_STACK, 'TOTAL_MEMORY must be larger than TOTAL_STACK, was ' + str(shared.Settings.TOTAL_MEMORY) + ' (TOTAL_STACK=' + str(shared.Settings.TOTAL_STACK) + ')'
1119-
assert shared.Settings.BINARYEN_MEM_MAX == -1 or shared.Settings.BINARYEN_MEM_MAX % 65536 == 0, 'BINARYEN_MEM_MAX must be a multiple of 64KB, was ' + str(shared.Settings.BINARYEN_MEM_MAX)
1129+
assert shared.Settings.WASM_MEM_MAX == -1 or shared.Settings.WASM_MEM_MAX % 65536 == 0, 'WASM_MEM_MAX must be a multiple of 64KB, was ' + str(shared.Settings.WASM_MEM_MAX)
11201130

11211131
if shared.Settings.WASM_BACKEND:
11221132
options.js_opts = None
@@ -2279,8 +2289,8 @@ def do_binaryen(final, target, asm_target, options, memfile, wasm_binary_target,
22792289
cmd += ['--table-max=-1']
22802290
if shared.Settings.SIDE_MODULE:
22812291
cmd += ['--mem-max=-1']
2282-
elif shared.Settings.BINARYEN_MEM_MAX >= 0:
2283-
cmd += ['--mem-max=' + str(shared.Settings.BINARYEN_MEM_MAX)]
2292+
elif shared.Settings.WASM_MEM_MAX >= 0:
2293+
cmd += ['--mem-max=' + str(shared.Settings.WASM_MEM_MAX)]
22842294
if shared.Settings.LEGALIZE_JS_FFI != 1:
22852295
cmd += ['--no-legalize-javascript-ffi']
22862296
if shared.Building.is_wasm_only():

src/library.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ LibraryManager.library = {
289289
#else
290290
var maxHeapSize = 2*1024*1024*1024 - 16777216;
291291
#endif
292-
#if BINARYEN_MEM_MAX != -1
293-
maxHeapSize = {{{ BINARYEN_MEM_MAX }}};
292+
#if WASM_MEM_MAX != -1
293+
maxHeapSize = {{{ WASM_MEM_MAX }}};
294294
#endif
295295
#if !ALLOW_MEMORY_GROWTH
296296
maxHeapSize = HEAPU8.length;

src/preamble.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,11 +1183,11 @@ if (Module['buffer']) {
11831183
assert(TOTAL_MEMORY % WASM_PAGE_SIZE === 0);
11841184
#endif
11851185
#if ALLOW_MEMORY_GROWTH
1186-
#if BINARYEN_MEM_MAX
1186+
#if WASM_MEM_MAX
11871187
#if ASSERTIONS
1188-
assert({{{ BINARYEN_MEM_MAX }}} % WASM_PAGE_SIZE == 0);
1188+
assert({{{ WASM_MEM_MAX }}} % WASM_PAGE_SIZE == 0);
11891189
#endif
1190-
Module['wasmMemory'] = new WebAssembly.Memory({ 'initial': TOTAL_MEMORY / WASM_PAGE_SIZE, 'maximum': {{{ BINARYEN_MEM_MAX }}} / WASM_PAGE_SIZE });
1190+
Module['wasmMemory'] = new WebAssembly.Memory({ 'initial': TOTAL_MEMORY / WASM_PAGE_SIZE, 'maximum': {{{ WASM_MEM_MAX }}} / WASM_PAGE_SIZE });
11911191
#else
11921192
Module['wasmMemory'] = new WebAssembly.Memory({ 'initial': TOTAL_MEMORY / WASM_PAGE_SIZE });
11931193
#endif

src/settings.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,10 @@ var BINARYEN_TRAP_MODE = "allow"; // How we handle wasm operations that may trap
718718
var BINARYEN_PASSES = ""; // A comma-separated list of passes to run in the binaryen optimizer,
719719
// for example, "dce,precompute,vacuum".
720720
// When set, this overrides the default passes we would normally run.
721-
var BINARYEN_MEM_MAX = -1; // Set the maximum size of memory in the wasm module (in bytes).
722-
// Without this, TOTAL_MEMORY is used (as it is used for the initial value),
723-
// or if memory growth is enabled, no limit is set. This overrides both of those.
721+
var WASM_MEM_MAX = -1; // Set the maximum size of memory in the wasm module (in bytes).
722+
// Without this, TOTAL_MEMORY is used (as it is used for the initial value),
723+
// or if memory growth is enabled, no limit is set. This overrides both of those.
724+
// (This option was formerly called BINARYEN_MEM_MAX)
724725
var BINARYEN_ASYNC_COMPILATION = 1; // Whether to compile the wasm asynchronously, which is more
725726
// efficient and does not block the main thread. This is currently
726727
// required for all but the smallest modules to run in V8

tests/test_other.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7471,8 +7471,8 @@ def test_binaryen_mem(self):
74717471
for args, expect_initial, expect_max in [
74727472
(['-s', 'TOTAL_MEMORY=20971520'], 320, 320),
74737473
(['-s', 'TOTAL_MEMORY=20971520', '-s', 'ALLOW_MEMORY_GROWTH=1'], 320, None),
7474-
(['-s', 'TOTAL_MEMORY=20971520', '-s', 'BINARYEN_MEM_MAX=41943040'], 320, 640),
7475-
(['-s', 'TOTAL_MEMORY=20971520', '-s', 'ALLOW_MEMORY_GROWTH=1', '-s', 'BINARYEN_MEM_MAX=41943040'], 320, 640),
7474+
(['-s', 'TOTAL_MEMORY=20971520', '-s', 'WASM_MEM_MAX=41943040'], 320, 640),
7475+
(['-s', 'TOTAL_MEMORY=20971520', '-s', 'ALLOW_MEMORY_GROWTH=1', '-s', 'WASM_MEM_MAX=41943040'], 320, 640),
74767476
]:
74777477
cmd = [PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'WASM=1', '-O2', '-s', 'BINARYEN_METHOD="interpret-s-expr"'] + args
74787478
print(' '.join(cmd))
@@ -7500,11 +7500,11 @@ def test_binaryen_invalid_mem(self):
75007500
ret = subprocess.Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'TOTAL_MEMORY=33MB'], stderr=subprocess.PIPE).communicate()[1]
75017501
assert 'TOTAL_MEMORY must be a multiple of 16MB' in ret, ret
75027502

7503-
ret = subprocess.Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'BINARYEN_MEM_MAX=33MB'], stderr=subprocess.PIPE).communicate()[1]
7504-
assert 'BINARYEN_MEM_MAX must be a multiple of 64KB' not in ret, ret
7503+
ret = subprocess.Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'WASM_MEM_MAX=33MB'], stderr=subprocess.PIPE).communicate()[1]
7504+
assert 'WASM_MEM_MAX must be a multiple of 64KB' not in ret, ret
75057505

7506-
ret = subprocess.Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'BINARYEN_MEM_MAX=33MB+1'], stderr=subprocess.PIPE).communicate()[1]
7507-
assert 'BINARYEN_MEM_MAX must be a multiple of 64KB' in ret, ret
7506+
ret = subprocess.Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', 'WASM_MEM_MAX=33MB+1'], stderr=subprocess.PIPE).communicate()[1]
7507+
assert 'WASM_MEM_MAX must be a multiple of 64KB' in ret, ret
75087508

75097509
def test_binaryen_ctors(self):
75107510
if SPIDERMONKEY_ENGINE not in JS_ENGINES: return self.skip('cannot run without spidermonkey')
@@ -7649,7 +7649,7 @@ def test_sysconf_phys_pages(self):
76497649
(['-s', 'TOTAL_MEMORY=32MB', '-s', 'ALLOW_MEMORY_GROWTH=1'], (2*1024*1024*1024 - 16777216) // 16384),
76507650
(['-s', 'TOTAL_MEMORY=32MB', '-s', 'BINARYEN=1', '-s', 'BINARYEN_METHOD="interpret-asm2wasm"'], 2048),
76517651
(['-s', 'TOTAL_MEMORY=32MB', '-s', 'ALLOW_MEMORY_GROWTH=1', '-s', 'BINARYEN=1', '-s', 'BINARYEN_METHOD="interpret-asm2wasm"'], (2*1024*1024*1024 - 65536) // 16384),
7652-
(['-s', 'TOTAL_MEMORY=32MB', '-s', 'ALLOW_MEMORY_GROWTH=1', '-s', 'BINARYEN=1', '-s', 'BINARYEN_METHOD="interpret-asm2wasm"', '-s', 'BINARYEN_MEM_MAX=128MB'], 2048*4)
7652+
(['-s', 'TOTAL_MEMORY=32MB', '-s', 'ALLOW_MEMORY_GROWTH=1', '-s', 'BINARYEN=1', '-s', 'BINARYEN_METHOD="interpret-asm2wasm"', '-s', 'WASM_MEM_MAX=128MB'], 2048*4)
76537653
]:
76547654
cmd = [PYTHON, EMCC, path_from_root('tests', 'unistd', 'sysconf_phys_pages.c')] + args
76557655
print(str(cmd))
@@ -7852,3 +7852,17 @@ def test_emar_M(self):
78527852
result = subprocess.check_output([PYTHON, EMAR, 't', 'combined.a'])
78537853
assert 'file1' in result
78547854
assert 'file2' in result
7855+
7856+
7857+
def test_flag_aliases(self):
7858+
def assert_aliases_match(flag1, flag2, flagarg, extra_args):
7859+
results = {}
7860+
for f in (flag1, flag2):
7861+
outfile = 'aliases.js'
7862+
subprocess.check_call([PYTHON, EMCC, path_from_root('tests', 'hello_world.c'), '-s', f + '=' + flagarg, '-o', outfile] + extra_args)
7863+
with open(outfile) as out:
7864+
results[f] = out.read()
7865+
self.assertEqual(results[flag1], results[flag2], 'results should be identical')
7866+
7867+
7868+
assert_aliases_match('WASM_MEM_MAX', 'BINARYEN_MEM_MAX', '16777216', ['-s', 'WASM=1'])

0 commit comments

Comments
 (0)