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

Method define_function

cranelift/filetests/src/function_runner.rs:255–275  ·  view source on GitHub ↗

Defines the body of a function

(
        &mut self,
        mut func: Function,
        ctrl_plane: &mut ControlPlane,
    )

Source from the content-addressed store, hash-verified

253
254 /// Defines the body of a function
255 pub fn define_function(
256 &mut self,
257 mut func: Function,
258 ctrl_plane: &mut ControlPlane,
259 ) -> Result<()> {
260 Self::replace_hostcall_references(&mut func);
261
262 let defined_func = self
263 .defined_functions
264 .get(&func.name)
265 .ok_or(anyhow!("Undeclared function {} found!", &func.name))?;
266
267 self.ctx.func = self.apply_func_rename(func, defined_func)?;
268 self.module.define_function_with_control_plane(
269 defined_func.func_id,
270 &mut self.ctx,
271 ctrl_plane,
272 )?;
273 self.module.clear_context(&mut self.ctx);
274 Ok(())
275 }
276
277 fn replace_hostcall_references(func: &mut Function) {
278 // For every `func_addr` referring to a hostcall that we

Callers 10

add_functionsMethod · 0.45
nopFunction · 0.45
define_simple_functionFunction · 0.45
mainFunction · 0.45
define_simple_functionFunction · 0.45
libcall_functionFunction · 0.45
define_leafFunction · 0.45

Calls 5

OkFunction · 0.85
apply_func_renameMethod · 0.80
getMethod · 0.45
clear_contextMethod · 0.45

Tested by 7

nopFunction · 0.36
define_simple_functionFunction · 0.36
define_simple_functionFunction · 0.36
libcall_functionFunction · 0.36
define_leafFunction · 0.36