Skip to content

Commit 593178a

Browse files
authored
Fixes for #5998 (#1341)
* binaryen.js and wasm.js don't need filesystem support * newest emscripten no longer uses Runtime.* * build fixes for binaryen.js and wasm.js also move binaryen.js to use standard emscripten MODULARIZE * run binaryen.js in all possible engines ; update js builds * don't emit debug build to a different name, just emit binaryen.js. makes testing easier and safer * remove volatile things from binaryen.js info printing in tests
1 parent b5ee16f commit 593178a

File tree

12 files changed

+1814
-3071
lines changed

12 files changed

+1814
-3071
lines changed

auto_update_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@
239239
print s
240240
f = open('a.js', 'w')
241241
f.write(open(os.path.join('bin', 'binaryen.js')).read())
242+
# node/shell test support
242243
f.write(open(os.path.join('test', 'binaryen.js', s)).read())
243244
f.close()
244245
cmd = [MOZJS, 'a.js']

bin/binaryen.js

Lines changed: 204 additions & 841 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/wasm.js

Lines changed: 100 additions & 729 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build-js.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,23 @@ fi
4040
EMCC_ARGS="-std=c++11 --memory-init-file 0"
4141
EMCC_ARGS="$EMCC_ARGS -s ALLOW_MEMORY_GROWTH=1"
4242
EMCC_ARGS="$EMCC_ARGS -s DEMANGLE_SUPPORT=1"
43+
EMCC_ARGS="$EMCC_ARGS -s NO_FILESYSTEM=1"
4344
EMCC_ARGS="$EMCC_ARGS -s DISABLE_EXCEPTION_CATCHING=0" # Exceptions are thrown and caught when optimizing endless loops
4445
OUT_FILE_SUFFIX=
4546

4647
if [ "$1" == "-g" ]; then
4748
EMCC_ARGS="$EMCC_ARGS -O2" # need emcc js opts to be decently fast
4849
EMCC_ARGS="$EMCC_ARGS --llvm-opts 0 --llvm-lto 0"
4950
EMCC_ARGS="$EMCC_ARGS -profiling"
50-
OUT_FILE_SUFFIX=-g
5151
else
5252
EMCC_ARGS="$EMCC_ARGS -Oz"
5353
EMCC_ARGS="$EMCC_ARGS --llvm-lto 1"
5454
EMCC_ARGS="$EMCC_ARGS -s ELIMINATE_DUPLICATE_FUNCTIONS=1"
55+
EMCC_ARGS="$EMCC_ARGS --closure 1"
5556
# Why these settings?
5657
# See https://gist.github.com/rsms/e33c61a25a31c08260161a087be03169
5758
fi
5859

59-
if [ "$1" != "-g" ]; then
60-
EMCC_ARGS="$EMCC_ARGS --closure 1"
61-
fi
62-
6360
echo "building shared bitcode"
6461

6562
"$EMSCRIPTEN/em++" \
@@ -138,6 +135,7 @@ echo "building wasm.js"
138135
-Isrc/ \
139136
-o bin/wasm${OUT_FILE_SUFFIX}.js \
140137
-s MODULARIZE=1 \
138+
-s 'EXTRA_EXPORTED_RUNTIME_METHODS=["writeAsciiToMemory"]' \
141139
-s 'EXPORT_NAME="WasmJS"'
142140

143141
echo "building binaryen.js"
@@ -580,5 +578,10 @@ export_function "_BinaryenSetAPITracing"
580578
-Isrc/ \
581579
-s EXPORTED_FUNCTIONS=[${EXPORTED_FUNCTIONS}] \
582580
-o bin/binaryen${OUT_FILE_SUFFIX}.js \
583-
--pre-js src/js/binaryen.js-pre.js \
584-
--post-js src/js/binaryen.js-post.js
581+
--post-js src/js/binaryen.js-post.js \
582+
-s MODULARIZE=1 \
583+
-s 'EXPORT_NAME="Binaryen"'
584+
585+
# Create a singleton instance from the MODULARIZE module
586+
echo "Binaryen = Binaryen();" >> bin/binaryen${OUT_FILE_SUFFIX}.js
587+

check.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -358,25 +358,24 @@ def run_binaryen_js_tests():
358358
if not s.endswith('.js'): continue
359359
print s
360360
f = open('a.js', 'w')
361-
f.write(open(os.path.join(options.binaryen_bin, 'binaryen.js')).read())
362-
# node test support
363-
f.write('\nif (typeof require === "function") var Binaryen = module.exports;\n')
361+
binaryen_js = open(os.path.join(options.binaryen_bin, 'binaryen.js')).read()
362+
f.write(binaryen_js)
364363
test_path = os.path.join(options.binaryen_test, 'binaryen.js', s)
365364
test = open(test_path).read()
366365
need_wasm = 'WebAssembly.' in test # some tests use wasm support in the VM
367-
if MOZJS:
368-
cmd = [MOZJS]
369-
elif NODEJS and not need_wasm: # TODO: check if node is new and has wasm support
370-
cmd = [NODEJS]
371-
else:
372-
continue # we can't run it
373-
cmd += ['a.js']
374366
f.write(test)
375367
f.close()
376-
out = run_command(cmd, stderr=subprocess.STDOUT)
377-
expected = open(os.path.join(options.binaryen_test, 'binaryen.js', s + '.txt')).read()
378-
if expected not in out:
379-
fail(out, expected)
368+
def test(engine):
369+
cmd = [engine, 'a.js']
370+
out = run_command(cmd, stderr=subprocess.STDOUT)
371+
expected = open(os.path.join(options.binaryen_test, 'binaryen.js', s + '.txt')).read()
372+
if expected not in out:
373+
fail(out, expected)
374+
# run in all possible shells
375+
if MOZJS:
376+
test(MOZJS)
377+
if NODEJS and not need_wasm: # TODO: check if node is new and has wasm support
378+
test(NODEJS)
380379

381380
def run_validator_tests():
382381
print '\n[ running validation tests... ]\n'

src/js/binaryen.js-post.js

Lines changed: 1449 additions & 1465 deletions
Large diffs are not rendered by default.

src/js/binaryen.js-pre.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/binaryen.js/functions.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
function cleanInfo(info) {
2+
var ret = {};
3+
for (var x in info) {
4+
if (x !== 'name' && x !== 'body' && x !== 'type') {
5+
ret[x] = info[x];
6+
}
7+
}
8+
return ret;
9+
}
10+
111
var module = new Binaryen.Module();
212

313
var signature = module.addFunctionType("i", Binaryen.i32, []);
@@ -13,15 +23,17 @@ console.log("GetFunction is equal: " + (func === module.getFunction("a-function"
1323

1424
module.runPassesOnFunction(func, ["precompute"]);
1525

16-
console.log("getFunctionTypeInfo=" + JSON.stringify(Binaryen.getFunctionTypeInfo(signature)));
17-
var info = Binaryen.getFunctionInfo(func);
18-
console.log("getFunctionInfo=" + JSON.stringify(info));
19-
console.log("getExpressionInfo(body)=" + JSON.stringify(Binaryen.getExpressionInfo(info.body)));
20-
console.log(Binaryen.emitText(info.body));
26+
var sigInfo = Binaryen.getFunctionTypeInfo(signature);
27+
console.log("getFunctionTypeInfo=" + JSON.stringify(cleanInfo(sigInfo)));
28+
var funcInfo = Binaryen.getFunctionInfo(func);
29+
console.log("getFunctionInfo=" + JSON.stringify(cleanInfo(funcInfo)));
30+
var expInfo = Binaryen.getExpressionInfo(funcInfo.body);
31+
console.log("getExpressionInfo(body)=" + JSON.stringify(cleanInfo(expInfo)));
32+
console.log(Binaryen.emitText(funcInfo.body));
2133

2234
module.removeFunction("a-function");
2335

24-
module.addGlobal("a-global", Binaryen.i32, false, info.body);
36+
module.addGlobal("a-global", Binaryen.i32, false, funcInfo.body);
2537

2638
module.validate();
2739

test/binaryen.js/functions.js.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GetFunction is equal: true
2-
getFunctionTypeInfo={"name":5366144,"params":[],"result":1}
3-
getFunctionInfo={"name":5399120,"type":5366144,"params":[],"result":1,"vars":[],"body":5366312}
4-
getExpressionInfo(body)={"id":15,"type":1,"value":3}
2+
getFunctionTypeInfo={"params":[],"result":1}
3+
getFunctionInfo={"params":[],"result":1,"vars":[]}
4+
getExpressionInfo(body)={"id":15,"value":3}
55
(i32.const 3)
66

77
(module

test/binaryen.js/kitchen-sink.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11

22
// kitchen sink, tests the full API
33

4+
function cleanInfo(info) {
5+
var ret = {};
6+
for (var x in info) {
7+
if (x !== 'value') {
8+
ret[x] = info[x];
9+
}
10+
}
11+
return ret;
12+
}
13+
414
var module;
515

616
// helpers
@@ -212,7 +222,7 @@ function test_core() {
212222
];
213223

214224
// Test expression utility
215-
console.log("getExpressionInfo=" + JSON.stringify(Binaryen.getExpressionInfo(valueList[3])));
225+
console.log("getExpressionInfo=" + JSON.stringify(cleanInfo(Binaryen.getExpressionInfo(valueList[3]))));
216226
console.log(Binaryen.emitText(valueList[3])); // test printing a standalone expression
217227

218228
console.log("getExpressionInfo(i32.const)=" + JSON.stringify(Binaryen.getExpressionInfo(module.i32.const(5))));

0 commit comments

Comments
 (0)