diff options
author | Abbas Mashayekh <martianboy2005@gmail.com> | 2021-02-10 01:17:28 +0330 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 13:47:28 -0800 |
commit | 3da8b08ecd57f5662bebc69ea73bf59e1928341e (patch) | |
tree | 2902eedc161579eaf37a1aed463de95916eee703 /src/js | |
parent | a12a8250da24aa5b5787bf89562b243fdc514302 (diff) | |
download | binaryen-3da8b08ecd57f5662bebc69ea73bf59e1928341e.tar.gz binaryen-3da8b08ecd57f5662bebc69ea73bf59e1928341e.tar.bz2 binaryen-3da8b08ecd57f5662bebc69ea73bf59e1928341e.zip |
[reference-types] remove single table restriction in IR (#3517)
Adds support for modules with multiple tables. Adds a field for the table name to `CallIndirect` and updates the C/JS APIs accordingly.
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/binaryen.js-post.js | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index fc64d8bbd..2ac2605fa 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -576,9 +576,9 @@ function wrapModule(module, self = {}) { // 'callIndirect', 'returnCall', 'returnCallIndirect' are deprecated and may // be removed in a future release. Please use the the snake_case names // instead. - self['callIndirect'] = self['call_indirect'] = function(target, operands, params, results) { + self['callIndirect'] = self['call_indirect'] = function(table, target, operands, params, results) { return preserveStack(() => - Module['_BinaryenCallIndirect'](module, target, i32sToStack(operands), operands.length, params, results) + Module['_BinaryenCallIndirect'](module, strToStack(table), target, i32sToStack(operands), operands.length, params, results) ); }; self['returnCall'] = self['return_call'] = function(name, operands, type) { @@ -586,9 +586,9 @@ function wrapModule(module, self = {}) { Module['_BinaryenReturnCall'](module, strToStack(name), i32sToStack(operands), operands.length, type) ); }; - self['returnCallIndirect'] = self['return_call_indirect'] = function(target, operands, params, results) { + self['returnCallIndirect'] = self['return_call_indirect'] = function(table, target, operands, params, results) { return preserveStack(() => - Module['_BinaryenReturnCallIndirect'](module, target, i32sToStack(operands), operands.length, params, results) + Module['_BinaryenReturnCallIndirect'](module, strToStack(table), target, i32sToStack(operands), operands.length, params, results) ); }; @@ -2197,9 +2197,23 @@ function wrapModule(module, self = {}) { self['getGlobal'] = function(name) { return preserveStack(() => Module['_BinaryenGetGlobal'](module, strToStack(name))); }; + self['addTable'] = function(table, initial, maximum, funcNames, offset = self['i32']['const'](0)) { + return preserveStack(() => Module['_BinaryenAddTable'](module, + strToStack(table), initial, maximum, + i32sToStack(funcNames.map(strToStack)), + funcNames.length, + offset) + ); + } + self['getTable'] = function(name) { + return preserveStack(() => Module['_BinaryenGetTable'](module, strToStack(name))); + }; self['removeGlobal'] = function(name) { return preserveStack(() => Module['_BinaryenRemoveGlobal'](module, strToStack(name))); } + self['removeTable'] = function(name) { + return preserveStack(() => Module['_BinaryenRemoveTable'](module, strToStack(name))); + } self['addEvent'] = function(name, attribute, params, results) { return preserveStack(() => Module['_BinaryenAddEvent'](module, strToStack(name), attribute, params, results)); }; @@ -2360,9 +2374,15 @@ function wrapModule(module, self = {}) { self['getNumGlobals'] = function() { return Module['_BinaryenGetNumGlobals'](module); }; + self['getNumTables'] = function() { + return Module['_BinaryenGetNumTables'](module); + }; self['getGlobalByIndex'] = function(index) { return Module['_BinaryenGetGlobalByIndex'](module, index); }; + self['getTableByIndex'] = function(index) { + return Module['_BinaryenGetTableByIndex'](module, index); + }; self['emitText'] = function() { const old = out; let ret = ''; @@ -2587,6 +2607,7 @@ Module['getExpressionInfo'] = function(expr) { 'type': type, 'isReturn': Boolean(Module['_BinaryenCallIndirectIsReturn'](expr)), 'target': Module['_BinaryenCallIndirectGetTarget'](expr), + 'table': Module['_BinaryenCallIndirectGetTable'](expr), 'operands': getAllNested(expr, Module['_BinaryenCallIndirectGetNumOperands'], Module['_BinaryenCallIndirectGetOperandAt']) }; case Module['LocalGetId']: @@ -2973,6 +2994,23 @@ Module['getGlobalInfo'] = function(global) { }; }; +// Obtains information about a 'Table' +Module['getTableInfo'] = function(table) { + var hasMax = Boolean(Module['_BinaryenTableHasMax'](table)); + var tableInfo = { + 'name': UTF8ToString(Module['_BinaryenTableGetName'](table)), + 'module': UTF8ToString(Module['_BinaryenTableImportGetModule'](table)), + 'base': UTF8ToString(Module['_BinaryenTableImportGetBase'](table)), + 'initial': Module['_BinaryenTableGetInitial'](table) + }; + + if (hasMax) { + tableInfo.max = Module['_BinaryenTableGetMax'](table); + } + + return tableInfo; +}; + // Obtains information about a 'Event' Module['getEventInfo'] = function(event_) { return { @@ -3421,6 +3459,12 @@ Module['CallIndirect'] = makeExpressionWrapper({ 'setTarget'(expr, targetExpr) { Module['_BinaryenCallIndirectSetTarget'](expr, targetExpr); }, + 'getTable'(expr) { + return UTF8ToString(Module['_BinaryenCallIndirectGetTable'](expr)); + }, + 'setTable'(expr, table) { + preserveStack(() => { Module['_BinaryenCallIndirectSetTable'](expr, strToStack(table)) }); + }, 'getNumOperands'(expr) { return Module['_BinaryenCallIndirectGetNumOperands'](expr); }, |