summaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2019-12-11 17:12:37 -0800
committerAlon Zakai <azakai@google.com>2019-12-11 17:12:37 -0800
commit759c485a9f35bd859d43b86b02e1397a669fa469 (patch)
treea5c7475002b406e35c6d1e5c2d843000947ef192 /src/js
parentacd786dbd1e59f9d105c4ec8603c2ff46f233649 (diff)
downloadbinaryen-759c485a9f35bd859d43b86b02e1397a669fa469.tar.gz
binaryen-759c485a9f35bd859d43b86b02e1397a669fa469.tar.bz2
binaryen-759c485a9f35bd859d43b86b02e1397a669fa469.zip
Remove FunctionType (#2510)
Function signatures were previously redundantly stored on Function objects as well as on FunctionType objects. These two signature representations had to always be kept in sync, which was error-prone and needlessly complex. This PR takes advantage of the new ability of Type to represent multiple value types by consolidating function signatures as a pair of Types (params and results) stored on the Function object. Since there are no longer module-global named function types, significant changes had to be made to the printing and emitting of function types, as well as their parsing and manipulation in various passes. The C and JS APIs and their tests also had to be updated to remove named function types.
Diffstat (limited to 'src/js')
-rw-r--r--src/js/binaryen.js-post.js50
1 files changed, 10 insertions, 40 deletions
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js
index 3d732c1fc..65a4e15dc 100644
--- a/src/js/binaryen.js-post.js
+++ b/src/js/binaryen.js-post.js
@@ -1,5 +1,4 @@
// export friendly API methods
-
function preserveStack(func) {
try {
var stack = stackSave();
@@ -518,9 +517,9 @@ function wrapModule(module, self) {
return Module['_BinaryenCall'](module, strToStack(name), i32sToStack(operands), operands.length, type);
});
};
- self['callIndirect'] = self['call_indirect'] = function(target, operands, type) {
+ self['callIndirect'] = self['call_indirect'] = function(target, operands, params, results) {
return preserveStack(function() {
- return Module['_BinaryenCallIndirect'](module, target, i32sToStack(operands), operands.length, strToStack(type));
+ return Module['_BinaryenCallIndirect'](module, target, i32sToStack(operands), operands.length, params, results);
});
};
self['returnCall'] = function(name, operands, type) {
@@ -528,9 +527,9 @@ function wrapModule(module, self) {
return Module['_BinaryenReturnCall'](module, strToStack(name), i32sToStack(operands), operands.length, type);
});
};
- self['returnCallIndirect'] = function(target, operands, type) {
+ self['returnCallIndirect'] = function(target, operands, params, results) {
return preserveStack(function() {
- return Module['_BinaryenReturnCallIndirect'](module, target, i32sToStack(operands), operands.length, strToStack(type));
+ return Module['_BinaryenReturnCallIndirect'](module, target, i32sToStack(operands), operands.length, params, results);
});
};
@@ -2008,28 +2007,9 @@ function wrapModule(module, self) {
};
// 'Module' operations
- self['addFunctionType'] = function(name, result, paramTypes) {
- if (!paramTypes) paramTypes = [];
- return preserveStack(function() {
- return Module['_BinaryenAddFunctionType'](module, strToStack(name), result,
- i32sToStack(paramTypes), paramTypes.length);
- });
- };
- self['getFunctionTypeBySignature'] = function(result, paramTypes) {
- if (!paramTypes) paramTypes = [];
- return preserveStack(function() {
- return Module['_BinaryenGetFunctionTypeBySignature'](module, result,
- i32sToStack(paramTypes), paramTypes.length);
- });
- };
- self['removeFunctionType'] = function(name) {
+ self['addFunction'] = function(name, params, results, varTypes, body) {
return preserveStack(function() {
- return Module['_BinaryenRemoveFunctionType'](module, strToStack(name));
- });
- };
- self['addFunction'] = function(name, functionType, varTypes, body) {
- return preserveStack(function() {
- return Module['_BinaryenAddFunction'](module, strToStack(name), functionType, i32sToStack(varTypes), varTypes.length, body);
+ return Module['_BinaryenAddFunction'](module, strToStack(name), params, results, i32sToStack(varTypes), varTypes.length, body);
});
};
self['getFunction'] = function(name) {
@@ -2072,9 +2052,9 @@ function wrapModule(module, self) {
return Module['_BinaryenRemoveEvent'](module, strToStack(name));
});
};
- self['addFunctionImport'] = function(internalName, externalModuleName, externalBaseName, functionType) {
+ self['addFunctionImport'] = function(internalName, externalModuleName, externalBaseName, params, results) {
return preserveStack(function() {
- return Module['_BinaryenAddFunctionImport'](module, strToStack(internalName), strToStack(externalModuleName), strToStack(externalBaseName), functionType);
+ return Module['_BinaryenAddFunctionImport'](module, strToStack(internalName), strToStack(externalModuleName), strToStack(externalBaseName), params, results);
});
};
self['addTableImport'] = function(internalName, externalModuleName, externalBaseName) {
@@ -2698,24 +2678,14 @@ Module['getExpressionInfo'] = function(expr) {
}
};
-// Obtains information about a 'FunctionType'
-Module['getFunctionTypeInfo'] = function(func) {
- return {
- 'name': UTF8ToString(Module['_BinaryenFunctionTypeGetName'](func)),
- 'params': getAllNested(func, Module['_BinaryenFunctionTypeGetNumParams'], Module['_BinaryenFunctionTypeGetParam']),
- 'result': Module['_BinaryenFunctionTypeGetResult'](func)
- };
-};
-
// Obtains information about a 'Function'
Module['getFunctionInfo'] = function(func) {
return {
'name': UTF8ToString(Module['_BinaryenFunctionGetName'](func)),
'module': UTF8ToString(Module['_BinaryenFunctionImportGetModule'](func)),
'base': UTF8ToString(Module['_BinaryenFunctionImportGetBase'](func)),
- 'type': UTF8ToString(Module['_BinaryenFunctionGetType'](func)),
- 'params': getAllNested(func, Module['_BinaryenFunctionGetNumParams'], Module['_BinaryenFunctionGetParam']),
- 'result': Module['_BinaryenFunctionGetResult'](func),
+ 'params': Module['_BinaryenFunctionGetParams'](func),
+ 'results': Module['_BinaryenFunctionGetResults'](func),
'vars': getAllNested(func, Module['_BinaryenFunctionGetNumVars'], Module['_BinaryenFunctionGetVar']),
'body': Module['_BinaryenFunctionGetBody'](func)
};