summaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorDaniel Wirtz <dcode@dcode.io>2020-01-17 18:43:45 +0100
committerAlon Zakai <azakai@google.com>2020-01-17 09:43:44 -0800
commit98f5507c508d6fde326347df3fcad70740b634ea (patch)
tree3b8a7f1420ba81ca8e8df5b10a9e744a3602e6b4 /src/js
parente873e2a84db3fda3c8df5ed8e0b39578a1fb2f2d (diff)
downloadbinaryen-98f5507c508d6fde326347df3fcad70740b634ea.tar.gz
binaryen-98f5507c508d6fde326347df3fcad70740b634ea.tar.bz2
binaryen-98f5507c508d6fde326347df3fcad70740b634ea.zip
Expose ExpressionAnalyzer in C-/JS-API (#2585)
Instead of reinventing the wheel on our side, this adds ExpressionAnalyzer bindings to the C- and JS-APIs, which can be useful for generators. For example, a generator may decide to simplify a compilation step if a subexpression doesn't have any side effects, or simply skip emitting something that is likely to compile to a drop or an empty block right away.
Diffstat (limited to 'src/js')
-rw-r--r--src/js/binaryen.js-post.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js
index 2993573d1..54f21ed07 100644
--- a/src/js/binaryen.js-post.js
+++ b/src/js/binaryen.js-post.js
@@ -457,6 +457,24 @@ function initializeConstants() {
].forEach(function(name) {
Module['Operations'][name] = Module[name] = Module['_Binaryen' + name]();
});
+
+ // Expression side effects
+ Module['SideEffects'] = {};
+ [ 'None',
+ 'Branches',
+ 'Calls',
+ 'ReadsLocal',
+ 'WritesLocal',
+ 'ReadsGlobal',
+ 'WritesGlobal',
+ 'ReadsMemory',
+ 'WritesMemory',
+ 'ImplicitTrap',
+ 'IsAtomic',
+ 'Any'
+ ].forEach(function(name) {
+ Module['SideEffects'][name] = Module['_BinaryenSideEffect' + name]();
+ });
}
// 'Module' interface
@@ -2739,6 +2757,11 @@ Module['getExpressionInfo'] = function(expr) {
}
};
+// Gets the side effects of the specified expression
+Module['getSideEffects'] = function(expr) {
+ return Module['_BinaryenExpressionGetSideEffects'](expr);
+};
+
Module['createType'] = function(types) {
return preserveStack(function() {
var array = i32sToStack(types);