summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Wirtz <dcode@dcode.io>2019-12-20 00:36:11 +0100
committerAlon Zakai <azakai@google.com>2019-12-19 15:36:11 -0800
commit02e6ba2b139e6c7ac0a97baa2af75df4250e140f (patch)
treeabef9ae255bf9d7369c47ef8c0ff714ef4d85b46
parent81c16df401347e8e067fe9ccf0c26ae532bc03d5 (diff)
downloadbinaryen-02e6ba2b139e6c7ac0a97baa2af75df4250e140f.tar.gz
binaryen-02e6ba2b139e6c7ac0a97baa2af75df4250e140f.tar.bz2
binaryen-02e6ba2b139e6c7ac0a97baa2af75df4250e140f.zip
Compile Binaryen to WebAssembly (#2503)
This PR enables compiling Binaryen to WebAssembly when building binaryen.js. Since WebAssembly is best compiled and instantiated asynchronously in browsers, it also adds a new mechanism to tell if respectively when the module is ready by means of one of the following: // Using a promise const binaryen = require("binaryen"); binaryen.ready.then(() => { ... use normally ... }); // Using await const binaryen = require("binaryen"); (async () => { await binaryen.ready; ... use normally ... })(); // Where top-level await is available const binaryen = await require("binaryen").ready; ... use normally ... One can also tell if Binaryen is already ready (for example when assuming it in follow-up code) by: if (/* we already know that */ binaryen.isReady) { ... use normally ... } else { throw Error("Binaryen is supposed to be ready here but isn't"); } The JS test cases have been updated accordingly by wrapping everything in a test function and invoking it once ready. Documentation will have to be updated as well to cover this of course. New file size is about 2.5mb, even though the Wasm becomes inlined into the JS file which makes distribution across different environments a lot easier. Also makes building binaryen (to either js or wasm) emit binaryen.js, and not binaryen_js.js etc. Supersedes and thus fixes #1381 With .ready it also fixes #2452
-rw-r--r--.gitattributes1
-rw-r--r--CHANGELOG.md4
-rw-r--r--CMakeLists.txt35
-rw-r--r--scripts/test/shared.py4
-rw-r--r--src/js/binaryen.js-post.js926
-rw-r--r--test/binaryen.js/atomics.js158
-rw-r--r--test/binaryen.js/custom-section.js14
-rw-r--r--test/binaryen.js/debug-info.js68
-rw-r--r--test/binaryen.js/emit_asmjs.js14
-rw-r--r--test/binaryen.js/event.js34
-rw-r--r--test/binaryen.js/exception-handling.js84
-rw-r--r--test/binaryen.js/functions.js38
-rw-r--r--test/binaryen.js/global.js42
-rw-r--r--test/binaryen.js/hello-world.js96
-rw-r--r--test/binaryen.js/kitchen-sink.js12
-rw-r--r--test/binaryen.js/kitchen-sink.js.txt10
-rw-r--r--test/binaryen.js/optimize-levels.js77
-rw-r--r--test/binaryen.js/push-pop.js50
-rw-r--r--test/binaryen.js/reloc.js34
-rw-r--r--test/binaryen.js/sieve.js128
-rw-r--r--test/binaryen.js/simd.js12
-rw-r--r--test/binaryen.js/sourcemap.js74
-rw-r--r--test/binaryen.js/stackir.js19
-rw-r--r--test/binaryen.js/validation_errors.js52
-rwxr-xr-xtravis-emcc-tests.sh12
25 files changed, 1085 insertions, 913 deletions
diff --git a/.gitattributes b/.gitattributes
index dfdb8b771..ba181f19d 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,2 @@
*.sh text eol=lf
+test/binaryen.js/*.txt text eol=lf
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d3f9cf4ad..74fe3191e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,10 @@ Current Trunk
- Add the ability to create multivalue Types in the C and JS APIs.
- Remove named function types. They are replaced by `params` and `results` types
local to each function.
+- Binaryen.js can now be compiled to Wasm using the `binaryen_wasm` target.
+ Unlike the JS variant, the Wasm variant requires asynchronously awaiting the
+ Wasm blob's instantiation and initialization before being usable, using the
+ `binaryen.ready` promise, e.g. `binaryen.ready.then(() => ...)`.
v88
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 118e80ba7..b338943ff 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -365,22 +365,40 @@ install(TARGETS wasm-reduce DESTINATION ${CMAKE_INSTALL_BINDIR})
# binaryen.js
#
# Note that we can't emit binaryen.js directly, as there is libbinaryen already
-# declared earlier, so we create binaryen_js.js, which must then be copied.
+# declared earlier, so we create binaryen_wasm/js.js, which must then be copied.
+# Note that SHELL: is needed as otherwise cmake will coalesce -s link flags
+# in an incorrect way for emscripten.
if(EMSCRIPTEN)
- set(binaryen_js_SOURCES
+ set(binaryen_emscripten_SOURCES
src/binaryen-c.cpp
)
+
+ # binaryen.js WebAssembly variant
+ add_executable(binaryen_wasm
+ ${binaryen_emscripten_SOURCES})
+ target_link_libraries(binaryen_wasm wasm asmjs emscripten-optimizer passes ir cfg support wasm)
+ target_link_libraries(binaryen_wasm "-s MODULARIZE_INSTANCE=1")
+ target_link_libraries(binaryen_wasm "-s NO_FILESYSTEM=0")
+ target_link_libraries(binaryen_wasm "-s NODERAWFS=0")
+ target_link_libraries(binaryen_wasm "-s EXPORT_NAME=Binaryen")
+ target_link_libraries(binaryen_wasm "--post-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-post.js")
+ target_link_libraries(binaryen_wasm optimized "--closure 1")
+ target_link_libraries(binaryen_wasm optimized "--llvm-lto 1")
+ target_link_libraries(binaryen_wasm debug "--profiling")
+ set_property(TARGET binaryen_wasm PROPERTY CXX_STANDARD 14)
+ set_property(TARGET binaryen_wasm PROPERTY CXX_STANDARD_REQUIRED ON)
+ install(TARGETS binaryen_wasm DESTINATION ${CMAKE_INSTALL_BINDIR})
+
+ # binaryen.js JavaScript variant
add_executable(binaryen_js
- ${binaryen_js_SOURCES})
+ ${binaryen_emscripten_SOURCES})
target_link_libraries(binaryen_js wasm asmjs emscripten-optimizer passes ir cfg support wasm)
- # note that SHELL: is needed as otherwise cmake will coalesce -s link flags
- # in an incorrect way for emscripten
target_link_libraries(binaryen_js "-s WASM=0")
+ target_link_libraries(binaryen_js "-s WASM_ASYNC_COMPILATION=0")
if(${CMAKE_CXX_COMPILER_VERSION} STREQUAL "6.0.1")
# only valid with fastcomp and WASM=0
- target_link_libraries(binaryen_js "-s ELIMINATE_DUPLICATE_FUNCTIONS=1")
+ target_link_libraries(binaryen_js "-s ELIMINATE_DUPLICATE_FUNCTIONS=1")
endif()
- target_link_libraries(binaryen_js "-s WASM_ASYNC_COMPILATION=0")
target_link_libraries(binaryen_js "-s MODULARIZE_INSTANCE=1")
target_link_libraries(binaryen_js "-s NO_FILESYSTEM=0")
target_link_libraries(binaryen_js "-s NODERAWFS=0")
@@ -393,6 +411,9 @@ if(EMSCRIPTEN)
set_property(TARGET binaryen_js PROPERTY CXX_STANDARD 14)
set_property(TARGET binaryen_js PROPERTY CXX_STANDARD_REQUIRED ON)
install(TARGETS binaryen_js DESTINATION ${CMAKE_INSTALL_BINDIR})
+
+ # always emit as 'binaryen.js'
+ set_target_properties(binaryen_wasm binaryen_js PROPERTIES OUTPUT_NAME "binaryen")
endif()
# Testing
diff --git a/scripts/test/shared.py b/scripts/test/shared.py
index 1ec42bc59..7bf944097 100644
--- a/scripts/test/shared.py
+++ b/scripts/test/shared.py
@@ -184,9 +184,7 @@ WASM_REDUCE = [os.path.join(options.binaryen_bin, 'wasm-reduce')]
WASM_METADCE = [os.path.join(options.binaryen_bin, 'wasm-metadce')]
WASM_EMSCRIPTEN_FINALIZE = [os.path.join(options.binaryen_bin,
'wasm-emscripten-finalize')]
-# Due to cmake limitations, we emit binaryen_js.js (see CMakeLists.txt
-# for why).
-BINARYEN_JS = os.path.join(options.binaryen_bin, 'binaryen_js.js')
+BINARYEN_JS = os.path.join(options.binaryen_bin, 'binaryen.js')
def wrap_with_valgrind(cmd):
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js
index fa415ad0d..96562e6e0 100644
--- a/src/js/binaryen.js-post.js
+++ b/src/js/binaryen.js-post.js
@@ -29,444 +29,435 @@ function i8sToStack(i8s) {
return ret;
}
-// Types
-Module['none'] = Module['_BinaryenTypeNone']();
-Module['i32'] = Module['_BinaryenTypeInt32']();
-Module['i64'] = Module['_BinaryenTypeInt64']();
-Module['f32'] = Module['_BinaryenTypeFloat32']();
-Module['f64'] = Module['_BinaryenTypeFloat64']();
-Module['v128'] = Module['_BinaryenTypeVec128']();
-Module['anyref'] = Module['_BinaryenTypeAnyref']();
-Module['exnref'] = Module['_BinaryenTypeExnref']();
-Module['unreachable'] = Module['_BinaryenTypeUnreachable']();
-Module['auto'] = /* deprecated */ Module['undefined'] = Module['_BinaryenTypeAuto']();
+function initializeConstants() {
+
+ // Types
+ [ ['none', 'None'],
+ ['i32', 'Int32'],
+ ['i64', 'Int64'],
+ ['f32', 'Float32'],
+ ['f64', 'Float64'],
+ ['v128', 'Vec128'],
+ ['anyref', 'Anyref'],
+ ['exnref', 'Exnref'],
+ ['unreachable', 'Unreachable'],
+ ['auto', 'Auto']
+ ].forEach(function(entry) {
+ Module[entry[0]] = Module['_BinaryenType' + entry[1]]();
+ });
-Module['createType'] = function(types) {
- return preserveStack(function() {
- var array = i32sToStack(types);
- return Module['_BinaryenTypeCreate'](array, types.length);
+ // Expression ids
+ Module['ExpressionIds'] = {};
+ [ 'Invalid',
+ 'Block',
+ 'If',
+ 'Loop',
+ 'Break',
+ 'Switch',
+ 'Call',
+ 'CallIndirect',
+ 'LocalGet',
+ 'LocalSet',
+ 'GlobalGet',
+ 'GlobalSet',
+ 'Load',
+ 'Store',
+ 'Const',
+ 'Unary',
+ 'Binary',
+ 'Select',
+ 'Drop',
+ 'Return',
+ 'Host',
+ 'Nop',
+ 'Unreachable',
+ 'AtomicCmpxchg',
+ 'AtomicRMW',
+ 'AtomicWait',
+ 'AtomicNotify',
+ 'AtomicFence',
+ 'SIMDExtract',
+ 'SIMDReplace',
+ 'SIMDShuffle',
+ 'SIMDTernary',
+ 'SIMDShift',
+ 'SIMDLoad',
+ 'MemoryInit',
+ 'DataDrop',
+ 'MemoryCopy',
+ 'MemoryFill',
+ 'Try',
+ 'Throw',
+ 'Rethrow',
+ 'BrOnExn',
+ 'Push',
+ 'Pop'
+ ].forEach(function(name) {
+ Module['ExpressionIds'][name] = Module[name + 'Id'] = Module['_Binaryen' + name + 'Id']();
});
-};
-Module['expandType'] = function(ty) {
- return preserveStack(function() {
- var numTypes = Module['_BinaryenTypeArity'](ty);
- var array = stackAlloc(numTypes << 2);
- Module['_BinaryenTypeExpand'](ty, array);
- var types = [];
- for (var i = 0; i < numTypes; i++) {
- types.push(HEAPU32[(array >>> 2) + i]);
- }
- return types;
+ // External kinds
+ Module['ExternalKinds'] = {};
+ [ 'Function',
+ 'Table',
+ 'Memory',
+ 'Global',
+ 'Event'
+ ].forEach(function(name) {
+ Module['ExternalKinds'][name] = Module['External' + name] = Module['_BinaryenExternal' + name]();
});
-};
-// Expression ids
-Module['InvalidId'] = Module['_BinaryenInvalidId']();
-Module['BlockId'] = Module['_BinaryenBlockId']();
-Module['IfId'] = Module['_BinaryenIfId']();
-Module['LoopId'] = Module['_BinaryenLoopId']();
-Module['BreakId'] = Module['_BinaryenBreakId']();
-Module['SwitchId'] = Module['_BinaryenSwitchId']();
-Module['CallId'] = Module['_BinaryenCallId']();
-Module['CallIndirectId'] = Module['_BinaryenCallIndirectId']();
-Module['LocalGetId'] = Module['_BinaryenLocalGetId']();
-Module['LocalSetId'] = Module['_BinaryenLocalSetId']();
-Module['GlobalGetId'] = Module['_BinaryenGlobalGetId']();
-Module['GlobalSetId'] = Module['_BinaryenGlobalSetId']();
-Module['LoadId'] = Module['_BinaryenLoadId']();
-Module['StoreId'] = Module['_BinaryenStoreId']();
-Module['ConstId'] = Module['_BinaryenConstId']();
-Module['UnaryId'] = Module['_BinaryenUnaryId']();
-Module['BinaryId'] = Module['_BinaryenBinaryId']();
-Module['SelectId'] = Module['_BinaryenSelectId']();
-Module['DropId'] = Module['_BinaryenDropId']();
-Module['ReturnId'] = Module['_BinaryenReturnId']();
-Module['HostId'] = Module['_BinaryenHostId']();
-Module['NopId'] = Module['_BinaryenNopId']();
-Module['UnreachableId'] = Module['_BinaryenUnreachableId']();
-Module['AtomicCmpxchgId'] = Module['_BinaryenAtomicCmpxchgId']();
-Module['AtomicRMWId'] = Module['_BinaryenAtomicRMWId']();
-Module['AtomicWaitId'] = Module['_BinaryenAtomicWaitId']();
-Module['AtomicNotifyId'] = Module['_BinaryenAtomicNotifyId']();
-Module['AtomicFenceId'] = Module['_BinaryenAtomicFenceId']();
-Module['SIMDExtractId'] = Module['_BinaryenSIMDExtractId']();
-Module['SIMDReplaceId'] = Module['_BinaryenSIMDReplaceId']();
-Module['SIMDShuffleId'] = Module['_BinaryenSIMDShuffleId']();
-Module['SIMDTernaryId'] = Module['_BinaryenSIMDTernaryId']();
-Module['SIMDShiftId'] = Module['_BinaryenSIMDShiftId']();
-Module['SIMDLoadId'] = Module['_BinaryenSIMDLoadId']();
-Module['MemoryInitId'] = Module['_BinaryenMemoryInitId']();
-Module['DataDropId'] = Module['_BinaryenDataDropId']();
-Module['MemoryCopyId'] = Module['_BinaryenMemoryCopyId']();
-Module['MemoryFillId'] = Module['_BinaryenMemoryFillId']();
-Module['TryId'] = Module['_BinaryenTryId']();
-Module['ThrowId'] = Module['_BinaryenThrowId']();
-Module['RethrowId'] = Module['_BinaryenRethrowId']();
-Module['BrOnExnId'] = Module['_BinaryenBrOnExnId']();
-Module['PushId'] = Module['_BinaryenPushId']();
-Module['PopId'] = Module['_BinaryenPopId']();
-
-// External kinds
-Module['ExternalFunction'] = Module['_BinaryenExternalFunction']();
-Module['ExternalTable'] = Module['_BinaryenExternalTable']();
-Module['ExternalMemory'] = Module['_BinaryenExternalMemory']();
-Module['ExternalGlobal'] = Module['_BinaryenExternalGlobal']();
-Module['ExternalEvent'] = Module['_BinaryenExternalEvent']();
-
-// Features
-Module['Features'] = {
- 'MVP': Module['_BinaryenFeatureMVP'](),
- 'Atomics': Module['_BinaryenFeatureAtomics'](),
- 'BulkMemory': Module['_BinaryenFeatureBulkMemory'](),
- 'MutableGlobals': Module['_BinaryenFeatureMutableGlobals'](),
- 'NontrappingFPToInt': Module['_BinaryenFeatureNontrappingFPToInt'](),
- 'SignExt': Module['_BinaryenFeatureSignExt'](),
- 'SIMD128': Module['_BinaryenFeatureSIMD128'](),
- 'ExceptionHandling': Module['_BinaryenFeatureExceptionHandling'](),
- 'TailCall': Module['_BinaryenFeatureTailCall'](),
- 'ReferenceTypes': Module['_BinaryenFeatureReferenceTypes'](),
- 'All': Module['_BinaryenFeatureAll']()
-};
+ // Features
+ Module['Features'] = {};
+ [ 'MVP',
+ 'Atomics',
+ 'BulkMemory',
+ 'MutableGlobals',
+ 'NontrappingFPToInt',
+ 'SignExt',
+ 'SIMD128',
+ 'ExceptionHandling',
+ 'TailCall',
+ 'ReferenceTypes',
+ 'All'
+ ].forEach(function(name) {
+ Module['Features'][name] = Module['_BinaryenFeature' + name]();
+ });
-// Operations
-Module['ClzInt32'] = Module['_BinaryenClzInt32']();
-Module['CtzInt32'] = Module['_BinaryenCtzInt32']();
-Module['PopcntInt32'] = Module['_BinaryenPopcntInt32']();
-Module['NegFloat32'] = Module['_BinaryenNegFloat32']();
-Module['AbsFloat32'] = Module['_BinaryenAbsFloat32']();
-Module['CeilFloat32'] = Module['_BinaryenCeilFloat32']();
-Module['FloorFloat32'] = Module['_BinaryenFloorFloat32']();
-Module['TruncFloat32'] = Module['_BinaryenTruncFloat32']();
-Module['NearestFloat32'] = Module['_BinaryenNearestFloat32']();
-Module['SqrtFloat32'] = Module['_BinaryenSqrtFloat32']();
-Module['EqZInt32'] = Module['_BinaryenEqZInt32']();
-Module['ClzInt64'] = Module['_BinaryenClzInt64']();
-Module['CtzInt64'] = Module['_BinaryenCtzInt64']();
-Module['PopcntInt64'] = Module['_BinaryenPopcntInt64']();
-Module['NegFloat64'] = Module['_BinaryenNegFloat64']();
-Module['AbsFloat64'] = Module['_BinaryenAbsFloat64']();
-Module['CeilFloat64'] = Module['_BinaryenCeilFloat64']();
-Module['FloorFloat64'] = Module['_BinaryenFloorFloat64']();
-Module['TruncFloat64'] = Module['_BinaryenTruncFloat64']();
-Module['NearestFloat64'] = Module['_BinaryenNearestFloat64']();
-Module['SqrtFloat64'] = Module['_BinaryenSqrtFloat64']();
-Module['EqZInt64'] = Module['_BinaryenEqZInt64']();
-Module['ExtendSInt32'] = Module['_BinaryenExtendSInt32']();
-Module['ExtendUInt32'] = Module['_BinaryenExtendUInt32']();
-Module['WrapInt64'] = Module['_BinaryenWrapInt64']();
-Module['TruncSFloat32ToInt32'] = Module['_BinaryenTruncSFloat32ToInt32']();
-Module['TruncSFloat32ToInt64'] = Module['_BinaryenTruncSFloat32ToInt64']();
-Module['TruncUFloat32ToInt32'] = Module['_BinaryenTruncUFloat32ToInt32']();
-Module['TruncUFloat32ToInt64'] = Module['_BinaryenTruncUFloat32ToInt64']();
-Module['TruncSFloat64ToInt32'] = Module['_BinaryenTruncSFloat64ToInt32']();
-Module['TruncSFloat64ToInt64'] = Module['_BinaryenTruncSFloat64ToInt64']();
-Module['TruncUFloat64ToInt32'] = Module['_BinaryenTruncUFloat64ToInt32']();
-Module['TruncUFloat64ToInt64'] = Module['_BinaryenTruncUFloat64ToInt64']();
-Module['TruncSatSFloat32ToInt32'] = Module['_BinaryenTruncSatSFloat32ToInt32']();
-Module['TruncSatSFloat32ToInt64'] = Module['_BinaryenTruncSatSFloat32ToInt64']();
-Module['TruncSatUFloat32ToInt32'] = Module['_BinaryenTruncSatUFloat32ToInt32']();
-Module['TruncSatUFloat32ToInt64'] = Module['_BinaryenTruncSatUFloat32ToInt64']();
-Module['TruncSatSFloat64ToInt32'] = Module['_BinaryenTruncSatSFloat64ToInt32']();
-Module['TruncSatSFloat64ToInt64'] = Module['_BinaryenTruncSatSFloat64ToInt64']();
-Module['TruncSatUFloat64ToInt32'] = Module['_BinaryenTruncSatUFloat64ToInt32']();
-Module['TruncSatUFloat64ToInt64'] = Module['_BinaryenTruncSatUFloat64ToInt64']();
-Module['ReinterpretFloat32'] = Module['_BinaryenReinterpretFloat32']();
-Module['ReinterpretFloat64'] = Module['_BinaryenReinterpretFloat64']();
-Module['ConvertSInt32ToFloat32'] = Module['_BinaryenConvertSInt32ToFloat32']();
-Module['ConvertSInt32ToFloat64'] = Module['_BinaryenConvertSInt32ToFloat64']();
-Module['ConvertUInt32ToFloat32'] = Module['_BinaryenConvertUInt32ToFloat32']();
-Module['ConvertUInt32ToFloat64'] = Module['_BinaryenConvertUInt32ToFloat64']();
-Module['ConvertSInt64ToFloat32'] = Module['_BinaryenConvertSInt64ToFloat32']();
-Module['ConvertSInt64ToFloat64'] = Module['_BinaryenConvertSInt64ToFloat64']();
-Module['ConvertUInt64ToFloat32'] = Module['_BinaryenConvertUInt64ToFloat32']();
-Module['ConvertUInt64ToFloat64'] = Module['_BinaryenConvertUInt64ToFloat64']();
-Module['PromoteFloat32'] = Module['_BinaryenPromoteFloat32']();
-Module['DemoteFloat64'] = Module['_BinaryenDemoteFloat64']();
-Module['ReinterpretInt32'] = Module['_BinaryenReinterpretInt32']();
-Module['ReinterpretInt64'] = Module['_BinaryenReinterpretInt64']();
-Module['ExtendS8Int32'] = Module['_BinaryenExtendS8Int32']();
-Module['ExtendS16Int32'] = Module['_BinaryenExtendS16Int32']();
-Module['ExtendS8Int64'] = Module['_BinaryenExtendS8Int64']();
-Module['ExtendS16Int64'] = Module['_BinaryenExtendS16Int64']();
-Module['ExtendS32Int64'] = Module['_BinaryenExtendS32Int64']();
-Module['AddInt32'] = Module['_BinaryenAddInt32']();
-Module['SubInt32'] = Module['_BinaryenSubInt32']();
-Module['MulInt32'] = Module['_BinaryenMulInt32']();
-Module['DivSInt32'] = Module['_BinaryenDivSInt32']();
-Module['DivUInt32'] = Module['_BinaryenDivUInt32']();
-Module['RemSInt32'] = Module['_BinaryenRemSInt32']();
-Module['RemUInt32'] = Module['_BinaryenRemUInt32']();
-Module['AndInt32'] = Module['_BinaryenAndInt32']();
-Module['OrInt32'] = Module['_BinaryenOrInt32']();
-Module['XorInt32'] = Module['_BinaryenXorInt32']();
-Module['ShlInt32'] = Module['_BinaryenShlInt32']();
-Module['ShrUInt32'] = Module['_BinaryenShrUInt32']();
-Module['ShrSInt32'] = Module['_BinaryenShrSInt32']();
-Module['RotLInt32'] = Module['_BinaryenRotLInt32']();
-Module['RotRInt32'] = Module['_BinaryenRotRInt32']();
-Module['EqInt32'] = Module['_BinaryenEqInt32']();
-Module['NeInt32'] = Module['_BinaryenNeInt32']();
-Module['LtSInt32'] = Module['_BinaryenLtSInt32']();
-Module['LtUInt32'] = Module['_BinaryenLtUInt32']();
-Module['LeSInt32'] = Module['_BinaryenLeSInt32']();
-Module['LeUInt32'] = Module['_BinaryenLeUInt32']();
-Module['GtSInt32'] = Module['_BinaryenGtSInt32']();
-Module['GtUInt32'] = Module['_BinaryenGtUInt32']();
-Module['GeSInt32'] = Module['_BinaryenGeSInt32']();
-Module['GeUInt32'] = Module['_BinaryenGeUInt32']();
-Module['AddInt64'] = Module['_BinaryenAddInt64']();
-Module['SubInt64'] = Module['_BinaryenSubInt64']();
-Module['MulInt64'] = Module['_BinaryenMulInt64']();
-Module['DivSInt64'] = Module['_BinaryenDivSInt64']();
-Module['DivUInt64'] = Module['_BinaryenDivUInt64']();
-Module['RemSInt64'] = Module['_BinaryenRemSInt64']();
-Module['RemUInt64'] = Module['_BinaryenRemUInt64']();
-Module['AndInt64'] = Module['_BinaryenAndInt64']();
-Module['OrInt64'] = Module['_BinaryenOrInt64']();
-Module['XorInt64'] = Module['_BinaryenXorInt64']();
-Module['ShlInt64'] = Module['_BinaryenShlInt64']();
-Module['ShrUInt64'] = Module['_BinaryenShrUInt64']();
-Module['ShrSInt64'] = Module['_BinaryenShrSInt64']();
-Module['RotLInt64'] = Module['_BinaryenRotLInt64']();
-Module['RotRInt64'] = Module['_BinaryenRotRInt64']();
-Module['EqInt64'] = Module['_BinaryenEqInt64']();
-Module['NeInt64'] = Module['_BinaryenNeInt64']();
-Module['LtSInt64'] = Module['_BinaryenLtSInt64']();
-Module['LtUInt64'] = Module['_BinaryenLtUInt64']();
-Module['LeSInt64'] = Module['_BinaryenLeSInt64']();
-Module['LeUInt64'] = Module['_BinaryenLeUInt64']();
-Module['GtSInt64'] = Module['_BinaryenGtSInt64']();
-Module['GtUInt64'] = Module['_BinaryenGtUInt64']();
-Module['GeSInt64'] = Module['_BinaryenGeSInt64']();
-Module['GeUInt64'] = Module['_BinaryenGeUInt64']();
-Module['AddFloat32'] = Module['_BinaryenAddFloat32']();
-Module['SubFloat32'] = Module['_BinaryenSubFloat32']();
-Module['MulFloat32'] = Module['_BinaryenMulFloat32']();
-Module['DivFloat32'] = Module['_BinaryenDivFloat32']();
-Module['CopySignFloat32'] = Module['_BinaryenCopySignFloat32']();
-Module['MinFloat32'] = Module['_BinaryenMinFloat32']();
-Module['MaxFloat32'] = Module['_BinaryenMaxFloat32']();
-Module['EqFloat32'] = Module['_BinaryenEqFloat32']();
-Module['NeFloat32'] = Module['_BinaryenNeFloat32']();
-Module['LtFloat32'] = Module['_BinaryenLtFloat32']();
-Module['LeFloat32'] = Module['_BinaryenLeFloat32']();
-Module['GtFloat32'] = Module['_BinaryenGtFloat32']();
-Module['GeFloat32'] = Module['_BinaryenGeFloat32']();
-Module['AddFloat64'] = Module['_BinaryenAddFloat64']();
-Module['SubFloat64'] = Module['_BinaryenSubFloat64']();
-Module['MulFloat64'] = Module['_BinaryenMulFloat64']();
-Module['DivFloat64'] = Module['_BinaryenDivFloat64']();
-Module['CopySignFloat64'] = Module['_BinaryenCopySignFloat64']();
-Module['MinFloat64'] = Module['_BinaryenMinFloat64']();
-Module['MaxFloat64'] = Module['_BinaryenMaxFloat64']();
-Module['EqFloat64'] = Module['_BinaryenEqFloat64']();
-Module['NeFloat64'] = Module['_BinaryenNeFloat64']();
-Module['LtFloat64'] = Module['_BinaryenLtFloat64']();
-Module['LeFloat64'] = Module['_BinaryenLeFloat64']();
-Module['GtFloat64'] = Module['_BinaryenGtFloat64']();
-Module['GeFloat64'] = Module['_BinaryenGeFloat64']();
-Module['MemorySize'] = Module['_BinaryenMemorySize']();
-Module['MemoryGrow'] = Module['_BinaryenMemoryGrow']();
-Module['AtomicRMWAdd'] = Module['_BinaryenAtomicRMWAdd']();
-Module['AtomicRMWSub'] = Module['_BinaryenAtomicRMWSub']();
-Module['AtomicRMWAnd'] = Module['_BinaryenAtomicRMWAnd']();
-Module['AtomicRMWOr'] = Module['_BinaryenAtomicRMWOr']();
-Module['AtomicRMWXor'] = Module['_BinaryenAtomicRMWXor']();
-Module['AtomicRMWXchg'] = Module['_BinaryenAtomicRMWXchg']();
-Module['SplatVecI8x16'] = Module['_BinaryenSplatVecI8x16']();
-Module['ExtractLaneSVecI8x16'] = Module['_BinaryenExtractLaneSVecI8x16']();
-Module['ExtractLaneUVecI8x16'] = Module['_BinaryenExtractLaneUVecI8x16']();
-Module['ReplaceLaneVecI8x16'] = Module['_BinaryenReplaceLaneVecI8x16']();
-Module['SplatVecI16x8'] = Module['_BinaryenSplatVecI16x8']();
-Module['ExtractLaneSVecI16x8'] = Module['_BinaryenExtractLaneSVecI16x8']();
-Module['ExtractLaneUVecI16x8'] = Module['_BinaryenExtractLaneUVecI16x8']();
-Module['ReplaceLaneVecI16x8'] = Module['_BinaryenReplaceLaneVecI16x8']();
-Module['SplatVecI32x4'] = Module['_BinaryenSplatVecI32x4']();
-Module['ExtractLaneVecI32x4'] = Module['_BinaryenExtractLaneVecI32x4']();
-Module['ReplaceLaneVecI32x4'] = Module['_BinaryenReplaceLaneVecI32x4']();
-Module['SplatVecI64x2'] = Module['_BinaryenSplatVecI64x2']();
-Module['ExtractLaneVecI64x2'] = Module['_BinaryenExtractLaneVecI64x2']();
-Module['ReplaceLaneVecI64x2'] = Module['_BinaryenReplaceLaneVecI64x2']();
-Module['SplatVecF32x4'] = Module['_BinaryenSplatVecF32x4']();
-Module['ExtractLaneVecF32x4'] = Module['_BinaryenExtractLaneVecF32x4']();
-Module['ReplaceLaneVecF32x4'] = Module['_BinaryenReplaceLaneVecF32x4']();
-Module['SplatVecF64x2'] = Module['_BinaryenSplatVecF64x2']();
-Module['ExtractLaneVecF64x2'] = Module['_BinaryenExtractLaneVecF64x2']();
-Module['ReplaceLaneVecF64x2'] = Module['_BinaryenReplaceLaneVecF64x2']();
-Module['EqVecI8x16'] = Module['_BinaryenEqVecI8x16']();
-Module['NeVecI8x16'] = Module['_BinaryenNeVecI8x16']();
-Module['LtSVecI8x16'] = Module['_BinaryenLtSVecI8x16']();
-Module['LtUVecI8x16'] = Module['_BinaryenLtUVecI8x16']();
-Module['GtSVecI8x16'] = Module['_BinaryenGtSVecI8x16']();
-Module['GtUVecI8x16'] = Module['_BinaryenGtUVecI8x16']();
-Module['LeSVecI8x16'] = Module['_BinaryenLeSVecI8x16']();
-Module['LeUVecI8x16'] = Module['_BinaryenLeUVecI8x16']();
-Module['GeSVecI8x16'] = Module['_BinaryenGeSVecI8x16']();
-Module['GeUVecI8x16'] = Module['_BinaryenGeUVecI8x16']();
-Module['EqVecI16x8'] = Module['_BinaryenEqVecI16x8']();
-Module['NeVecI16x8'] = Module['_BinaryenNeVecI16x8']();
-Module['LtSVecI16x8'] = Module['_BinaryenLtSVecI16x8']();
-Module['LtUVecI16x8'] = Module['_BinaryenLtUVecI16x8']();
-Module['GtSVecI16x8'] = Module['_BinaryenGtSVecI16x8']();
-Module['GtUVecI16x8'] = Module['_BinaryenGtUVecI16x8']();
-Module['LeSVecI16x8'] = Module['_BinaryenLeSVecI16x8']();
-Module['LeUVecI16x8'] = Module['_BinaryenLeUVecI16x8']();
-Module['GeSVecI16x8'] = Module['_BinaryenGeSVecI16x8']();
-Module['GeUVecI16x8'] = Module['_BinaryenGeUVecI16x8']();
-Module['EqVecI32x4'] = Module['_BinaryenEqVecI32x4']();
-Module['NeVecI32x4'] = Module['_BinaryenNeVecI32x4']();
-Module['LtSVecI32x4'] = Module['_BinaryenLtSVecI32x4']();
-Module['LtUVecI32x4'] = Module['_BinaryenLtUVecI32x4']();
-Module['GtSVecI32x4'] = Module['_BinaryenGtSVecI32x4']();
-Module['GtUVecI32x4'] = Module['_BinaryenGtUVecI32x4']();
-Module['LeSVecI32x4'] = Module['_BinaryenLeSVecI32x4']();
-Module['LeUVecI32x4'] = Module['_BinaryenLeUVecI32x4']();
-Module['GeSVecI32x4'] = Module['_BinaryenGeSVecI32x4']();
-Module['GeUVecI32x4'] = Module['_BinaryenGeUVecI32x4']();
-Module['EqVecF32x4'] = Module['_BinaryenEqVecF32x4']();
-Module['NeVecF32x4'] = Module['_BinaryenNeVecF32x4']();
-Module['LtVecF32x4'] = Module['_BinaryenLtVecF32x4']();
-Module['GtVecF32x4'] = Module['_BinaryenGtVecF32x4']();
-Module['LeVecF32x4'] = Module['_BinaryenLeVecF32x4']();
-Module['GeVecF32x4'] = Module['_BinaryenGeVecF32x4']();
-Module['EqVecF64x2'] = Module['_BinaryenGeVecF32x4']();
-Module['NeVecF64x2'] = Module['_BinaryenNeVecF64x2']();
-Module['LtVecF64x2'] = Module['_BinaryenLtVecF64x2']();
-Module['GtVecF64x2'] = Module['_BinaryenGtVecF64x2']();
-Module['LeVecF64x2'] = Module['_BinaryenLeVecF64x2']();
-Module['GeVecF64x2'] = Module['_BinaryenGeVecF64x2']();
-Module['NotVec128'] = Module['_BinaryenNotVec128']();
-Module['AndVec128'] = Module['_BinaryenAndVec128']();
-Module['OrVec128'] = Module['_BinaryenOrVec128']();
-Module['XorVec128'] = Module['_BinaryenXorVec128']();
-Module['AndNotVec128'] = Module['_BinaryenAndNotVec128']();
-Module['BitselectVec128'] = Module['_BinaryenBitselectVec128']();
-Module['NegVecI8x16'] = Module['_BinaryenNegVecI8x16']();
-Module['AnyTrueVecI8x16'] = Module['_BinaryenAnyTrueVecI8x16']();
-Module['AllTrueVecI8x16'] = Module['_BinaryenAllTrueVecI8x16']();
-Module['ShlVecI8x16'] = Module['_BinaryenShlVecI8x16']();
-Module['ShrSVecI8x16'] = Module['_BinaryenShrSVecI8x16']();
-Module['ShrUVecI8x16'] = Module['_BinaryenShrUVecI8x16']();
-Module['AddVecI8x16'] = Module['_BinaryenAddVecI8x16']();
-Module['AddSatSVecI8x16'] = Module['_BinaryenAddSatSVecI8x16']();
-Module['AddSatUVecI8x16'] = Module['_BinaryenAddSatUVecI8x16']();
-Module['SubVecI8x16'] = Module['_BinaryenSubVecI8x16']();
-Module['SubSatSVecI8x16'] = Module['_BinaryenSubSatSVecI8x16']();
-Module['SubSatUVecI8x16'] = Module['_BinaryenSubSatUVecI8x16']();
-Module['MulVecI8x16'] = Module['_BinaryenMulVecI8x16']();
-Module['MinSVecI8x16'] = Module['_BinaryenMinSVecI8x16']();
-Module['MinUVecI8x16'] = Module['_BinaryenMinUVecI8x16']();
-Module['MaxSVecI8x16'] = Module['_BinaryenMaxSVecI8x16']();
-Module['MaxUVecI8x16'] = Module['_BinaryenMaxUVecI8x16']();
-Module['AvgrUVecI8x16'] = Module['_BinaryenAvgrUVecI8x16']();
-Module['NegVecI16x8'] = Module['_BinaryenNegVecI16x8']();
-Module['AnyTrueVecI16x8'] = Module['_BinaryenAnyTrueVecI16x8']();
-Module['AllTrueVecI16x8'] = Module['_BinaryenAllTrueVecI16x8']();
-Module['ShlVecI16x8'] = Module['_BinaryenShlVecI16x8']();
-Module['ShrSVecI16x8'] = Module['_BinaryenShrSVecI16x8']();
-Module['ShrUVecI16x8'] = Module['_BinaryenShrUVecI16x8']();
-Module['AddVecI16x8'] = Module['_BinaryenAddVecI16x8']();
-Module['AddSatSVecI16x8'] = Module['_BinaryenAddSatSVecI16x8']();
-Module['AddSatUVecI16x8'] = Module['_BinaryenAddSatUVecI16x8']();
-Module['SubVecI16x8'] = Module['_BinaryenSubVecI16x8']();
-Module['SubSatSVecI16x8'] = Module['_BinaryenSubSatSVecI16x8']();
-Module['SubSatUVecI16x8'] = Module['_BinaryenSubSatUVecI16x8']();
-Module['MulVecI16x8'] = Module['_BinaryenMulVecI16x8']();
-Module['MinSVecI16x8'] = Module['_BinaryenMinSVecI16x8']();
-Module['MinUVecI16x8'] = Module['_BinaryenMinUVecI16x8']();
-Module['MaxSVecI16x8'] = Module['_BinaryenMaxSVecI16x8']();
-Module['MaxUVecI16x8'] = Module['_BinaryenMaxUVecI16x8']();
-Module['AvgrUVecI16x8'] = Module['_BinaryenAvgrUVecI16x8']();
-Module['DotSVecI16x8ToVecI32x4'] = Module['_BinaryenDotSVecI16x8ToVecI32x4']();
-Module['NegVecI32x4'] = Module['_BinaryenNegVecI32x4']();
-Module['AnyTrueVecI32x4'] = Module['_BinaryenAnyTrueVecI32x4']();
-Module['AllTrueVecI32x4'] = Module['_BinaryenAllTrueVecI32x4']();
-Module['ShlVecI32x4'] = Module['_BinaryenShlVecI32x4']();
-Module['ShrSVecI32x4'] = Module['_BinaryenShrSVecI32x4']();
-Module['ShrUVecI32x4'] = Module['_BinaryenShrUVecI32x4']();
-Module['AddVecI32x4'] = Module['_BinaryenAddVecI32x4']();
-Module['SubVecI32x4'] = Module['_BinaryenSubVecI32x4']();
-Module['MulVecI32x4'] = Module['_BinaryenMulVecI32x4']();
-Module['MinSVecI32x4'] = Module['_BinaryenMinSVecI32x4']();
-Module['MinUVecI32x4'] = Module['_BinaryenMinUVecI32x4']();
-Module['MaxSVecI32x4'] = Module['_BinaryenMaxSVecI32x4']();
-Module['MaxUVecI32x4'] = Module['_BinaryenMaxUVecI32x4']();
-Module['NegVecI64x2'] = Module['_BinaryenNegVecI64x2']();
-Module['AnyTrueVecI64x2'] = Module['_BinaryenAnyTrueVecI64x2']();
-Module['AllTrueVecI64x2'] = Module['_BinaryenAllTrueVecI64x2']();
-Module['ShlVecI64x2'] = Module['_BinaryenShlVecI64x2']();
-Module['ShrSVecI64x2'] = Module['_BinaryenShrSVecI64x2']();
-Module['ShrUVecI64x2'] = Module['_BinaryenShrUVecI64x2']();
-Module['AddVecI64x2'] = Module['_BinaryenAddVecI64x2']();
-Module['SubVecI64x2'] = Module['_BinaryenSubVecI64x2']();
-Module['AbsVecF32x4'] = Module['_BinaryenAbsVecF32x4']();
-Module['NegVecF32x4'] = Module['_BinaryenNegVecF32x4']();
-Module['SqrtVecF32x4'] = Module['_BinaryenSqrtVecF32x4']();
-Module['QFMAVecF32x4'] = Module['_BinaryenQFMAVecF32x4']();
-Module['QFMSVecF32x4'] = Module['_BinaryenQFMSVecF32x4']();
-Module['AddVecF32x4'] = Module['_BinaryenAddVecF32x4']();
-Module['SubVecF32x4'] = Module['_BinaryenSubVecF32x4']();
-Module['MulVecF32x4'] = Module['_BinaryenMulVecF32x4']();
-Module['DivVecF32x4'] = Module['_BinaryenDivVecF32x4']();
-Module['MinVecF32x4'] = Module['_BinaryenMinVecF32x4']();
-Module['MaxVecF32x4'] = Module['_BinaryenMaxVecF32x4']();
-Module['AbsVecF64x2'] = Module['_BinaryenAbsVecF64x2']();
-Module['NegVecF64x2'] = Module['_BinaryenNegVecF64x2']();
-Module['SqrtVecF64x2'] = Module['_BinaryenSqrtVecF64x2']();
-Module['QFMAVecF64x2'] = Module['_BinaryenQFMAVecF64x2']();
-Module['QFMSVecF64x2'] = Module['_BinaryenQFMSVecF64x2']();
-Module['AddVecF64x2'] = Module['_BinaryenAddVecF64x2']();
-Module['SubVecF64x2'] = Module['_BinaryenSubVecF64x2']();
-Module['MulVecF64x2'] = Module['_BinaryenMulVecF64x2']();
-Module['DivVecF64x2'] = Module['_BinaryenDivVecF64x2']();
-Module['MinVecF64x2'] = Module['_BinaryenMinVecF64x2']();
-Module['MaxVecF64x2'] = Module['_BinaryenMaxVecF64x2']();
-Module['TruncSatSVecF32x4ToVecI32x4'] = Module['_BinaryenTruncSatSVecF32x4ToVecI32x4']();
-Module['TruncSatUVecF32x4ToVecI32x4'] = Module['_BinaryenTruncSatUVecF32x4ToVecI32x4']();
-Module['TruncSatSVecF64x2ToVecI64x2'] = Module['_BinaryenTruncSatSVecF64x2ToVecI64x2']();
-Module['TruncSatUVecF64x2ToVecI64x2'] = Module['_BinaryenTruncSatUVecF64x2ToVecI64x2']();
-Module['ConvertSVecI32x4ToVecF32x4'] = Module['_BinaryenConvertSVecI32x4ToVecF32x4']();
-Module['ConvertUVecI32x4ToVecF32x4'] = Module['_BinaryenConvertUVecI32x4ToVecF32x4']();
-Module['ConvertSVecI64x2ToVecF64x2'] = Module['_BinaryenConvertSVecI64x2ToVecF64x2']();
-Module['ConvertUVecI64x2ToVecF64x2'] = Module['_BinaryenConvertUVecI64x2ToVecF64x2']();
-Module['LoadSplatVec8x16'] = Module['_BinaryenLoadSplatVec8x16']();
-Module['LoadSplatVec16x8'] = Module['_BinaryenLoadSplatVec16x8']();
-Module['LoadSplatVec32x4'] = Module['_BinaryenLoadSplatVec32x4']();
-Module['LoadSplatVec64x2'] = Module['_BinaryenLoadSplatVec64x2']();
-Module['LoadExtSVec8x8ToVecI16x8'] = Module['_BinaryenLoadExtSVec8x8ToVecI16x8']();
-Module['LoadExtUVec8x8ToVecI16x8'] = Module['_BinaryenLoadExtUVec8x8ToVecI16x8']();
-Module['LoadExtSVec16x4ToVecI32x4'] = Module['_BinaryenLoadExtSVec16x4ToVecI32x4']();
-Module['LoadExtUVec16x4ToVecI32x4'] = Module['_BinaryenLoadExtUVec16x4ToVecI32x4']();
-Module['LoadExtSVec32x2ToVecI64x2'] = Module['_BinaryenLoadExtSVec32x2ToVecI64x2']();
-Module['LoadExtUVec32x2ToVecI64x2'] = Module['_BinaryenLoadExtUVec32x2ToVecI64x2']();
-Module['NarrowSVecI16x8ToVecI8x16'] = Module['_BinaryenNarrowSVecI16x8ToVecI8x16']();
-Module['NarrowUVecI16x8ToVecI8x16'] = Module['_BinaryenNarrowUVecI16x8ToVecI8x16']();
-Module['NarrowSVecI32x4ToVecI16x8'] = Module['_BinaryenNarrowSVecI32x4ToVecI16x8']();
-Module['NarrowUVecI32x4ToVecI16x8'] = Module['_BinaryenNarrowUVecI32x4ToVecI16x8']();
-Module['WidenLowSVecI8x16ToVecI16x8'] = Module['_BinaryenWidenLowSVecI8x16ToVecI16x8']();
-Module['WidenHighSVecI8x16ToVecI16x8'] = Module['_BinaryenWidenHighSVecI8x16ToVecI16x8']();
-Module['WidenLowUVecI8x16ToVecI16x8'] = Module['_BinaryenWidenLowUVecI8x16ToVecI16x8']();
-Module['WidenHighUVecI8x16ToVecI16x8'] = Module['_BinaryenWidenHighUVecI8x16ToVecI16x8']();
-Module['WidenLowSVecI16x8ToVecI32x4'] = Module['_BinaryenWidenLowSVecI16x8ToVecI32x4']();
-Module['WidenHighSVecI16x8ToVecI32x4'] = Module['_BinaryenWidenHighSVecI16x8ToVecI32x4']();
-Module['WidenLowUVecI16x8ToVecI32x4'] = Module['_BinaryenWidenLowUVecI16x8ToVecI32x4']();
-Module['WidenHighUVecI16x8ToVecI32x4'] = Module['_BinaryenWidenHighUVecI16x8ToVecI32x4']();
-Module['SwizzleVec8x16'] = Module['_BinaryenSwizzleVec8x16']();
-
-// The size of a single literal in memory as used in Const creation,
-// which is a little different: we don't want users to need to make
-// their own Literals, as the C API handles them by value, which means
-// we would leak them. Instead, Const creation is fused together with
-// an intermediate stack allocation of this size to pass the value.
-var sizeOfLiteral = _BinaryenSizeofLiteral();
+ // Operations
+ Module['Operations'] = {};
+ [ 'ClzInt32',
+ 'CtzInt32',
+ 'PopcntInt32',
+ 'NegFloat32',
+ 'AbsFloat32',
+ 'CeilFloat32',
+ 'FloorFloat32',
+ 'TruncFloat32',
+ 'NearestFloat32',
+ 'SqrtFloat32',
+ 'EqZInt32',
+ 'ClzInt64',
+ 'CtzInt64',
+ 'PopcntInt64',
+ 'NegFloat64',
+ 'AbsFloat64',
+ 'CeilFloat64',
+ 'FloorFloat64',
+ 'TruncFloat64',
+ 'NearestFloat64',
+ 'SqrtFloat64',
+ 'EqZInt64',
+ 'ExtendSInt32',
+ 'ExtendUInt32',
+ 'WrapInt64',
+ 'TruncSFloat32ToInt32',
+ 'TruncSFloat32ToInt64',
+ 'TruncUFloat32ToInt32',
+ 'TruncUFloat32ToInt64',
+ 'TruncSFloat64ToInt32',
+ 'TruncSFloat64ToInt64',
+ 'TruncUFloat64ToInt32',
+ 'TruncUFloat64ToInt64',
+ 'TruncSatSFloat32ToInt32',
+ 'TruncSatSFloat32ToInt64',
+ 'TruncSatUFloat32ToInt32',
+ 'TruncSatUFloat32ToInt64',
+ 'TruncSatSFloat64ToInt32',
+ 'TruncSatSFloat64ToInt64',
+ 'TruncSatUFloat64ToInt32',
+ 'TruncSatUFloat64ToInt64',
+ 'ReinterpretFloat32',
+ 'ReinterpretFloat64',
+ 'ConvertSInt32ToFloat32',
+ 'ConvertSInt32ToFloat64',
+ 'ConvertUInt32ToFloat32',
+ 'ConvertUInt32ToFloat64',
+ 'ConvertSInt64ToFloat32',
+ 'ConvertSInt64ToFloat64',
+ 'ConvertUInt64ToFloat32',
+ 'ConvertUInt64ToFloat64',
+ 'PromoteFloat32',
+ 'DemoteFloat64',
+ 'ReinterpretInt32',
+ 'ReinterpretInt64',
+ 'ExtendS8Int32',
+ 'ExtendS16Int32',
+ 'ExtendS8Int64',
+ 'ExtendS16Int64',
+ 'ExtendS32Int64',
+ 'AddInt32',
+ 'SubInt32',
+ 'MulInt32',
+ 'DivSInt32',
+ 'DivUInt32',
+ 'RemSInt32',
+ 'RemUInt32',
+ 'AndInt32',
+ 'OrInt32',
+ 'XorInt32',
+ 'ShlInt32',
+ 'ShrUInt32',
+ 'ShrSInt32',
+ 'RotLInt32',
+ 'RotRInt32',
+ 'EqInt32',
+ 'NeInt32',
+ 'LtSInt32',
+ 'LtUInt32',
+ 'LeSInt32',
+ 'LeUInt32',
+ 'GtSInt32',
+ 'GtUInt32',
+ 'GeSInt32',
+ 'GeUInt32',
+ 'AddInt64',
+ 'SubInt64',
+ 'MulInt64',
+ 'DivSInt64',
+ 'DivUInt64',
+ 'RemSInt64',
+ 'RemUInt64',
+ 'AndInt64',
+ 'OrInt64',
+ 'XorInt64',
+ 'ShlInt64',
+ 'ShrUInt64',
+ 'ShrSInt64',
+ 'RotLInt64',
+ 'RotRInt64',
+ 'EqInt64',
+ 'NeInt64',
+ 'LtSInt64',
+ 'LtUInt64',
+ 'LeSInt64',
+ 'LeUInt64',
+ 'GtSInt64',
+ 'GtUInt64',
+ 'GeSInt64',
+ 'GeUInt64',
+ 'AddFloat32',
+ 'SubFloat32',
+ 'MulFloat32',
+ 'DivFloat32',
+ 'CopySignFloat32',
+ 'MinFloat32',
+ 'MaxFloat32',
+ 'EqFloat32',
+ 'NeFloat32',
+ 'LtFloat32',
+ 'LeFloat32',
+ 'GtFloat32',
+ 'GeFloat32',
+ 'AddFloat64',
+ 'SubFloat64',
+ 'MulFloat64',
+ 'DivFloat64',
+ 'CopySignFloat64',
+ 'MinFloat64',
+ 'MaxFloat64',
+ 'EqFloat64',
+ 'NeFloat64',
+ 'LtFloat64',
+ 'LeFloat64',
+ 'GtFloat64',
+ 'GeFloat64',
+ 'MemorySize',
+ 'MemoryGrow',
+ 'AtomicRMWAdd',
+ 'AtomicRMWSub',
+ 'AtomicRMWAnd',
+ 'AtomicRMWOr',
+ 'AtomicRMWXor',
+ 'AtomicRMWXchg',
+ 'SplatVecI8x16',
+ 'ExtractLaneSVecI8x16',
+ 'ExtractLaneUVecI8x16',
+ 'ReplaceLaneVecI8x16',
+ 'SplatVecI16x8',
+ 'ExtractLaneSVecI16x8',
+ 'ExtractLaneUVecI16x8',
+ 'ReplaceLaneVecI16x8',
+ 'SplatVecI32x4',
+ 'ExtractLaneVecI32x4',
+ 'ReplaceLaneVecI32x4',
+ 'SplatVecI64x2',
+ 'ExtractLaneVecI64x2',
+ 'ReplaceLaneVecI64x2',
+ 'SplatVecF32x4',
+ 'ExtractLaneVecF32x4',
+ 'ReplaceLaneVecF32x4',
+ 'SplatVecF64x2',
+ 'ExtractLaneVecF64x2',
+ 'ReplaceLaneVecF64x2',
+ 'EqVecI8x16',
+ 'NeVecI8x16',
+ 'LtSVecI8x16',
+ 'LtUVecI8x16',
+ 'GtSVecI8x16',
+ 'GtUVecI8x16',
+ 'LeSVecI8x16',
+ 'LeUVecI8x16',
+ 'GeSVecI8x16',
+ 'GeUVecI8x16',
+ 'EqVecI16x8',
+ 'NeVecI16x8',
+ 'LtSVecI16x8',
+ 'LtUVecI16x8',
+ 'GtSVecI16x8',
+ 'GtUVecI16x8',
+ 'LeSVecI16x8',
+ 'LeUVecI16x8',
+ 'GeSVecI16x8',
+ 'GeUVecI16x8',
+ 'EqVecI32x4',
+ 'NeVecI32x4',
+ 'LtSVecI32x4',
+ 'LtUVecI32x4',
+ 'GtSVecI32x4',
+ 'GtUVecI32x4',
+ 'LeSVecI32x4',
+ 'LeUVecI32x4',
+ 'GeSVecI32x4',
+ 'GeUVecI32x4',
+ 'EqVecF32x4',
+ 'NeVecF32x4',
+ 'LtVecF32x4',
+ 'GtVecF32x4',
+ 'LeVecF32x4',
+ 'GeVecF32x4',
+ 'EqVecF64x2',
+ 'NeVecF64x2',
+ 'LtVecF64x2',
+ 'GtVecF64x2',
+ 'LeVecF64x2',
+ 'GeVecF64x2',
+ 'NotVec128',
+ 'AndVec128',
+ 'OrVec128',
+ 'XorVec128',
+ 'AndNotVec128',
+ 'BitselectVec128',
+ 'NegVecI8x16',
+ 'AnyTrueVecI8x16',
+ 'AllTrueVecI8x16',
+ 'ShlVecI8x16',
+ 'ShrSVecI8x16',
+ 'ShrUVecI8x16',
+ 'AddVecI8x16',
+ 'AddSatSVecI8x16',
+ 'AddSatUVecI8x16',
+ 'SubVecI8x16',
+ 'SubSatSVecI8x16',
+ 'SubSatUVecI8x16',
+ 'MulVecI8x16',
+ 'MinSVecI8x16',
+ 'MinUVecI8x16',
+ 'MaxSVecI8x16',
+ 'MaxUVecI8x16',
+ 'AvgrUVecI8x16',
+ 'NegVecI16x8',
+ 'AnyTrueVecI16x8',
+ 'AllTrueVecI16x8',
+ 'ShlVecI16x8',
+ 'ShrSVecI16x8',
+ 'ShrUVecI16x8',
+ 'AddVecI16x8',
+ 'AddSatSVecI16x8',
+ 'AddSatUVecI16x8',
+ 'SubVecI16x8',
+ 'SubSatSVecI16x8',
+ 'SubSatUVecI16x8',
+ 'MulVecI16x8',
+ 'MinSVecI16x8',
+ 'MinUVecI16x8',
+ 'MaxSVecI16x8',
+ 'MaxUVecI16x8',
+ 'AvgrUVecI16x8',
+ 'DotSVecI16x8ToVecI32x4',
+ 'NegVecI32x4',
+ 'AnyTrueVecI32x4',
+ 'AllTrueVecI32x4',
+ 'ShlVecI32x4',
+ 'ShrSVecI32x4',
+ 'ShrUVecI32x4',
+ 'AddVecI32x4',
+ 'SubVecI32x4',
+ 'MulVecI32x4',
+ 'MinSVecI32x4',
+ 'MinUVecI32x4',
+ 'MaxSVecI32x4',
+ 'MaxUVecI32x4',
+ 'NegVecI64x2',
+ 'AnyTrueVecI64x2',
+ 'AllTrueVecI64x2',
+ 'ShlVecI64x2',
+ 'ShrSVecI64x2',
+ 'ShrUVecI64x2',
+ 'AddVecI64x2',
+ 'SubVecI64x2',
+ 'AbsVecF32x4',
+ 'NegVecF32x4',
+ 'SqrtVecF32x4',
+ 'QFMAVecF32x4',
+ 'QFMSVecF32x4',
+ 'AddVecF32x4',
+ 'SubVecF32x4',
+ 'MulVecF32x4',
+ 'DivVecF32x4',
+ 'MinVecF32x4',
+ 'MaxVecF32x4',
+ 'AbsVecF64x2',
+ 'NegVecF64x2',
+ 'SqrtVecF64x2',
+ 'QFMAVecF64x2',
+ 'QFMSVecF64x2',
+ 'AddVecF64x2',
+ 'SubVecF64x2',
+ 'MulVecF64x2',
+ 'DivVecF64x2',
+ 'MinVecF64x2',
+ 'MaxVecF64x2',
+ 'TruncSatSVecF32x4ToVecI32x4',
+ 'TruncSatUVecF32x4ToVecI32x4',
+ 'TruncSatSVecF64x2ToVecI64x2',
+ 'TruncSatUVecF64x2ToVecI64x2',
+ 'ConvertSVecI32x4ToVecF32x4',
+ 'ConvertUVecI32x4ToVecF32x4',
+ 'ConvertSVecI64x2ToVecF64x2',
+ 'ConvertUVecI64x2ToVecF64x2',
+ 'LoadSplatVec8x16',
+ 'LoadSplatVec16x8',
+ 'LoadSplatVec32x4',
+ 'LoadSplatVec64x2',
+ 'LoadExtSVec8x8ToVecI16x8',
+ 'LoadExtUVec8x8ToVecI16x8',
+ 'LoadExtSVec16x4ToVecI32x4',
+ 'LoadExtUVec16x4ToVecI32x4',
+ 'LoadExtSVec32x2ToVecI64x2',
+ 'LoadExtUVec32x2ToVecI64x2',
+ 'NarrowSVecI16x8ToVecI8x16',
+ 'NarrowUVecI16x8ToVecI8x16',
+ 'NarrowSVecI32x4ToVecI16x8',
+ 'NarrowUVecI32x4ToVecI16x8',
+ 'WidenLowSVecI8x16ToVecI16x8',
+ 'WidenHighSVecI8x16ToVecI16x8',
+ 'WidenLowUVecI8x16ToVecI16x8',
+ 'WidenHighUVecI8x16ToVecI16x8',
+ 'WidenLowSVecI16x8ToVecI32x4',
+ 'WidenHighSVecI16x8ToVecI32x4',
+ 'WidenLowUVecI16x8ToVecI32x4',
+ 'WidenHighUVecI16x8ToVecI32x4',
+ 'SwizzleVec8x16',
+ ].forEach(function(name) {
+ Module['Operations'][name] = Module[name] = Module['_Binaryen' + name]();
+ });
+}
// 'Module' interface
Module['Module'] = function(module) {
assert(!module); // guard against incorrect old API usage
- var module = Module['_BinaryenModuleCreate']();
-
- wrapModule(module, this);
+ wrapModule(Module['_BinaryenModuleCreate'](), this);
};
// Receives a C pointer to a C Module and a JS object, and creates
@@ -480,6 +471,13 @@ function wrapModule(module, self) {
self['ptr'] = module;
+ // The size of a single literal in memory as used in Const creation,
+ // which is a little different: we don't want users to need to make
+ // their own Literals, as the C API handles them by value, which means
+ // we would leak them. Instead, Const creation is fused together with
+ // an intermediate stack allocation of this size to pass the value.
+ var sizeOfLiteral = _BinaryenSizeofLiteral();
+
// 'Expression' creation
self['block'] = function(name, children, type) {
return preserveStack(function() {
@@ -2689,6 +2687,26 @@ Module['getExpressionInfo'] = function(expr) {
}
};
+Module['createType'] = function(types) {
+ return preserveStack(function() {
+ var array = i32sToStack(types);
+ return Module['_BinaryenTypeCreate'](array, types.length);
+ });
+};
+
+Module['expandType'] = function(ty) {
+ return preserveStack(function() {
+ var numTypes = Module['_BinaryenTypeArity'](ty);
+ var array = stackAlloc(numTypes << 2);
+ Module['_BinaryenTypeExpand'](ty, array);
+ var types = [];
+ for (var i = 0; i < numTypes; i++) {
+ types.push(HEAPU32[(array >>> 2) + i]);
+ }
+ return types;
+ });
+};
+
// Obtains information about a 'Function'
Module['getFunctionInfo'] = function(func) {
return {
@@ -2813,3 +2831,55 @@ Module['exit'] = function(status) {
// a stack trace, for debuggability.
if (status != 0) throw new Error('exiting due to error: ' + status);
};
+
+// Indicates if Binaryen has been loaded and is ready
+Module['isReady'] = runtimeInitialized;
+
+// Provide a mechanism to tell when the module is ready
+//
+// if (!binaryen.isReady) await binaryen.ready;
+// ...
+//
+var pendingPromises = [];
+var initializeError = null;
+Object.defineProperty(Module, 'ready', {
+ get: function() {
+ return new Promise(function(resolve, reject) {
+ if (initializeError) {
+ reject(initializeError);
+ } else if (runtimeInitialized) {
+ resolve(Module);
+ } else {
+ pendingPromises.push({
+ resolve: resolve,
+ reject: reject
+ });
+ }
+ });
+ }
+});
+
+// Intercept the onRuntimeInitialized hook if necessary
+if (runtimeInitialized) {
+ initializeConstants();
+} else {
+ Module['onRuntimeInitialized'] = (function(super_) {
+ return function() {
+ try {
+ initializeConstants();
+ if (super_) super_();
+ Module['isReady'] = true;
+ pendingPromises.forEach(function(p) {
+ p.resolve(Module);
+ });
+ } catch (e) {
+ initializeError = e;
+ pendingPromises.forEach(function(p) {
+ p.reject(e);
+ });
+ } finally {
+ pendingPromises = [];
+ }
+ };
+ })(Module['onRuntimeInitialized']);
+}
diff --git a/test/binaryen.js/atomics.js b/test/binaryen.js/atomics.js
index d19a8e89d..1374da804 100644
--- a/test/binaryen.js/atomics.js
+++ b/test/binaryen.js/atomics.js
@@ -2,88 +2,94 @@ function assert(x) {
if (!x) throw 'error!';
}
-var module = Binaryen.parseText(`
+var wast = `
(module
(memory $0 (shared 1 1))
)
-`);
+`;
-// i32/i64.atomic.load/store
-module.addFunction("main", Binaryen.none, Binaryen.none, [], module.block("", [
- // i32
- module.i32.atomic.store(0,
- module.i32.const(0),
- module.i32.atomic.load(0,
- module.i32.const(0)
- )
- ),
- // i32 as u8
- module.i32.atomic.store8(0,
- module.i32.const(0),
- module.i32.atomic.load8_u(0,
- module.i32.const(0)
- )
- ),
- // i32 as u16
- module.i32.atomic.store16(0,
- module.i32.const(0),
- module.i32.atomic.load16_u(0,
- module.i32.const(0)
- )
- ),
- // i64
- module.i64.atomic.store(0,
- module.i32.const(0),
- module.i64.atomic.load(0,
- module.i32.const(0)
- )
- ),
- // i64 as u8
- module.i64.atomic.store8(0,
- module.i32.const(0),
- module.i64.atomic.load8_u(0,
- module.i32.const(0)
- )
- ),
- // i64 as u16
- module.i64.atomic.store16(0,
- module.i32.const(0),
- module.i64.atomic.load16_u(0,
- module.i32.const(0)
- )
- ),
- // i64 as u32
- module.i64.atomic.store32(0,
- module.i32.const(0),
- module.i64.atomic.load32_u(0,
- module.i32.const(0)
- )
- ),
- // wait and notify
- module.drop(
- module.i32.atomic.wait(
+function test() {
+ var module = Binaryen.parseText(wast);
+
+ // i32/i64.atomic.load/store
+ module.addFunction("main", Binaryen.none, Binaryen.none, [], module.block("", [
+ // i32
+ module.i32.atomic.store(0,
+ module.i32.const(0),
+ module.i32.atomic.load(0,
+ module.i32.const(0)
+ )
+ ),
+ // i32 as u8
+ module.i32.atomic.store8(0,
+ module.i32.const(0),
+ module.i32.atomic.load8_u(0,
+ module.i32.const(0)
+ )
+ ),
+ // i32 as u16
+ module.i32.atomic.store16(0,
module.i32.const(0),
+ module.i32.atomic.load16_u(0,
+ module.i32.const(0)
+ )
+ ),
+ // i64
+ module.i64.atomic.store(0,
module.i32.const(0),
- module.i64.const(0)
- )
- ),
- module.drop(
- module.i64.atomic.wait(
+ module.i64.atomic.load(0,
+ module.i32.const(0)
+ )
+ ),
+ // i64 as u8
+ module.i64.atomic.store8(0,
module.i32.const(0),
- module.i64.const(0),
- module.i64.const(0)
- )
- ),
- module.drop(
- module.atomic.notify(
+ module.i64.atomic.load8_u(0,
+ module.i32.const(0)
+ )
+ ),
+ // i64 as u16
+ module.i64.atomic.store16(0,
module.i32.const(0),
- module.i32.const(0)
- )
- ),
- // fence
- module.atomic.fence()
-]));
+ module.i64.atomic.load16_u(0,
+ module.i32.const(0)
+ )
+ ),
+ // i64 as u32
+ module.i64.atomic.store32(0,
+ module.i32.const(0),
+ module.i64.atomic.load32_u(0,
+ module.i32.const(0)
+ )
+ ),
+ // wait and notify
+ module.drop(
+ module.i32.atomic.wait(
+ module.i32.const(0),
+ module.i32.const(0),
+ module.i64.const(0)
+ )
+ ),
+ module.drop(
+ module.i64.atomic.wait(
+ module.i32.const(0),
+ module.i64.const(0),
+ module.i64.const(0)
+ )
+ ),
+ module.drop(
+ module.atomic.notify(
+ module.i32.const(0),
+ module.i32.const(0)
+ )
+ ),
+ // fence
+ module.atomic.fence()
+ ]));
+
+ module.setFeatures(Binaryen.Features.Atomics);
+ assert(module.validate());
+ console.log(module.emitText());
+}
-module.setFeatures(Binaryen.Features.Atomics);
-assert(module.validate());
-console.log(module.emitText());
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/custom-section.js b/test/binaryen.js/custom-section.js
index f61af0096..2ecd39025 100644
--- a/test/binaryen.js/custom-section.js
+++ b/test/binaryen.js/custom-section.js
@@ -2,10 +2,14 @@ function assert(x) {
if (!x) throw 'error!';
}
-Binaryen.setAPITracing(true);
-var module = new Binaryen.Module();
+function test() {
+ Binaryen.setAPITracing(true);
+ var module = new Binaryen.Module();
-module.addCustomSection("hello", [119, 111, 114, 108, 100]);
+ module.addCustomSection("hello", [119, 111, 114, 108, 100]);
-assert(module.validate());
-console.log(module.emitText());
+ assert(module.validate());
+ console.log(module.emitText());
+}
+
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/debug-info.js b/test/binaryen.js/debug-info.js
index d1634f10e..a769d8911 100644
--- a/test/binaryen.js/debug-info.js
+++ b/test/binaryen.js/debug-info.js
@@ -11,37 +11,41 @@ var wast = `
)
`;
-// Use defaults (should not emit debug info)
-console.log("=== default ===");
-console.log("debugInfo=" + Binaryen.getDebugInfo());
-var module = Binaryen.parseText(wast);
-var binary = module.emitBinary();
-module.dispose();
-module = Binaryen.readBinary(binary);
-console.log(module.emitText());
-assert(module.validate());
-module.dispose();
+function test() {
+ // Use defaults (should not emit debug info)
+ console.log("=== default ===");
+ console.log("debugInfo=" + Binaryen.getDebugInfo());
+ var module = Binaryen.parseText(wast);
+ var binary = module.emitBinary();
+ module.dispose();
+ module = Binaryen.readBinary(binary);
+ console.log(module.emitText());
+ assert(module.validate());
+ module.dispose();
-// With debug info
-console.log("=== with debug info ===");
-Binaryen.setDebugInfo(true);
-console.log("debugInfo=" + Binaryen.getDebugInfo());
-module = Binaryen.parseText(wast);
-binary = module.emitBinary();
-module.dispose();
-module = Binaryen.readBinary(binary);
-console.log(module.emitText());
-assert(module.validate());
-module.dispose();
+ // With debug info
+ console.log("=== with debug info ===");
+ Binaryen.setDebugInfo(true);
+ console.log("debugInfo=" + Binaryen.getDebugInfo());
+ module = Binaryen.parseText(wast);
+ binary = module.emitBinary();
+ module.dispose();
+ module = Binaryen.readBinary(binary);
+ console.log(module.emitText());
+ assert(module.validate());
+ module.dispose();
-// Without debug info
-console.log("=== without debug info ===");
-Binaryen.setDebugInfo(false);
-console.log("debugInfo=" + Binaryen.getDebugInfo());
-module = Binaryen.parseText(wast);
-binary = module.emitBinary();
-module.dispose();
-module = Binaryen.readBinary(binary);
-console.log(module.emitText());
-assert(module.validate());
-module.dispose();
+ // Without debug info
+ console.log("=== without debug info ===");
+ Binaryen.setDebugInfo(false);
+ console.log("debugInfo=" + Binaryen.getDebugInfo());
+ module = Binaryen.parseText(wast);
+ binary = module.emitBinary();
+ module.dispose();
+ module = Binaryen.readBinary(binary);
+ console.log(module.emitText());
+ assert(module.validate());
+ module.dispose();
+}
+
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/emit_asmjs.js b/test/binaryen.js/emit_asmjs.js
index 9d5a3966d..751712592 100644
--- a/test/binaryen.js/emit_asmjs.js
+++ b/test/binaryen.js/emit_asmjs.js
@@ -2,12 +2,16 @@ function assert(x) {
if (!x) throw 'error!';
}
-var module = new Binaryen.Module();
+function test() {
+ var module = new Binaryen.Module();
-module.addFunction("main", Binaryen.i32, Binaryen.i32, [], module.local.get(0, Binaryen.i32));
+ module.addFunction("main", Binaryen.i32, Binaryen.i32, [], module.local.get(0, Binaryen.i32));
-module.addFunctionExport("main", "main");
+ module.addFunctionExport("main", "main");
-assert(module.validate()); // should validate before calling emitAsmjs
+ assert(module.validate()); // should validate before calling emitAsmjs
-console.log(module.emitAsmjs());
+ console.log(module.emitAsmjs());
+}
+
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/event.js b/test/binaryen.js/event.js
index 3931b3440..f728e9228 100644
--- a/test/binaryen.js/event.js
+++ b/test/binaryen.js/event.js
@@ -10,26 +10,30 @@ function cleanInfo(info) {
return ret;
}
-var module = new Binaryen.Module();
-module.setFeatures(Binaryen.Features.ExceptionHandling);
+function test() {
+ var module = new Binaryen.Module();
+ module.setFeatures(Binaryen.Features.ExceptionHandling);
-var pairType = Binaryen.createType([Binaryen.i32, Binaryen.f32]);
+ var pairType = Binaryen.createType([Binaryen.i32, Binaryen.f32]);
-var event_ = module.addEvent("a-event", 0, Binaryen.i32, Binaryen.none);
+ var event_ = module.addEvent("a-event", 0, Binaryen.i32, Binaryen.none);
-console.log("GetEvent is equal: " + (event_ === module.getEvent("a-event")));
+ console.log("GetEvent is equal: " + (event_ === module.getEvent("a-event")));
-var eventInfo = Binaryen.getEventInfo(event_);
-console.log("getEventInfo=" + JSON.stringify(cleanInfo(eventInfo)));
+ var eventInfo = Binaryen.getEventInfo(event_);
+ console.log("getEventInfo=" + JSON.stringify(cleanInfo(eventInfo)));
-module.addEventExport("a-event", "a-event-exp");
-module.addEventImport("a-event-imp", "module", "base", 0, pairType, Binaryen.none);
+ module.addEventExport("a-event", "a-event-exp");
+ module.addEventImport("a-event-imp", "module", "base", 0, pairType, Binaryen.none);
-assert(module.validate());
-console.log(module.emitText());
+ assert(module.validate());
+ console.log(module.emitText());
-module.removeExport("a-event-exp");
-module.removeEvent("a-event");
+ module.removeExport("a-event-exp");
+ module.removeEvent("a-event");
-assert(module.validate());
-console.log(module.emitText());
+ assert(module.validate());
+ console.log(module.emitText());
+}
+
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/exception-handling.js b/test/binaryen.js/exception-handling.js
index 5d84c1365..6a1b32ed7 100644
--- a/test/binaryen.js/exception-handling.js
+++ b/test/binaryen.js/exception-handling.js
@@ -16,44 +16,48 @@ function stringify(expr) {
return JSON.stringify(cleanInfo(Binaryen.getExpressionInfo(expr)));
}
-var module = new Binaryen.Module();
-module.setFeatures(Binaryen.Features.ExceptionHandling);
-
-var event_ = module.addEvent("e", 0, Binaryen.i32, Binaryen.none);
-
-// (try
-// (throw $e (i32.const 0))
-// (catch
-// ;; We don't support multi-value yet. Use locals instead.
-// (local.set 0 (exnref.pop))
-// (drop
-// (block $l (result i32)
-// (rethrow
-// (br_on_exn $l $e (local.get 0))
-// )
-// )
-// )
-// )
-// )
-var throw_ = module.throw("e", [module.i32.const(0)]);
-var br_on_exn = module.br_on_exn("l", "e", module.local.get(0, Binaryen.exnref));
-var rethrow = module.rethrow(br_on_exn);
-var try_ = module.try(
- throw_,
- module.block(null, [
- module.local.set(0, module.exnref.pop()),
- module.drop(
- module.block("l", [rethrow], Binaryen.i32)
+function test() {
+ var module = new Binaryen.Module();
+ module.setFeatures(Binaryen.Features.ExceptionHandling);
+
+ var event_ = module.addEvent("e", 0, Binaryen.i32, Binaryen.none);
+
+ // (try
+ // (throw $e (i32.const 0))
+ // (catch
+ // ;; We don't support multi-value yet. Use locals instead.
+ // (local.set 0 (exnref.pop))
+ // (drop
+ // (block $l (result i32)
+ // (rethrow
+ // (br_on_exn $l $e (local.get 0))
+ // )
+ // )
+ // )
+ // )
+ // )
+ var throw_ = module.throw("e", [module.i32.const(0)]);
+ var br_on_exn = module.br_on_exn("l", "e", module.local.get(0, Binaryen.exnref));
+ var rethrow = module.rethrow(br_on_exn);
+ var try_ = module.try(
+ throw_,
+ module.block(null, [
+ module.local.set(0, module.exnref.pop()),
+ module.drop(
+ module.block("l", [rethrow], Binaryen.i32)
+ )
+ ]
)
- ]
- )
-);
-var func = module.addFunction("test", Binaryen.none, Binaryen.none, [Binaryen.exnref], try_);
-
-console.log(module.emitText());
-assert(module.validate());
-
-console.log("getExpressionInfo(throw) = " + stringify(throw_));
-console.log("getExpressionInfo(br_on_exn) = " + stringify(br_on_exn));
-console.log("getExpressionInfo(rethrow) = " + stringify(rethrow));
-console.log("getExpressionInfo(try) = " + stringify(try_));
+ );
+ var func = module.addFunction("test", Binaryen.none, Binaryen.none, [Binaryen.exnref], try_);
+
+ console.log(module.emitText());
+ assert(module.validate());
+
+ console.log("getExpressionInfo(throw) = " + stringify(throw_));
+ console.log("getExpressionInfo(br_on_exn) = " + stringify(br_on_exn));
+ console.log("getExpressionInfo(rethrow) = " + stringify(rethrow));
+ console.log("getExpressionInfo(try) = " + stringify(try_));
+}
+
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/functions.js b/test/binaryen.js/functions.js
index b2172d005..0a3aa2243 100644
--- a/test/binaryen.js/functions.js
+++ b/test/binaryen.js/functions.js
@@ -12,27 +12,31 @@ function cleanInfo(info) {
return ret;
}
-var module = new Binaryen.Module();
+function test() {
+ var module = new Binaryen.Module();
-var func = module.addFunction("a-function", Binaryen.none, Binaryen.i32, [],
- module.i32.add(
- module.i32.const(1),
- module.i32.const(2)
- )
-);
+ var func = module.addFunction("a-function", Binaryen.none, Binaryen.i32, [],
+ module.i32.add(
+ module.i32.const(1),
+ module.i32.const(2)
+ )
+ );
-console.log("GetFunction is equal: " + (func === module.getFunction("a-function")));
+ console.log("GetFunction is equal: " + (func === module.getFunction("a-function")));
-module.runPassesOnFunction(func, ["precompute"]);
+ module.runPassesOnFunction(func, ["precompute"]);
-var funcInfo = Binaryen.getFunctionInfo(func);
-console.log("getFunctionInfo=" + JSON.stringify(cleanInfo(funcInfo)));
-var expInfo = Binaryen.getExpressionInfo(funcInfo.body);
-console.log("getExpressionInfo(body)=" + JSON.stringify(cleanInfo(expInfo)));
-console.log(Binaryen.emitText(funcInfo.body));
+ var funcInfo = Binaryen.getFunctionInfo(func);
+ console.log("getFunctionInfo=" + JSON.stringify(cleanInfo(funcInfo)));
+ var expInfo = Binaryen.getExpressionInfo(funcInfo.body);
+ console.log("getExpressionInfo(body)=" + JSON.stringify(cleanInfo(expInfo)));
+ console.log(Binaryen.emitText(funcInfo.body));
-module.removeFunction("a-function");
+ module.removeFunction("a-function");
-assert(module.validate());
+ assert(module.validate());
-console.log(module.emitText());
+ console.log(module.emitText());
+}
+
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/global.js b/test/binaryen.js/global.js
index 562de7360..48571ef93 100644
--- a/test/binaryen.js/global.js
+++ b/test/binaryen.js/global.js
@@ -12,30 +12,34 @@ function cleanInfo(info) {
return ret;
}
-var module = new Binaryen.Module();
-module.setFeatures(Binaryen.Features.MVP | Binaryen.Features.MutableGlobals);
+function test() {
+ var module = new Binaryen.Module();
+ module.setFeatures(Binaryen.Features.MVP | Binaryen.Features.MutableGlobals);
-var initExpr = module.i32.const(1);
-var global = module.addGlobal("a-global", Binaryen.i32, false, initExpr);
+ var initExpr = module.i32.const(1);
+ var global = module.addGlobal("a-global", Binaryen.i32, false, initExpr);
-console.log("GetGlobal is equal: " + (global === module.getGlobal("a-global")));
+ console.log("GetGlobal is equal: " + (global === module.getGlobal("a-global")));
-var globalInfo = Binaryen.getGlobalInfo(global);
-console.log("getGlobalInfo=" + JSON.stringify(cleanInfo(globalInfo)));
+ var globalInfo = Binaryen.getGlobalInfo(global);
+ console.log("getGlobalInfo=" + JSON.stringify(cleanInfo(globalInfo)));
-var initExpInfo = Binaryen.getExpressionInfo(globalInfo.init);
-console.log("getExpressionInfo(init)=" + JSON.stringify(cleanInfo(initExpInfo)));
-console.log(Binaryen.emitText(globalInfo.init));
+ var initExpInfo = Binaryen.getExpressionInfo(globalInfo.init);
+ console.log("getExpressionInfo(init)=" + JSON.stringify(cleanInfo(initExpInfo)));
+ console.log(Binaryen.emitText(globalInfo.init));
-module.addGlobalExport("a-global", "a-global-exp");
-module.addGlobalImport("a-global-imp", "module", "base", Binaryen.i32, false);
-module.addGlobalImport("a-mut-global-imp", "module", "base", Binaryen.i32, true);
+ module.addGlobalExport("a-global", "a-global-exp");
+ module.addGlobalImport("a-global-imp", "module", "base", Binaryen.i32, false);
+ module.addGlobalImport("a-mut-global-imp", "module", "base", Binaryen.i32, true);
-assert(module.validate());
-console.log(module.emitText());
+ assert(module.validate());
+ console.log(module.emitText());
-module.removeGlobal("a-global");
-module.removeExport("a-global-exp");
+ module.removeGlobal("a-global");
+ module.removeExport("a-global-exp");
-assert(module.validate());
-console.log(module.emitText());
+ assert(module.validate());
+ console.log(module.emitText());
+}
+
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/hello-world.js b/test/binaryen.js/hello-world.js
index 414e5bfd1..d14c97912 100644
--- a/test/binaryen.js/hello-world.js
+++ b/test/binaryen.js/hello-world.js
@@ -5,49 +5,53 @@ function assert(x) {
// "hello world" type example: create a function that adds two i32s and
// returns the result
-// Create a module to work on
-var module = new Binaryen.Module();
-
-// Start to create the function, starting with the contents: Get the 0 and
-// 1 arguments, and add them, then return them
-var left = module.local.get(0, Binaryen.i32);
-var right = module.local.get(1, Binaryen.i32);
-var add = module.i32.add(left, right);
-var ret = module.return(add);
-
-// Create the add function
-// Note: no additional local variables (that's the [])
-var ii = Binaryen.createType([Binaryen.i32, Binaryen.i32])
-module.addFunction('adder', ii, Binaryen.i32, [], ret);
-
-// Export the function, so we can call it later (for simplicity we
-// export it as the same name as it has internally)
-module.addFunctionExport('adder', 'adder');
-
-// Print out the text
-console.log(module.emitText());
-
-// Optimize the module! This removes the 'return', since the
-// output of the add can just fall through
-module.optimize();
-
-// Print out the optimized module's text
-console.log('optimized:\n\n' + module.emitText());
-
-// Get the binary in typed array form
-var binary = module.emitBinary();
-console.log('binary size: ' + binary.length);
-console.log();
-assert(module.validate());
-
-// We don't need the Binaryen module anymore, so we can tell it to
-// clean itself up
-module.dispose();
-
-// Compile the binary and create an instance
-var wasm = new WebAssembly.Instance(new WebAssembly.Module(binary), {})
-console.log("exports: " + Object.keys(wasm.exports).sort().join(","));
-console.log();
-
-// Call the code!
-console.log('an addition: ' + wasm.exports.adder(40, 2));
+function test() {
+ // Create a module to work on
+ var module = new Binaryen.Module();
+
+ // Start to create the function, starting with the contents: Get the 0 and
+ // 1 arguments, and add them, then return them
+ var left = module.local.get(0, Binaryen.i32);
+ var right = module.local.get(1, Binaryen.i32);
+ var add = module.i32.add(left, right);
+ var ret = module.return(add);
+
+ // Create the add function
+ // Note: no additional local variables (that's the [])
+ var ii = Binaryen.createType([Binaryen.i32, Binaryen.i32])
+ module.addFunction('adder', ii, Binaryen.i32, [], ret);
+
+ // Export the function, so we can call it later (for simplicity we
+ // export it as the same name as it has internally)
+ module.addFunctionExport('adder', 'adder');
+
+ // Print out the text
+ console.log(module.emitText());
+
+ // Optimize the module! This removes the 'return', since the
+ // output of the add can just fall through
+ module.optimize();
+
+ // Print out the optimized module's text
+ console.log('optimized:\n\n' + module.emitText());
+
+ // Get the binary in typed array form
+ var binary = module.emitBinary();
+ console.log('binary size: ' + binary.length);
+ console.log();
+ assert(module.validate());
+
+ // We don't need the Binaryen module anymore, so we can tell it to
+ // clean itself up
+ module.dispose();
+
+ // Compile the binary and create an instance
+ var wasm = new WebAssembly.Instance(new WebAssembly.Module(binary), {})
+ console.log("exports: " + Object.keys(wasm.exports).sort().join(","));
+ console.log();
+
+ // Call the code!
+ console.log('an addition: ' + wasm.exports.adder(40, 2));
+}
+
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js
index 630db311f..e8cf3e0f5 100644
--- a/test/binaryen.js/kitchen-sink.js
+++ b/test/binaryen.js/kitchen-sink.js
@@ -1,5 +1,9 @@
// kitchen sink, tests the full API
+function assert(x) {
+ if (!x) throw 'error!';
+}
+
function cleanInfo(info) {
var ret = {};
for (var x in info) {
@@ -16,10 +20,6 @@ var module;
var v128_bytes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
-function assert(x) {
- if (!x) throw 'error!';
-}
-
function makeInt32(x) {
return module.i32.const(x);
}
@@ -975,7 +975,7 @@ function test_expression_info() {
module.dispose();
}
-function main() {
+function test() {
// Tracing must be first so it starts with a fresh set of interned types
test_tracing();
test_types();
@@ -992,4 +992,4 @@ function main() {
test_expression_info();
}
-main();
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt
index 586834f26..bb6c92f72 100644
--- a/test/binaryen.js/kitchen-sink.js.txt
+++ b/test/binaryen.js/kitchen-sink.js.txt
@@ -743,7 +743,7 @@ int main() {
uint8_t t109[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
expressions[398] = BinaryenConst(the_module, BinaryenLiteralVec128(t109));
}
- expressions[399] = BinaryenBinary(the_module, 111, expressions[397], expressions[398]);
+ expressions[399] = BinaryenBinary(the_module, 112, expressions[397], expressions[398]);
{
uint8_t t110[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
expressions[400] = BinaryenConst(the_module, BinaryenLiteralVec128(t110));
@@ -2689,7 +2689,7 @@ getExpressionInfo(f64.const)={"id":14,"type":5,"value":9.5}
)
)
(drop
- (f32x4.ge
+ (f64x2.eq
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
@@ -4386,7 +4386,7 @@ getExpressionInfo(f64.const)={"id":14,"type":5,"value":9.5}
)
)
(drop
- (f32x4.ge
+ (f64x2.eq
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
@@ -7139,7 +7139,7 @@ getExpressionInfo(f64.const)={"id":14,"type":5,"value":9.5}
)
)
(drop
- (f32x4.ge
+ (f64x2.eq
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
@@ -8834,7 +8834,7 @@ getExpressionInfo(f64.const)={"id":14,"type":5,"value":9.5}
)
)
(drop
- (f32x4.ge
+ (f64x2.eq
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
(v128.const i32x4 0x04030201 0x08070605 0x0c0b0a09 0x100f0e0d)
)
diff --git a/test/binaryen.js/optimize-levels.js b/test/binaryen.js/optimize-levels.js
index e42bd5409..b3ae66a43 100644
--- a/test/binaryen.js/optimize-levels.js
+++ b/test/binaryen.js/optimize-levels.js
@@ -18,47 +18,52 @@ var wast = `
)
)
`;
-console.log("=== input wast ===" + wast);
-function printOptions() {
- console.log("optimizeLevel=" + Binaryen.getOptimizeLevel());
- console.log("shrinkLevel=" + Binaryen.getShrinkLevel());
-}
+function test() {
+ console.log("=== input wast ===" + wast);
+
+ function printOptions() {
+ console.log("optimizeLevel=" + Binaryen.getOptimizeLevel());
+ console.log("shrinkLevel=" + Binaryen.getShrinkLevel());
+ }
-// Use defaults (should be equal to -Os below)
-var module = Binaryen.parseText(wast);
+ // Use defaults (should be equal to -Os below)
+ var module = Binaryen.parseText(wast);
-console.log("=== unoptimized ===");
-assert(module.validate());
-console.log(module.emitText());
+ console.log("=== unoptimized ===");
+ assert(module.validate());
+ console.log(module.emitText());
-module.optimize();
-console.log("=== optimized using defaults ===");
-printOptions();
-assert(module.validate());
-console.log(module.emitText());
-module.dispose();
+ module.optimize();
+ console.log("=== optimized using defaults ===");
+ printOptions();
+ assert(module.validate());
+ console.log(module.emitText());
+ module.dispose();
-// Use -O0 (should remove the block)
-module = Binaryen.parseText(wast);
+ // Use -O0 (should remove the block)
+ module = Binaryen.parseText(wast);
-Binaryen.setOptimizeLevel(0);
-Binaryen.setShrinkLevel(0);
-module.optimize();
-console.log("=== optimized with -O0 ===");
-printOptions();
-assert(module.validate());
-console.log(module.emitText());
-module.dispose();
+ Binaryen.setOptimizeLevel(0);
+ Binaryen.setShrinkLevel(0);
+ module.optimize();
+ console.log("=== optimized with -O0 ===");
+ printOptions();
+ assert(module.validate());
+ console.log(module.emitText());
+ module.dispose();
-// Use -Os (should remove the block and convert to a select)
-module = Binaryen.parseText(wast);
+ // Use -Os (should remove the block and convert to a select)
+ module = Binaryen.parseText(wast);
+
+ Binaryen.setOptimizeLevel(2);
+ Binaryen.setShrinkLevel(1);
+ module.optimize();
+ console.log("=== optimized with -Os ===");
+ printOptions();
+ assert(module.validate());
+ console.log(module.emitText());
+ module.dispose();
+}
-Binaryen.setOptimizeLevel(2);
-Binaryen.setShrinkLevel(1);
-module.optimize();
-console.log("=== optimized with -Os ===");
-printOptions();
-assert(module.validate());
-console.log(module.emitText());
-module.dispose();
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/push-pop.js b/test/binaryen.js/push-pop.js
index 9f1d66719..01d6e76a9 100644
--- a/test/binaryen.js/push-pop.js
+++ b/test/binaryen.js/push-pop.js
@@ -16,29 +16,33 @@ function stringify(expr) {
return JSON.stringify(cleanInfo(Binaryen.getExpressionInfo(expr)));
}
-var module = new Binaryen.Module();
+function test() {
+ var module = new Binaryen.Module();
-var func = module.addFunction("func", Binaryen.none, Binaryen.none, [],
- module.block(null, [
- module.push(module.i32.pop()),
- module.push(module.i64.pop()),
- module.push(module.f32.pop()),
- module.push(module.f64.pop()),
- module.push(module.v128.pop()),
- module.push(module.anyref.pop()),
- module.push(module.exnref.pop())
- ]
- )
-)
+ var func = module.addFunction("func", Binaryen.none, Binaryen.none, [],
+ module.block(null, [
+ module.push(module.i32.pop()),
+ module.push(module.i64.pop()),
+ module.push(module.f32.pop()),
+ module.push(module.f64.pop()),
+ module.push(module.v128.pop()),
+ module.push(module.anyref.pop()),
+ module.push(module.exnref.pop())
+ ]
+ )
+ )
-assert(module.validate());
-console.log(module.emitText());
+ assert(module.validate());
+ console.log(module.emitText());
-console.log("getExpressionInfo(i32.pop) = " + stringify(module.i32.pop()));
-console.log("getExpressionInfo(i64.pop) = " + stringify(module.i64.pop()));
-console.log("getExpressionInfo(f32.pop) = " + stringify(module.f32.pop()));
-console.log("getExpressionInfo(f64.pop) = " + stringify(module.f64.pop()));
-console.log("getExpressionInfo(v128.pop) = " + stringify(module.v128.pop()));
-console.log("getExpressionInfo(anyref.pop) = " + stringify(module.anyref.pop()));
-console.log("getExpressionInfo(exnref.pop) = " + stringify(module.exnref.pop()));
-console.log("getExpressionInfo(push) = " + stringify(module.push(module.i32.const(0))));
+ console.log("getExpressionInfo(i32.pop) = " + stringify(module.i32.pop()));
+ console.log("getExpressionInfo(i64.pop) = " + stringify(module.i64.pop()));
+ console.log("getExpressionInfo(f32.pop) = " + stringify(module.f32.pop()));
+ console.log("getExpressionInfo(f64.pop) = " + stringify(module.f64.pop()));
+ console.log("getExpressionInfo(v128.pop) = " + stringify(module.v128.pop()));
+ console.log("getExpressionInfo(anyref.pop) = " + stringify(module.anyref.pop()));
+ console.log("getExpressionInfo(exnref.pop) = " + stringify(module.exnref.pop()));
+ console.log("getExpressionInfo(push) = " + stringify(module.push(module.i32.const(0))));
+}
+
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/reloc.js b/test/binaryen.js/reloc.js
index 9666d17fd..e9fdd6012 100644
--- a/test/binaryen.js/reloc.js
+++ b/test/binaryen.js/reloc.js
@@ -2,24 +2,28 @@ function assert(x) {
if (!x) throw 'error!';
}
-var module = new Binaryen.Module();
+function test() {
+ var module = new Binaryen.Module();
-// memory with offset
+ // memory with offset
-module.addGlobalImport("memory_base", "env", "memory_base", Binaryen.i32, false);
-module.setMemory(1, -1, null, [
- {
- offset: module.global.get("memory_base", Binaryen.i32),
- data: "data data".split('').map(function(x) { return x.charCodeAt(0) })
- }
-]);
+ module.addGlobalImport("memory_base", "env", "memory_base", Binaryen.i32, false);
+ module.setMemory(1, -1, null, [
+ {
+ offset: module.global.get("memory_base", Binaryen.i32),
+ data: "data data".split('').map(function(x) { return x.charCodeAt(0) })
+ }
+ ]);
-// table with offset
+ // table with offset
-var func = module.addFunction("func", Binaryen.none, Binaryen.none, [], module.nop());
+ var func = module.addFunction("func", Binaryen.none, Binaryen.none, [], module.nop());
-module.addGlobalImport("table_base", "env", "table_base", Binaryen.i32, false);
-module.setFunctionTable(1, -1, [ "func", "func" ], module.global.get("table_base", Binaryen.i32));
+ module.addGlobalImport("table_base", "env", "table_base", Binaryen.i32, false);
+ module.setFunctionTable(1, -1, [ "func", "func" ], module.global.get("table_base", Binaryen.i32));
-assert(module.validate());
-console.log(module.emitText());
+ assert(module.validate());
+ console.log(module.emitText());
+}
+
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/sieve.js b/test/binaryen.js/sieve.js
index b2c278cbd..ef7c6cca8 100644
--- a/test/binaryen.js/sieve.js
+++ b/test/binaryen.js/sieve.js
@@ -1,75 +1,79 @@
-// Create a module to work on
-var module = new Binaryen.Module();
+function test() {
+ // Create a module to work on
+ var module = new Binaryen.Module();
-// Set a memory of initially one page, maximum 100 pages
-module.setMemory(1, 100);
+ // Set a memory of initially one page, maximum 100 pages
+ module.setMemory(1, 100);
-var body = module.block(
- null,
- [
- // if the current memory size is too small, grow it
- module.if(
- module.i32.lt_u(
- module.i32.mul(
- module.memory.size(),
- module.i32.const(65536)
+ var body = module.block(
+ null,
+ [
+ // if the current memory size is too small, grow it
+ module.if(
+ module.i32.lt_u(
+ module.i32.mul(
+ module.memory.size(),
+ module.i32.const(65536)
+ ),
+ module.local.get(0, Binaryen.i32)
),
- module.local.get(0, Binaryen.i32)
- ),
- module.drop(
- module.memory.grow(
- module.i32.sub(
- module.i32.div_u(
- module.i32.add(
- module.local.get(0, Binaryen.i32),
- module.i32.const(65535)
+ module.drop(
+ module.memory.grow(
+ module.i32.sub(
+ module.i32.div_u(
+ module.i32.add(
+ module.local.get(0, Binaryen.i32),
+ module.i32.const(65535)
+ ),
+ module.i32.const(65536)
),
- module.i32.const(65536)
- ),
- module.memory.size()
+ module.memory.size()
+ )
)
)
- )
- ),
- // first, clear memory
- module.local.set(1, module.i32.const(0)),
- module.loop('clear', module.block(null, [
- module.i32.store8(0, 1,
- module.local.get(1, Binaryen.i32),
- module.i32.const(0)
),
- module.local.set(1, module.i32.add(
- module.local.get(1, Binaryen.i32),
- module.i32.const(1)
- )),
- module.br_if('clear', module.i32.eq(
- module.local.get(1, Binaryen.i32),
- module.local.get(0, Binaryen.i32)
- ))
- ])),
- // perform the sieve TODO
- // calculate how many primes there are
- module.return(module.local.get(0, Binaryen.i32))
- ],
- Binaryen.none
-);
+ // first, clear memory
+ module.local.set(1, module.i32.const(0)),
+ module.loop('clear', module.block(null, [
+ module.i32.store8(0, 1,
+ module.local.get(1, Binaryen.i32),
+ module.i32.const(0)
+ ),
+ module.local.set(1, module.i32.add(
+ module.local.get(1, Binaryen.i32),
+ module.i32.const(1)
+ )),
+ module.br_if('clear', module.i32.eq(
+ module.local.get(1, Binaryen.i32),
+ module.local.get(0, Binaryen.i32)
+ ))
+ ])),
+ // perform the sieve TODO
+ // calculate how many primes there are
+ module.return(module.local.get(0, Binaryen.i32))
+ ],
+ Binaryen.none
+ );
+
+ // Create the add function
+ // Note: no additional local variables (that's the [])
+ module.addFunction('sieve', Binaryen.i32, Binaryen.i32, [Binaryen.i32], body);
-// Create the add function
-// Note: no additional local variables (that's the [])
-module.addFunction('sieve', Binaryen.i32, Binaryen.i32, [Binaryen.i32], body);
+ // Export the function, so we can call it later (for simplicity we
+ // export it as the same name as it has internally)
+ module.addFunctionExport('sieve', 'sieve');
-// Export the function, so we can call it later (for simplicity we
-// export it as the same name as it has internally)
-module.addFunctionExport('sieve', 'sieve');
+ if (!module.validate()) throw 'did not validate :(';
-if (!module.validate()) throw 'did not validate :(';
+ // Print out the text
+ console.log(module.emitText());
-// Print out the text
-console.log(module.emitText());
+ // Optimize the module! This removes the 'return', since the
+ // output of the add can just fall through
+ module.optimize();
-// Optimize the module! This removes the 'return', since the
-// output of the add can just fall through
-module.optimize();
+ // Print out the optimized module's text
+ console.log('optimized:\n\n' + module.emitText());
+}
-// Print out the optimized module's text
-console.log('optimized:\n\n' + module.emitText());
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/simd.js b/test/binaryen.js/simd.js
index a6055a267..68785f9d7 100644
--- a/test/binaryen.js/simd.js
+++ b/test/binaryen.js/simd.js
@@ -1,5 +1,9 @@
-var module = new Binaryen.Module();
+function test() {
+ var module = new Binaryen.Module();
-var expr = module.v128.const([1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]);
-var info = Binaryen.getExpressionInfo(expr);
-console.log("v128.const i8x16 0x" + info.value.map(b => b.toString(16)).join(" 0x"));
+ var expr = module.v128.const([1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]);
+ var info = Binaryen.getExpressionInfo(expr);
+ console.log("v128.const i8x16 0x" + info.value.map(b => b.toString(16)).join(" 0x"));
+}
+
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/sourcemap.js b/test/binaryen.js/sourcemap.js
index 04f188e23..f8deecf3f 100644
--- a/test/binaryen.js/sourcemap.js
+++ b/test/binaryen.js/sourcemap.js
@@ -2,41 +2,45 @@ function assert(x) {
if (!x) throw 'error!';
}
-var module = new Binaryen.Module();
-
-var fileIndex = module.addDebugInfoFileName("module.c");
-
-console.log(module.getDebugInfoFileName(fileIndex));
-console.log();
-
-var expr = module.i32.const(1);
-var body = module.block("", [
- expr
-], Binaryen.i32);
-
-var func = module.addFunction("main", Binaryen.none, Binaryen.i32, [], body);
-
-module.setDebugLocation(func, expr, fileIndex, 1, 2);
-module.setDebugLocation(func, body, fileIndex, 0, 3);
-
-var output = module.emitBinary("module.wasm.map");
-assert(module.validate());
-
-function dumpBinary(buffer) {
- var hex = [], o, b, h;
- for (var i = 0; i < buffer.length; ++i) {
- o = i.toString(16);
- while (o.length < 3) o = "0" + o;
- if ((i & 15) === 0) hex.push((i ? "\n" : "") + o + ":");
- if ((b = buffer[i]) >= 0x21 && b <= 0x7e)
- h = String.fromCharCode(b) + ' ';
- else if ((h = b.toString(16)).length < 2)
- h = "0" + h;
- hex.push(h);
+function test() {
+ var module = new Binaryen.Module();
+
+ var fileIndex = module.addDebugInfoFileName("module.c");
+
+ console.log(module.getDebugInfoFileName(fileIndex));
+ console.log();
+
+ var expr = module.i32.const(1);
+ var body = module.block("", [
+ expr
+ ], Binaryen.i32);
+
+ var func = module.addFunction("main", Binaryen.none, Binaryen.i32, [], body);
+
+ module.setDebugLocation(func, expr, fileIndex, 1, 2);
+ module.setDebugLocation(func, body, fileIndex, 0, 3);
+
+ var output = module.emitBinary("module.wasm.map");
+ assert(module.validate());
+
+ function dumpBinary(buffer) {
+ var hex = [], o, b, h;
+ for (var i = 0; i < buffer.length; ++i) {
+ o = i.toString(16);
+ while (o.length < 3) o = "0" + o;
+ if ((i & 15) === 0) hex.push((i ? "\n" : "") + o + ":");
+ if ((b = buffer[i]) >= 0x21 && b <= 0x7e)
+ h = String.fromCharCode(b) + ' ';
+ else if ((h = b.toString(16)).length < 2)
+ h = "0" + h;
+ hex.push(h);
+ }
+ console.log(hex.join(" "));
}
- console.log(hex.join(" "));
+
+ dumpBinary(output.binary);
+ console.log();
+ console.log(output.sourceMap);
}
-dumpBinary(output.binary);
-console.log();
-console.log(output.sourceMap);
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/stackir.js b/test/binaryen.js/stackir.js
index 929fbaa0e..324a99abe 100644
--- a/test/binaryen.js/stackir.js
+++ b/test/binaryen.js/stackir.js
@@ -20,13 +20,18 @@ var wast = `
)
)
`;
-console.log("=== input wast ===" + wast);
-var module = Binaryen.parseText(wast);
-assert(module.validate());
+function test() {
+ console.log("=== input wast ===" + wast);
-console.log("=== default ===");
-console.log(module.emitStackIR());
+ var module = Binaryen.parseText(wast);
+ assert(module.validate());
-console.log("=== optimize ==="); // should omit the second block
-console.log(module.emitStackIR(true));
+ console.log("=== default ===");
+ console.log(module.emitStackIR());
+
+ console.log("=== optimize ==="); // should omit the second block
+ console.log(module.emitStackIR(true));
+}
+
+Binaryen.ready.then(test);
diff --git a/test/binaryen.js/validation_errors.js b/test/binaryen.js/validation_errors.js
index 16bc6f433..1251d37e6 100644
--- a/test/binaryen.js/validation_errors.js
+++ b/test/binaryen.js/validation_errors.js
@@ -1,25 +1,29 @@
-(function() {
- var mod = new Binaryen.Module();
- var func = mod.addFunction("test", Binaryen.none, Binaryen.none, [],
- mod.block("", [
- mod.drop(
- mod.global.get("missing", Binaryen.i32)
- )
- ])
- );
- mod.addExport("test", func);
- console.log(mod.validate())
-})();
+function test() {
+ (function() {
+ var mod = new Binaryen.Module();
+ var func = mod.addFunction("test", Binaryen.none, Binaryen.none, [],
+ mod.block("", [
+ mod.drop(
+ mod.global.get("missing", Binaryen.i32)
+ )
+ ])
+ );
+ mod.addExport("test", func);
+ console.log(mod.validate())
+ })();
-(function() {
- var mod = new Binaryen.Module();
- var func = mod.addFunction("test", Binaryen.none, Binaryen.none, [],
- mod.block("", [
- mod.drop(
- mod.local.get(0, Binaryen.i32)
- )
- ])
- );
- mod.addFunctionExport("test", "test", func);
- console.log(mod.validate())
-})();
+ (function() {
+ var mod = new Binaryen.Module();
+ var func = mod.addFunction("test", Binaryen.none, Binaryen.none, [],
+ mod.block("", [
+ mod.drop(
+ mod.local.get(0, Binaryen.i32)
+ )
+ ])
+ );
+ mod.addFunctionExport("test", "test", func);
+ console.log(mod.validate())
+ })();
+}
+
+Binaryen.ready.then(test);
diff --git a/travis-emcc-tests.sh b/travis-emcc-tests.sh
index 5dde9d0ed..41a25a205 100755
--- a/travis-emcc-tests.sh
+++ b/travis-emcc-tests.sh
@@ -1,9 +1,15 @@
#!/usr/bin/env bash
set -e
-echo "travis-test build"
+echo "travis-test build:wasm"
emconfigure cmake -DCMAKE_BUILD_TYPE=Release
+emmake make -j4 binaryen_wasm
+echo "travis-test test:wasm"
+python3 -m scripts.test.binaryenjs
+echo "travis-test done:wasm"
+
+echo "travis-test build:js"
emmake make -j4 binaryen_js
-echo "travis-test test"
+echo "travis-test test:js"
python3 -m scripts.test.binaryenjs
-echo "travis-test yay!"
+echo "travis-test done:js"