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

Function define_simple_function

cranelift/object/tests/basic.rs:34–58  ·  view source on GitHub ↗
(module: &mut ObjectModule)

Source from the content-addressed store, hash-verified

32}
33
34fn define_simple_function(module: &mut ObjectModule) -> FuncId {
35 let sig = Signature {
36 params: vec![],
37 returns: vec![],
38 call_conv: CallConv::SystemV,
39 };
40
41 let func_id = module
42 .declare_function("abc", Linkage::Local, &sig)
43 .unwrap();
44
45 let mut ctx = Context::new();
46 ctx.func = Function::with_name_signature(UserFuncName::user(0, func_id.as_u32()), sig);
47 let mut func_ctx = FunctionBuilderContext::new();
48 {
49 let mut bcx: FunctionBuilder = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
50 let block = bcx.create_block();
51 bcx.switch_to_block(block);
52 bcx.ins().return_(&[]);
53 }
54
55 module.define_function(func_id, &mut ctx).unwrap();
56
57 func_id
58}
59
60#[test]
61#[should_panic(expected = "Result::unwrap()` on an `Err` value: DuplicateDefinition(\"abc\")")]

Calls 8

create_blockMethod · 0.80
switch_to_blockMethod · 0.80
newFunction · 0.50
unwrapMethod · 0.45
declare_functionMethod · 0.45
as_u32Method · 0.45
insMethod · 0.45
define_functionMethod · 0.45

Tested by

no test coverage detected