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

Method declare_data

cranelift/module/src/module.rs:777–809  ·  view source on GitHub ↗

Declare a data object in this module.

(
        &mut self,
        name: &str,
        linkage: Linkage,
        writable: bool,
        tls: bool,
    )

Source from the content-addressed store, hash-verified

775
776 /// Declare a data object in this module.
777 pub fn declare_data(
778 &mut self,
779 name: &str,
780 linkage: Linkage,
781 writable: bool,
782 tls: bool,
783 ) -> ModuleResult<(DataId, Linkage)> {
784 // TODO: Can we avoid allocating names so often?
785 use super::hash_map::Entry::*;
786 match self.names.entry(name.to_owned()) {
787 Occupied(entry) => match *entry.get() {
788 FuncOrDataId::Data(id) => {
789 let existing = &mut self.data_objects[id];
790 existing.merge(linkage, writable, tls);
791 Ok((id, existing.linkage))
792 }
793
794 FuncOrDataId::Func(..) => {
795 Err(ModuleError::IncompatibleDeclaration(name.to_owned()))
796 }
797 },
798 Vacant(entry) => {
799 let id = self.data_objects.push(DataDeclaration {
800 name: Some(name.to_owned()),
801 linkage,
802 writable,
803 tls,
804 });
805 entry.insert(FuncOrDataId::Data(id));
806 Ok((id, self.data_objects[id].linkage))
807 }
808 }
809 }
810
811 /// Declare an anonymous data object in this module.
812 pub fn declare_anonymous_data(&mut self, writable: bool, tls: bool) -> ModuleResult<DataId> {

Callers

nothing calls this directly

Calls 7

OkFunction · 0.85
DataClass · 0.85
entryMethod · 0.45
getMethod · 0.45
mergeMethod · 0.45
pushMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected