cranelift-wasm hooks to instrument wasm operators#861
Conversation
| let op = reader.read_operator()?; | ||
| translate_operator(op, builder, state, environ)?; | ||
| environ.before_translate_operator(&op, builder)?; | ||
| translate_operator(&op, builder, state, environ)?; |
There was a problem hiding this comment.
op being used in {before,after}_translate_operator is what necessitates the bulk of this PR, by changing to &op here.
| /// - The depth of the two unreachable control blocks stacks, that are manipulated when translating | ||
| /// unreachable code; | ||
| pub struct TranslationState { | ||
| /// A stack of values corresponding to the active values in the input wasm function at this |
There was a problem hiding this comment.
I was initially thinking we'd want to expose the function's corresponding TranslationState (in case a user of cranelift-wasm wanted to add/modify values or the control stack), but that ended up not being necessary in how I'm using this right now. #[deny(missing_docs)] got me to fill in docs here and I figure they don't hurt to keep around :)
It seems like tweaking TranslationState would be a very typical {before,after}_translate_operator use case, so passing along TranslationState might make sense even if not strictly necessary in my use right now
pchickey
left a comment
There was a problem hiding this comment.
Looks good. Thanks for adding docs!
In some circumstances we'd like to insert instructions, and update translator-internal state, based on the wasm operations being translated. This adds a pair of functions to
FuncEnvironmentto support that (and adjustsfunc_translatorto call them appropriately)