-
Notifications
You must be signed in to change notification settings - Fork 829
Add getters for various specific expression fields to C/JS #1332
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
Conversation
src/binaryen-c.cpp
Outdated
| BinaryenType BinaryenInt64(void) { return i64; } | ||
| BinaryenType BinaryenFloat32(void) { return f32; } | ||
| BinaryenType BinaryenFloat64(void) { return f64; } | ||
| BinaryenType BinaryenUnreachableType(void) { return unreachable; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me sad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah...
What do you think about changing these to BinaryenTypeInt32, BinaryenTypeUnreachable etc.? We could keep the old ones for backwards compatibility, but I think we can get away with frequent breaking changes, currently.
|
Tests are going to fail now because I haven't touched them yet. |
|
What tracing issue did you hit with |
|
IIUC, the API here has |
The issue was that when cloning let's say a
Yeah, there is getExpression. Not sure about the name though (maybe |
|
Hmm, turns out that testing this new API will be somewhat error prone, because infos include pointer values that tend to change when binaryen.js is recompiled :( |
|
Not yet implemented: |
|
Looks great, thanks! Anything left to discuss here before merging? One followup idea I have is to add another field to the JSON infos, that gives their class in JS, so if you get a block's info, you get Maybe |
When I think about it, ideally we'd have TypeScript-like enums first that allow forward and backwards lookups of all these things, like types, expression ids, external kinds, operations etc. Something in the form Type[Type["none"] = Module['_BinaryenTypeNone']()] = "none";
Type[Type["i32"] = Module['_BinaryenTypeInt32']()] = "i32";
...
ExpressionId[ExpressionId["InvalidId"] = Module['_BinaryenInvalidId']()] = "InvalidId";
ExpressionId[ExpressionId["BlockId"] = Module['_BinaryenBlockId']()] = "BlockId";
...for each enum-like. With that in place it'd be really easy to look up the numeric ids and string names of everything in both directions. Wdyt? |
|
Yeah, that makes sense too. I guess it depends on if we want JSON.stringify of these info objects to be self-explanatory, or require the enum lookups. I'm not sure myself. Anyhow, let's merge this in, and keep thinking about the other stuff. |
We'd then also have to do the same for types I guess? I'd be fine with just the ids, keeping the JSON minimal. Though, we could also make info objects be 'class' instances that provide all sorts of additional utility, in this context for example a getter that returns the string name of an id by implicitly calling the enum utility I proposed above. |
|
Good point, the type field should be handled the same way. Not sure what's best for those two fields. Minimal JSON makes sense for efficiency, I suspect, although maybe it doesn't matter much since the strings are going to be internalized anyhow, so they have the same overhead as an integer. And on the other hand, richer JSON, with full string names, seems nicer for people just getting started and for debugging. |
These functions will allow code generators to examine
some usually side-effect freeall expressions, for example to then properly cloneConst,GetLocal,GetGlobalandLoadexpressions where, without that knowledge, aTeeLocalor similar would have to be emitted.Somewhat related to #1331
(Initially I intended to create a
BinaryenExpressionCloneAPI but that didn't play well with tracing when recursively traversing nested expressions, so I figured it might be better to do cloning externally to ensure that proper C-API traces are generated.)