summaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorDaniel Wirtz <dcode@dcode.io>2017-06-07 20:28:08 +0200
committerAlon Zakai <alonzakai@gmail.com>2017-06-07 11:28:08 -0700
commit2c220f5cebd915447e786f0b365b0bac1e2f719f (patch)
tree103ed218e637ff868e7ee067d51c25bdeb1a6f9a /src/js
parent3f0db5a7aafaaa4de713ff3ba3c3bbeb59fe566e (diff)
downloadbinaryen-2c220f5cebd915447e786f0b365b0bac1e2f719f.tar.gz
binaryen-2c220f5cebd915447e786f0b365b0bac1e2f719f.tar.bz2
binaryen-2c220f5cebd915447e786f0b365b0bac1e2f719f.zip
Update binaryen-c/binaryen.js, fixes #1028, fixes #1029 (#1030)
This PR adds global variable support (addGlobal, getGlobal, setGlobal), host operations (currentMemory, growMemory), a few utility functions (removeImport, removeExport, getFunctionTypeBySignature with the latter being scheduled for removal once a better alternative is in place) and it introduces an additional argument to specify the result type in BinaryenBlock (effectively breaking the C-API but retaining previous behaviour by introducing the BinaryenUndefined() type for this purpose). Additionally, it enables compilation with exception support in build-js.sh as exceptions are thrown and caught when optimizing endless loops, intentionally resulting in an unreachable opcode. Affected test cases have been updated accordingly.
Diffstat (limited to 'src/js')
-rw-r--r--src/js/binaryen.js-post.js44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js
index b5d8ab5b2..2f7defc63 100644
--- a/src/js/binaryen.js-post.js
+++ b/src/js/binaryen.js-post.js
@@ -27,6 +27,7 @@
Module['i64'] = Module['_BinaryenInt64']();
Module['f32'] = Module['_BinaryenFloat32']();
Module['f64'] = Module['_BinaryenFloat64']();
+ Module['undefined'] = Module['_BinaryenUndefined']();
Module['ClzInt32'] = Module['_BinaryenClzInt32']();
Module['CtzInt32'] = Module['_BinaryenCtzInt32']();
@@ -170,11 +171,18 @@
i32sToStack(paramTypes), paramTypes.length);
});
};
+ this['getFunctionTypeBySignature'] = function(result, paramTypes) {
+ return preserveStack(function() {
+ return Module['_BinaryenGetFunctionTypeBySignature'](module, result,
+ i32sToStack(paramTypes), paramTypes.length);
+ });
+ };
- this['block'] = function(name, children) {
+ this['block'] = function(name, children, type) {
return preserveStack(function() {
return Module['_BinaryenBlock'](module, name ? strToStack(name) : 0,
- i32sToStack(children), children.length);
+ i32sToStack(children), children.length,
+ typeof type !== 'undefined' ? type : Module['undefined']);
});
};
this['if'] = function(condition, ifTrue, ifFalse) {
@@ -224,6 +232,21 @@
this['teeLocal'] = function(index, value) {
return Module['_BinaryenTeeLocal'](module, index, value);
};
+ this['getGlobal'] = function(name, type) {
+ return Module['_BinaryenGetGlobal'](module, strToStack(name), type);
+ }
+ this['setGlobal'] = function(name, value) {
+ return Module['_BinaryenSetGlobal'](module, strToStack(name), value);
+ }
+ this['currentMemory'] = function() {
+ return Module['_BinaryenHost'](module, Module['CurrentMemory']);
+ }
+ this['growMemory'] = function(value) {
+ return Module['_BinaryenHost'](module, Module['GrowMemory'], null, i32sToStack([value]), 1);
+ }
+ this['hasFeature'] = function(name) {
+ return Module['_BinaryenHost'](module, Module['HasFeature'], strToStack(name));
+ }
// The Const creation API is a little different: we don't want users to
// need to make their own Literals, as the C API handles them by value,
@@ -745,16 +768,31 @@
return Module['_BinaryenAddFunction'](module, strToStack(name), functionType, i32sToStack(varTypes), varTypes.length, body);
});
};
+ this['addGlobal'] = function(name, type, mutable, init) {
+ return preserveStack(function() {
+ return Module['_BinaryenAddGlobal'](module, strToStack(name), type, mutable, init);
+ });
+ }
this['addImport'] = function(internalName, externalModuleName, externalBaseName, type) {
return preserveStack(function() {
return Module['_BinaryenAddImport'](module, strToStack(internalName), strToStack(externalModuleName), strToStack(externalBaseName), type);
});
};
+ this['removeImport'] = function(internalName) {
+ return preserveStack(function() {
+ return Module['_BinaryenRemoveImport'](module, strToStack(internalName));
+ });
+ };
this['addExport'] = function(internalName, externalName) {
return preserveStack(function() {
return Module['_BinaryenAddExport'](module, strToStack(internalName), strToStack(externalName));
});
};
+ this['removeExport'] = function(externalName) {
+ return preserveStack(function() {
+ return Module['_BinaryenRemoveExport'](module, strToStack(externalName));
+ });
+ };
this['setFunctionTable'] = function(funcs) {
return preserveStack(function() {
return Module['_BinaryenSetFunctionTable'](module, i32sToStack(funcs), funcs.length);
@@ -883,7 +921,7 @@ if (typeof exports != 'undefined') {
(typeof window !== 'undefined' ? window :
typeof global !== 'undefined' && (
typeof process === 'undefined' ||
-
+
// Note: We must export "Binaryen" even inside a CommonJS/AMD/UMD module
// space because check.py generates a.js which requires Binaryen global var
( process.argv &&