Add FuncEnvironment hooks to generate prologue and epilogue code.
In some cases, it is useful to do some work at entry to or exit from a Cranelift function translated from WebAssembly. This PR adds two optional methods to the `FuncEnvironment` trait to do just this, analogous to the pre/post-hooks on operators that already exist. This PR also includes a drive-by compilation fix due to the latest nightly wherein `.is_empty()` on a `Range` ambiguously refers to either the `Range` impl or the `ExactSizeIterator` impl and can't resolve.
This commit is contained in:
@@ -624,6 +624,26 @@ pub trait FuncEnvironment: TargetEnvironment {
|
||||
) -> WasmResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Optional callback for the `FunctionEnvironment` performing this translation to perform work
|
||||
/// before the function body is translated.
|
||||
fn before_translate_function(
|
||||
&mut self,
|
||||
_builder: &mut FunctionBuilder,
|
||||
_state: &FuncTranslationState,
|
||||
) -> WasmResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Optional callback for the `FunctionEnvironment` performing this translation to perform work
|
||||
/// after the function body is translated.
|
||||
fn after_translate_function(
|
||||
&mut self,
|
||||
_builder: &mut FunctionBuilder,
|
||||
_state: &FuncTranslationState,
|
||||
) -> WasmResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// An object satisfying the `ModuleEnvironment` trait can be passed as argument to the
|
||||
|
||||
Reference in New Issue
Block a user