| 492 | |
| 493 | #[cfg(test)] |
| 494 | pub fn mock( |
| 495 | module_map: &wasmtime_environ::PrimaryMap< |
| 496 | wasmtime_environ::DefinedFuncIndex, |
| 497 | &crate::CompiledFunctionMetadata, |
| 498 | >, |
| 499 | wasm_file: wasmtime_environ::WasmFileInfo, |
| 500 | ) -> Self { |
| 501 | use cranelift_entity::EntityRef; |
| 502 | |
| 503 | let mut translations = wasmtime_environ::PrimaryMap::new(); |
| 504 | let mut translation = wasmtime_environ::ModuleTranslation::new(StaticModuleIndex::new(0)); |
| 505 | translation.debuginfo.wasm_file = wasm_file; |
| 506 | translation |
| 507 | .module |
| 508 | .push_function(wasmtime_environ::ModuleInternedTypeIndex::from_u32(0)); |
| 509 | translations.push(translation); |
| 510 | |
| 511 | let mut dummy_obj = object::write::Object::new( |
| 512 | object::BinaryFormat::Elf, |
| 513 | object::Architecture::Wasm32, |
| 514 | object::Endianness::Little, |
| 515 | ); |
| 516 | let dummy_symbol = dummy_obj.add_file_symbol(Vec::new()); |
| 517 | let func_lookup = move |_, f| (dummy_symbol, module_map[f]); |
| 518 | let tunables = wasmtime_environ::Tunables::default_host(); |
| 519 | let compile = Compilation::new( |
| 520 | &*cranelift_codegen::isa::lookup(target_lexicon::Triple::host()) |
| 521 | .unwrap() |
| 522 | .finish(cranelift_codegen::settings::Flags::new( |
| 523 | cranelift_codegen::settings::builder(), |
| 524 | )) |
| 525 | .unwrap(), |
| 526 | &translations, |
| 527 | &func_lookup, |
| 528 | None, |
| 529 | &tunables, |
| 530 | ); |
| 531 | Self::new(&compile, StaticModuleIndex::from_u32(0)) |
| 532 | } |
| 533 | |
| 534 | fn find_func(&self, addr: u64) -> Option<&FuncTransform> { |
| 535 | // TODO check if we need to include end address |