-
Notifications
You must be signed in to change notification settings - Fork 786
Ability to iterate over webassembly contents with JS api #2370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As a workaround, you can print to WAT and then regex as needed. I am doing this now to generate a list of all function names. +1 on adding this directly to the JS API. |
Partial solution in the following commit: |
The accessors in #2386 have landed, but the npm module doesn't seem to have updated if I install as I did find a bug in the handling of switch destination label names, for which I have a fix in #2553. Otherwise seems to be enough to both list out the functions and walk through the code in the function bodies. |
For a bit of background: The |
I tagged version 90 now. |
Reporting back from the buildbot: There's a v90.0.0 now with updated definitions and docs, that also ships the (yet undocumented) Wasm variant as |
Awesome, thanks! I've got most of what I seem to need for iterating over things now on my project, except for iterating through the function table initialization segments. I'll try and put together a patch later adding that if I can work it out. |
Also would be useful to iterate over globals; as a workaround I can find all the ones that are referenced in a get/set or an export. |
module.getNumFunctionTableSegments() gives the number of segments. module.getFunctionTableSegmentInfoByIndex() yields: ``` { offset, functions: ["func1", "func2"] } ``` Another piece for WebAssembly#2370
module.getNumFunctionTableSegments() gives the number of segments. module.getFunctionTableSegmentInfoByIndex() yields: ``` { offset, functions: ["func1", "func2"] } ``` Another piece for WebAssembly#2370
module.getNumFunctionTableSegments() gives the number of segments. module.getFunctionTableSegmentInfoByIndex() yields: ``` { offset, functions: ["func1", "func2"] } ``` Another piece for WebAssembly#2370
module.getNumFunctionTableSegments() gives the number of segments. module.getFunctionTableSegmentInfoByIndex() yields: ``` { offset, functions: ["func1", "func2"] } ``` Another piece for WebAssembly#2370
#2554 does the function table accessor better than the version I posted; closing mine. |
It looks like there are APIs for exports, functions and memory segments, but no API to iterate over imports, unless I'm missing something? |
@RReverser there's not an iterator specifically for imports, but for imported memories and functions you can iterate over all mems/funcs and check which have an import module & name set. For imported globals, there's no easy iterator last I checked; in my compiler project I had to find global references while walking through instructions in function bodies. |
Looks like the features requested here are mostly implemented. Please open new issues for any follow-up feature requests. |
Uh oh!
There was an error while loading. Please reload this page.
The Js api can't be used to iterate over WebAssembly functions and exports.
This feature could be really useful.
For now, to get a function, we need, at least, to know its name.
[ Edit: In a more general way, binaryen (via its js wrapper) could be able to list the exports, the data sections, the globals and all the functions. ]
The text was updated successfully, but these errors were encountered: