Skip to content

Provide some way for C & JS to visit and transform module code #7457

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

Open
GulgDev opened this issue Apr 6, 2025 · 3 comments
Open

Provide some way for C & JS to visit and transform module code #7457

GulgDev opened this issue Apr 6, 2025 · 3 comments

Comments

@GulgDev
Copy link
Contributor

GulgDev commented Apr 6, 2025

Currently, Binaryen uses custom passes to transform Wasm (e.g. in wasm-merge). These passes are unavailable to C and JS, meaning that there's no built-in way for the users to transform the code.
In my project, I need to transform the code using Binaryen.js. Currently, I recursively gather all the information about expressions and reconstruct them with the required changes. My code is giant and repetative, as there's no way to convert from the JS object info format back to the original (or modified) expression.
I have two suggestions: either provide a way for JS to reconstruct expression from the corresponding info object, or provide a way for C (and add the corresponding JS bindings) to transform the code using callbacks or some other API.
I am willing to open a PR if we discuss this idea further!

@kripken
Copy link
Member

kripken commented Apr 7, 2025

I agree it would be good to add something for these use cases, but I don't have a specific idea what would be best - both of those directions sound plausible. Perhaps write up in detail the one you think is more promising, for discussion here?

@GulgDev
Copy link
Contributor Author

GulgDev commented Apr 8, 2025

I think that wrapping WalkerPass could be a viable solution. That would mean that we also need to provide some way to interact with delegations fields API.
Maybe creating a separate C++ class for that purpose could be helpful, especially for registering callbacks?

@kripken
Copy link
Member

kripken commented Apr 8, 2025

That might make sense. For simplicity, perhaps wrapping WalkerPass<T, UnifiedExpressionVisitor> is enough, that is, having a single visit* method rather than one per class? Then on the C/JS side the user can pick which classes to operate on themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants