Struct cranelift_wasm::DummyEnvironment
source · pub struct DummyEnvironment {
pub info: DummyModuleInfo,
pub func_bytecode_sizes: Vec<usize>,
pub module_name: Option<String>,
/* private fields */
}
Expand description
This ModuleEnvironment
implementation is a “naïve” one, doing essentially nothing and
emitting placeholders when forced to. Don’t try to execute code translated for this
environment, essentially here for translation debug purposes.
Fields§
§info: DummyModuleInfo
Module information.
func_bytecode_sizes: Vec<usize>
Vector of wasm bytecode size for each function.
module_name: Option<String>
Name of the module from the wasm file.
Implementations§
source§impl DummyEnvironment
impl DummyEnvironment
sourcepub fn new(config: TargetFrontendConfig, debug_info: bool) -> Self
pub fn new(config: TargetFrontendConfig, debug_info: bool) -> Self
Creates a new DummyEnvironment
instance.
sourcepub fn func_env(&self) -> DummyFuncEnvironment<'_>
pub fn func_env(&self) -> DummyFuncEnvironment<'_>
Return a DummyFuncEnvironment
for translating functions within this
DummyEnvironment
.
sourcepub fn get_num_func_imports(&self) -> usize
pub fn get_num_func_imports(&self) -> usize
Return the number of imported functions within this DummyEnvironment
.
Examples found in repository?
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
fn define_function_body(
&mut self,
mut validator: FuncValidator<ValidatorResources>,
body: FunctionBody<'data>,
) -> WasmResult<()> {
self.func_bytecode_sizes
.push(body.get_binary_reader().bytes_remaining());
let func = {
let mut func_environ =
DummyFuncEnvironment::new(&self.info, self.expected_reachability.clone());
let func_index =
FuncIndex::new(self.get_num_func_imports() + self.info.function_bodies.len());
let sig = func_environ.vmctx_sig(self.get_func_type(func_index));
let mut func =
ir::Function::with_name_signature(UserFuncName::user(0, func_index.as_u32()), sig);
if self.debug_info {
func.collect_debug_info();
}
self.trans
.translate_body(&mut validator, body, &mut func, &mut func_environ)?;
func
};
self.info.function_bodies.push(func);
Ok(())
}
sourcepub fn get_func_name(&self, func_index: FuncIndex) -> Option<&str>
pub fn get_func_name(&self, func_index: FuncIndex) -> Option<&str>
Return the name of the function, if a name for the function with the corresponding index exists.
sourcepub fn test_expected_reachability(&mut self, reachability: Vec<(bool, bool)>)
pub fn test_expected_reachability(&mut self, reachability: Vec<(bool, bool)>)
Test reachability bits before and after every opcode during translation, as provided by the
FuncTranslationState
. This is generally used only for unit tests. This is applied to
every function in the module (so is likely only useful for test modules with one function).