I'm currently experimenting with implementing a pass using just the C-API. Most noteworthy limitation I encountered is that it's not yet possible to replace an expression in-place with just the C-API, so I tried to work around it by modifying the actual expression in, well, unusual ways.
Unsurprisingly, I hit a not-sure-if-interesting case when I wanted to prepend some code to execute before a (return) that returns, well, nothing. My first attempt was to modify the return as follows:
(return
(someCallReturningNone)
)
which looks funny but kinda works, except that it produces
Fatal: IR must be flat: run --flatten beforehand (instructions must only have constant expressions, local.get, or unreachable as children ...)
during optimizations where flat code is required, even though --flatten has been run. Likewise, this produces the same error:
(return
(block
(someCallReturningNone)
)
)
but this works:
(return
(block
(someCallReturningNone)
(return) ;; :-)
)
)
Now I'm not sure if this might or might not be a problem due to the nature of what I'm doing there, but thought I report just in case. Perhaps doing strange things like the above can be trivially supported in a way that no error is produced.
If you have hints how to implement a proper BinaryenExpressionReplace of sorts, that'd be even better ofc :)
I'm currently experimenting with implementing a pass using just the C-API. Most noteworthy limitation I encountered is that it's not yet possible to replace an expression in-place with just the C-API, so I tried to work around it by modifying the actual expression in, well, unusual ways.
Unsurprisingly, I hit a not-sure-if-interesting case when I wanted to prepend some code to execute before a
(return)that returns, well, nothing. My first attempt was to modify the return as follows:(return (someCallReturningNone) )which looks funny but kinda works, except that it produces
during optimizations where flat code is required, even though
--flattenhas been run. Likewise, this produces the same error:but this works:
Now I'm not sure if this might or might not be a problem due to the nature of what I'm doing there, but thought I report just in case. Perhaps doing strange things like the above can be trivially supported in a way that no error is produced.
If you have hints how to implement a proper
BinaryenExpressionReplaceof sorts, that'd be even better ofc :)