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

Method declare_function

cranelift/module/src/module.rs:732–761  ·  view source on GitHub ↗

Declare a function in this module.

(
        &mut self,
        name: &str,
        linkage: Linkage,
        signature: &ir::Signature,
    )

Source from the content-addressed store, hash-verified

730
731 /// Declare a function in this module.
732 pub fn declare_function(
733 &mut self,
734 name: &str,
735 linkage: Linkage,
736 signature: &ir::Signature,
737 ) -> ModuleResult<(FuncId, Linkage)> {
738 // TODO: Can we avoid allocating names so often?
739 use super::hash_map::Entry::*;
740 match self.names.entry(name.to_owned()) {
741 Occupied(entry) => match *entry.get() {
742 FuncOrDataId::Func(id) => {
743 let existing = &mut self.functions[id];
744 existing.merge(id, linkage, signature)?;
745 Ok((id, existing.linkage))
746 }
747 FuncOrDataId::Data(..) => {
748 Err(ModuleError::IncompatibleDeclaration(name.to_owned()))
749 }
750 },
751 Vacant(entry) => {
752 let id = self.functions.push(FunctionDeclaration {
753 name: Some(name.to_owned()),
754 linkage,
755 signature: signature.clone(),
756 });
757 entry.insert(FuncOrDataId::Func(id));
758 Ok((id, self.functions[id].linkage))
759 }
760 }
761 }
762
763 /// Declare an anonymous function in this module.
764 pub fn declare_anonymous_function(

Callers 1

handle_moduleFunction · 0.45

Calls 8

OkFunction · 0.85
FuncClass · 0.50
entryMethod · 0.45
getMethod · 0.45
mergeMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected