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

Method new

crates/cranelift/src/debug.rs:81–144  ·  view source on GitHub ↗
(
        isa: &dyn TargetIsa,
        translations: &'a PrimaryMap<StaticModuleIndex, ModuleTranslation<'a>>,
        get_func: &'a dyn Fn(
            StaticModuleIndex,
            DefinedFuncIndex

Source from the content-addressed store, hash-verified

79
80impl<'a> Compilation<'a> {
81 pub fn new(
82 isa: &dyn TargetIsa,
83 translations: &'a PrimaryMap<StaticModuleIndex, ModuleTranslation<'a>>,
84 get_func: &'a dyn Fn(
85 StaticModuleIndex,
86 DefinedFuncIndex,
87 ) -> (SymbolId, &'a CompiledFunctionMetadata),
88 dwarf_package_bytes: Option<&'a [u8]>,
89 tunables: &'a Tunables,
90 ) -> Compilation<'a> {
91 // Build the `module_memory_offsets` map based on the modules in
92 // `translations`.
93 let mut module_memory_offsets = PrimaryMap::new();
94 for (i, translation) in translations {
95 let ofs = VMOffsets::new(
96 isa.triple().architecture.pointer_width().unwrap().bytes(),
97 &translation.module,
98 );
99
100 let memory_offset = if ofs.num_imported_memories > 0 {
101 let index = MemoryIndex::new(0);
102 ModuleMemoryOffset::Imported {
103 offset_to_vm_memory_definition: ofs.vmctx_vmmemory_import(index)
104 + u32::from(ofs.vmmemory_import_from()),
105 offset_to_memory_base: ofs.ptr.vmmemory_definition_base().into(),
106 }
107 } else if ofs.num_owned_memories > 0 {
108 let index = OwnedMemoryIndex::new(0);
109 ModuleMemoryOffset::Defined(ofs.vmctx_vmmemory_definition_base(index))
110 } else if ofs.num_defined_memories > 0 {
111 let index = DefinedMemoryIndex::new(0);
112 ModuleMemoryOffset::Imported {
113 offset_to_vm_memory_definition: ofs.vmctx_vmmemory_pointer(index),
114 offset_to_memory_base: ofs.ptr.vmmemory_definition_base().into(),
115 }
116 } else {
117 ModuleMemoryOffset::None
118 };
119 let j = module_memory_offsets.push(memory_offset);
120 assert_eq!(i, j);
121 }
122
123 // Build the `symbol <=> usize` mappings
124 let mut symbol_index_to_id = Vec::new();
125 let mut symbol_id_to_index = HashMap::new();
126
127 for (module, translation) in translations {
128 for func in translation.module.defined_func_indices() {
129 let (sym, _func) = get_func(module, func);
130 symbol_id_to_index.insert(sym, (symbol_index_to_id.len(), module, func));
131 symbol_index_to_id.push(sym);
132 }
133 }
134
135 Compilation {
136 translations,
137 get_func,
138 dwarf_package_bytes,

Callers

nothing calls this directly

Calls 15

fromFunction · 0.85
vmctx_vmmemory_importMethod · 0.80
vmmemory_import_fromMethod · 0.80
defined_func_indicesMethod · 0.80
newFunction · 0.50
bytesMethod · 0.45
unwrapMethod · 0.45
pointer_widthMethod · 0.45
tripleMethod · 0.45

Tested by

no test coverage detected