wasm-autogen tool #3637
wasm-autogen tool #3637
Conversation
| // ";" at the end. | ||
| template<typename T> void autogenOneCAPIDecl(bool startOfImpl = false) { | ||
| MixedArena allocator; | ||
| T curr(allocator); |
kripken
Mar 2, 2021
Author
Member
This creates an instance of the class as a hack, so that we can use the delegates code on it.
This creates an instance of the class as a hack, so that we can use the delegates code on it.
|
nit: |
|
Looks great! That'll certainly help a lot with all the boilerplate. I don't have a strong opinion on whether to use C++ or Python for it. As long as it is easy to maintain and makes our lives easier in the long run, that's fine for me. Regarding Python: One needs Python anyway to do anything of significance with the code base, like updating or running tests. Seems rare to generate something new and then don't test it. |
|
I came in expecting to strongly prefer a Python approach, but actually this looks pretty reasonable to me. It's certainly not beautiful code, but I don't think the Python version would be either, especially since it would have to parse the delegation header as well. I would be happy to be proven wrong about that, though! |
| std::cout << "BINARYEN_API BinaryenExpressionRef\n" \ | ||
| << "Binaryen" << #id << "(BinaryenModuleRef module"; | ||
|
|
||
| #define DELEGATE_FIELD_CHILD(id, name) \ |
aardappel
Mar 4, 2021
Contributor
why are these macros? looks like some inline functions would not be that much more verbose?
why are these macros? looks like some inline functions would not be that much more verbose?
tlively
Mar 4, 2021
Member
This lets them all refer to their shared context, which is useful because theses are usually used to generate fragments of a single larger function.
This lets them all refer to their shared context, which is useful because theses are usually used to generate fragments of a single larger function.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

This implements one possible way of autogenerating C API code. In the future the JS API could also do this.
The approach taken here is:
wasm-autogenis created. It useswasm-delegates-fieldsto emit.hand.cppcode for the C API.*.autogen.h / *.autogen.cpp. You can see them in this PR, implementing theStructoperations. (Note: that is after clang-format has been run on them.)I am actually not that happy with this. I feel like a Python script could be simpler and cleaner. One issue is the hacks - both macros and templates - in order to do what amounts to string processing. Look at the code and tell me what you think... Another issue is that iteration on this tool is slightly annoying - imagine that you are in an intermediate step where
wasm-autogenemits bad C API code. Then buildingwasm-autogenwill fail (to avoid that, we'd need to getwasm-autogento not depend onlibbinaryen.sowhich includes the C API, perhaps splitting it up or such).Instead, I suspect it would be nicer to parse
wasm-delegates-fieldsfrom Python and do things there. We had a debate about this and decided to try to do more in C++; I think the above paragraph provides some new reasons to avoid C++ there.cc @aardappel @tlively @aheejin @dschuff @dcodeIO
Side issue, this reorders one wasm-builder method for consistency, as found by starting to autogenerate things.