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

Function libcall

cranelift/interpreter/src/interpreter.rs:956–983  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

954
955 #[test]
956 fn libcall() {
957 let code = "function %test() -> i64 {
958 fn0 = colocated %CeilF32 (f32) -> f32 fast
959 block0:
960 v1 = f32const 0x0.5
961 v2 = call fn0(v1)
962 return v2
963 }";
964
965 let func = parse_functions(code).unwrap().into_iter().next().unwrap();
966 let mut env = FunctionStore::default();
967 env.add(func.name.to_string(), &func);
968 let state = InterpreterState::default()
969 .with_function_store(env)
970 .with_libcall_handler(|libcall, args| {
971 Ok(smallvec![match (libcall, &args[..]) {
972 (LibCall::CeilF32, [DataValue::F32(a)]) => DataValue::F32(a.ceil()),
973 _ => panic!("Unexpected args"),
974 }])
975 });
976
977 let result = Interpreter::new(state).call_by_name("%test", &[]).unwrap();
978
979 assert_eq!(
980 result,
981 ControlFlow::Return(smallvec![DataValue::F32(Ieee32::with_float(1.0))])
982 )
983 }
984
985 #[test]
986 fn misaligned_store_traps() {

Callers

nothing calls this directly

Calls 11

parse_functionsFunction · 0.85
OkFunction · 0.85
with_libcall_handlerMethod · 0.80
with_function_storeMethod · 0.80
call_by_nameMethod · 0.80
newFunction · 0.50
unwrapMethod · 0.45
nextMethod · 0.45
into_iterMethod · 0.45
addMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected