Skip to content

Commit 0bff677

Browse files
authored
add a WASM option, identical to BINARYEN #4604 (#4632)
1 parent dc78bfd commit 0bff677

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

emcc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,9 @@ def check(input_file):
11761176
# we need to generate proper code for that
11771177
shared.Settings.RUNNING_JS_OPTS = 1
11781178

1179+
if shared.Settings.WASM:
1180+
shared.Settings.BINARYEN = 1 # these are synonyms
1181+
11791182
if shared.Settings.WASM_BACKEND:
11801183
js_opts = None
11811184
shared.Settings.BINARYEN = 1

src/settings.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ var USE_GLFW = 2; // Specify the GLFW version that is being linked against.
634634
// Valid options are 2 for GLFW2 and 3 for GLFW3.
635635

636636
var BINARYEN = 0; // Whether to use [Binaryen](https://github.com/WebAssembly/binaryen) to
637-
// compile (at runtime) our asm.js output into WebAssembly.
637+
// compile code to WebAssembly.
638638
// This will fetch the binaryen port and build it. (If, instead, you set
639639
// BINARYEN_ROOT in your ~/.emscripten file, then we use that instead
640640
// of the port, which can useful for local dev work on binaryen itself).
@@ -650,6 +650,8 @@ var BINARYEN_PASSES = ""; // A comma-separated list of passes to run in the bina
650650
var BINARYEN_ROOT = ""; // Directory where we can find Binaryen. Will be automatically set for you,
651651
// but you can set it to override if you are a Binaryen developer.
652652

653+
var WASM = 0; // Alias for BINARYEN, the two are identical. Both make us compile code to WebAssembly.
654+
653655
var WASM_BACKEND = 0; // Whether to use the WebAssembly backend that is in development in LLVM.
654656
// This requires that BINARYEN be set, as we use Binaryen's s2wasm to
655657
// translate the backend output.

tests/test_other.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6607,15 +6607,18 @@ def test_binaryen_and_js_opts(self):
66076607
(['-Os'], False, True),
66086608
(['-Oz'], False, False), # even though we run ctor evaller, don't run js opts, but we can't only-wasm due to ctor-evaller running js opts internally
66096609
]:
6610-
print args, 'js opts:', expect_js_opts, 'only-wasm:', expect_only_wasm
6611-
try_delete('a.out.js')
6612-
output, err = Popen([PYTHON, EMCC, path_from_root('tests', 'core', 'test_i64.c'), '-s', 'BINARYEN=1', '-s', 'BINARYEN_METHOD="interpret-s-expr"'] + args, stdout=PIPE, stderr=PIPE).communicate()
6613-
assert expect_js_opts == ('applying js optimization passes:' in err), err
6614-
assert expect_only_wasm == ('-emscripten-only-wasm' in err and '--wasm-only' in err), err # check both flag to fastcomp and to asm2wasm
6615-
wast = open('a.out.wast').read()
6616-
i64s = wast.count('(i64.')
6617-
print ' seen i64s:', i64s
6618-
assert expect_only_wasm == (i64s > 30), 'i64 opts can be emitted in only-wasm mode, but not normally' # note we emit a few i64s even without wasm-only, when we replace udivmoddi (around 15 such)
6610+
for option in ['BINARYEN', 'WASM']: # the two should be identical
6611+
try_delete('a.out.js')
6612+
try_delete('a.out.wast')
6613+
cmd = [PYTHON, EMCC, path_from_root('tests', 'core', 'test_i64.c'), '-s', option + '=1', '-s', 'BINARYEN_METHOD="interpret-s-expr"'] + args
6614+
print args, 'js opts:', expect_js_opts, 'only-wasm:', expect_only_wasm, ' ', ' '.join(cmd)
6615+
output, err = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()
6616+
assert expect_js_opts == ('applying js optimization passes:' in err), err
6617+
assert expect_only_wasm == ('-emscripten-only-wasm' in err and '--wasm-only' in err), err # check both flag to fastcomp and to asm2wasm
6618+
wast = open('a.out.wast').read()
6619+
i64s = wast.count('(i64.')
6620+
print ' seen i64s:', i64s
6621+
assert expect_only_wasm == (i64s > 30), 'i64 opts can be emitted in only-wasm mode, but not normally' # note we emit a few i64s even without wasm-only, when we replace udivmoddi (around 15 such)
66196622
finally:
66206623
del os.environ['EMCC_DEBUG']
66216624

0 commit comments

Comments
 (0)