MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / function_address

Method function_address

cranelift/interpreter/src/interpreter.rs:393–429  ·  view source on GitHub ↗
(
        &self,
        size: AddressSize,
        name: &ExternalName,
    )

Source from the content-addressed store, hash-verified

391 }
392
393 fn function_address(
394 &self,
395 size: AddressSize,
396 name: &ExternalName,
397 ) -> Result<Address, MemoryError> {
398 let curr_func = self.get_current_function();
399 let (entry, index) = match name {
400 ExternalName::User(username) => {
401 let ext_name = &curr_func.params.user_named_funcs()[*username];
402
403 // TODO: This is not optimal since we are looking up by string name
404 let index = self.functions.index_of(&ext_name.to_string()).unwrap();
405
406 (AddressFunctionEntry::UserFunction, index.as_u32())
407 }
408
409 ExternalName::TestCase(testname) => {
410 // TODO: This is not optimal since we are looking up by string name
411 let index = self.functions.index_of(&testname.to_string()).unwrap();
412
413 (AddressFunctionEntry::UserFunction, index.as_u32())
414 }
415 ExternalName::LibCall(libcall) => {
416 // We don't properly have a "libcall" store, but we can use `LibCall::all()`
417 // and index into that.
418 let index = LibCall::all_libcalls()
419 .iter()
420 .position(|lc| lc == libcall)
421 .unwrap();
422
423 (AddressFunctionEntry::LibCall, index as u32)
424 }
425 _ => unimplemented!("function_address: {:?}", name),
426 };
427
428 Address::from_parts(size, AddressRegion::Function, entry as u64, index as u64)
429 }
430
431 fn get_function_from_address(&self, address: Address) -> Option<InterpreterFunctionRef<'a>> {
432 let index = address.offset as u32;

Callers 1

stepFunction · 0.80

Calls 8

get_current_functionMethod · 0.80
user_named_funcsMethod · 0.80
index_ofMethod · 0.80
unwrapMethod · 0.45
to_stringMethod · 0.45
as_u32Method · 0.45
positionMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected