diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/binaryen-c.cpp | 59 | ||||
-rw-r--r-- | src/binaryen-c.h | 10 | ||||
-rw-r--r-- | src/js/binaryen.js-post.js | 21 |
3 files changed, 88 insertions, 2 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index fc16eee42..b9ac3abf9 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -3561,6 +3561,65 @@ void BinaryenSetFunctionTable(BinaryenModuleRef module, wasm->table.segments.push_back(segment); } +int BinaryenIsFunctionTableImported(BinaryenModuleRef module) { + if (tracing) { + std::cout << " BinaryenIsFunctionTableImported(the_module);\n"; + } + + auto* wasm = (Module*)module; + return wasm->table.imported(); +} +BinaryenIndex BinaryenGetNumFunctionTableSegments(BinaryenModuleRef module) { + if (tracing) { + std::cout << " BinaryenGetNumFunctionTableSegments(the_module);\n"; + } + + auto* wasm = (Module*)module; + return wasm->table.segments.size(); +} +BinaryenExpressionRef +BinaryenGetFunctionTableSegmentOffset(BinaryenModuleRef module, + BinaryenIndex segmentId) { + if (tracing) { + std::cout << " BinaryenGetFunctionTableSegmentOffset(the_module, " + << segmentId << ");\n"; + } + + auto* wasm = (Module*)module; + if (wasm->table.segments.size() <= segmentId) { + Fatal() << "invalid function table segment id."; + } + return wasm->table.segments[segmentId].offset; +} +BinaryenIndex BinaryenGetFunctionTableSegmentLength(BinaryenModuleRef module, + BinaryenIndex segmentId) { + if (tracing) { + std::cout << " BinaryenGetFunctionTableSegmentLength(the_module, " + << segmentId << ");\n"; + } + + auto* wasm = (Module*)module; + if (wasm->table.segments.size() <= segmentId) { + Fatal() << "invalid function table segment id."; + } + return wasm->table.segments[segmentId].data.size(); +} +const char* BinaryenGetFunctionTableSegmentData(BinaryenModuleRef module, + BinaryenIndex segmentId, + BinaryenIndex dataId) { + if (tracing) { + std::cout << " BinaryenGetFunctionTableSegmentData(the_module, " + << segmentId << ", " << dataId << ");\n"; + } + + auto* wasm = (Module*)module; + if (wasm->table.segments.size() <= segmentId || + wasm->table.segments[segmentId].data.size() <= dataId) { + Fatal() << "invalid function table segment or data id."; + } + return wasm->table.segments[segmentId].data[dataId].c_str(); +} + // Memory. One per module void BinaryenSetMemory(BinaryenModuleRef module, diff --git a/src/binaryen-c.h b/src/binaryen-c.h index 39e0aca33..fa6398fea 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -1191,12 +1191,22 @@ BINARYEN_API void BinaryenRemoveEvent(BinaryenModuleRef module, // Function table. One per module +// TODO: Add support for multiple segments in BinaryenSetFunctionTable. BINARYEN_API void BinaryenSetFunctionTable(BinaryenModuleRef module, BinaryenIndex initial, BinaryenIndex maximum, const char** funcNames, BinaryenIndex numFuncNames, BinaryenExpressionRef offset); +BINARYEN_API int BinaryenIsFunctionTableImported(BinaryenModuleRef module); +BINARYEN_API BinaryenIndex +BinaryenGetNumFunctionTableSegments(BinaryenModuleRef module); +BINARYEN_API BinaryenExpressionRef BinaryenGetFunctionTableSegmentOffset( + BinaryenModuleRef module, BinaryenIndex segmentId); +BINARYEN_API BinaryenIndex BinaryenGetFunctionTableSegmentLength( + BinaryenModuleRef module, BinaryenIndex segmentId); +BINARYEN_API const char* BinaryenGetFunctionTableSegmentData( + BinaryenModuleRef module, BinaryenIndex segmentId, BinaryenIndex dataId); // Memory. One per module diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 3ef19fd7d..33f94939e 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -2177,6 +2177,23 @@ function wrapModule(module, self) { ); }); }; + self['getFunctionTable'] = function() { + return { + 'imported': Boolean(Module['_BinaryenIsFunctionTableImported'](module)), + 'segments': (function() { + var arr = []; + for (var i = 0, numSegments = Module['_BinaryenGetNumFunctionTableSegments'](module); i !== numSegments; ++i) { + var seg = {'offset': Module['_BinaryenGetFunctionTableSegmentOffset'](module, i), 'names': []}; + for (var j = 0, segmentLength = Module['_BinaryenGetFunctionTableSegmentLength'](module, i); j !== segmentLength; ++j) { + var ptr = Module['_BinaryenGetFunctionTableSegmentData'](module, i, j); + seg['names'].push(UTF8ToString(ptr)); + } + arr.push(seg); + } + return arr; + })() + }; + }; self['setMemory'] = function(initial, maximum, exportName, segments, shared) { // segments are assumed to be { passive: bool, offset: expression ref, data: array of 8-bit data } if (!segments) segments = []; @@ -2511,7 +2528,7 @@ Module['getExpressionInfo'] = function(expr) { var tempBuffer = stackAlloc(16); Module['_BinaryenConstGetValueV128'](expr, tempBuffer); value = new Array(16); - for (var i = 0 ; i < 16; i++) { + for (var i = 0; i < 16; i++) { value[i] = HEAPU8[tempBuffer + i]; } }); @@ -2639,7 +2656,7 @@ Module['getExpressionInfo'] = function(expr) { var tempBuffer = stackAlloc(16); Module['_BinaryenSIMDShuffleGetMask'](expr, tempBuffer); var mask = new Array(16); - for (var i = 0 ; i < 16; i++) { + for (var i = 0; i < 16; i++) { mask[i] = HEAPU8[tempBuffer + i]; } return { |