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

Function try_call

cranelift/frontend/src/frontend.rs:1947–2032  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1945
1946 #[test]
1947 fn try_call() {
1948 let mut sig = Signature::new(CallConv::SystemV);
1949 sig.params.push(AbiParam::new(I8));
1950 sig.returns.push(AbiParam::new(I32));
1951 let mut fn_ctx = FunctionBuilderContext::new();
1952 let mut func = Function::with_name_signature(UserFuncName::testcase("sample"), sig);
1953
1954 let sig0 = func.import_signature(Signature::new(CallConv::SystemV));
1955 let name = func.declare_imported_user_function(UserExternalName::new(0, 0));
1956 let fn0 = func.import_function(ExtFuncData {
1957 name: ExternalName::User(name),
1958 signature: sig0,
1959 colocated: false,
1960 patchable: false,
1961 });
1962
1963 let mut builder = FunctionBuilder::new(&mut func, &mut fn_ctx);
1964
1965 let block0 = builder.create_block();
1966 let block1 = builder.create_block();
1967 let block2 = builder.create_block();
1968 let block3 = builder.create_block();
1969
1970 let my_var = builder.declare_var(I32);
1971
1972 builder.switch_to_block(block0);
1973 let branch_val = builder.append_block_param(block0, I8);
1974 builder.ins().brif(branch_val, block1, &[], block2, &[]);
1975
1976 builder.switch_to_block(block1);
1977 let one = builder.ins().iconst(I32, 1);
1978 builder.def_var(my_var, one);
1979
1980 let normal_return = BlockCall::new(block3, [], &mut builder.func.dfg.value_lists);
1981 let exception_table = builder
1982 .func
1983 .dfg
1984 .exception_tables
1985 .push(ExceptionTableData::new(sig0, normal_return, []));
1986 builder.ins().try_call(fn0, &[], exception_table);
1987
1988 builder.switch_to_block(block2);
1989 let two = builder.ins().iconst(I32, 2);
1990 builder.def_var(my_var, two);
1991
1992 let normal_return = BlockCall::new(block3, [], &mut builder.func.dfg.value_lists);
1993 let exception_table = builder
1994 .func
1995 .dfg
1996 .exception_tables
1997 .push(ExceptionTableData::new(sig0, normal_return, []));
1998 builder.ins().try_call(fn0, &[], exception_table);
1999
2000 builder.switch_to_block(block3);
2001 let ret_val = builder.use_var(my_var);
2002 builder.ins().return_(&[ret_val]);
2003
2004 builder.seal_all_blocks();

Callers

nothing calls this directly

Calls 15

create_blockMethod · 0.80
declare_varMethod · 0.80
switch_to_blockMethod · 0.80
checkFunction · 0.70
newFunction · 0.50
builderFunction · 0.50
pushMethod · 0.45
import_signatureMethod · 0.45
import_functionMethod · 0.45
append_block_paramMethod · 0.45
insMethod · 0.45

Tested by

no test coverage detected