wasmer_wast/
spectest.rs

1use wasmer::*;
2
3/// Return an instance implementing the "spectest" interface used in the
4/// spec testsuite.
5#[allow(clippy::print_stdout)]
6pub fn spectest_importobject(store: &mut Store) -> Imports {
7    let print = Function::new_typed(store, || {});
8    let print_i32 = Function::new_typed(store, |val: i32| println!("{val}: i32"));
9    let print_i64 = Function::new_typed(store, |val: i64| println!("{val}: i64"));
10    let print_f32 = Function::new_typed(store, |val: f32| println!("{val}: f32"));
11    let print_f64 = Function::new_typed(store, |val: f64| println!("{val}: f64"));
12    let print_i32_f32 = Function::new_typed(store, |i: i32, f: f32| {
13        println!("{i}: i32");
14        println!("{f}: f32");
15    });
16    let print_f64_f64 = Function::new_typed(store, |f1: f64, f2: f64| {
17        println!("{f1}: f64");
18        println!("{f2}: f64");
19    });
20
21    let global_i32 = Global::new(store, Value::I32(666));
22    let global_i64 = Global::new(store, Value::I64(666));
23    let global_f32 = Global::new(store, Value::F32(666.6));
24    let global_f64 = Global::new(store, Value::F64(666.6));
25
26    let ty = TableType::new(Type::FuncRef, 10, Some(20));
27    let table = Table::new(store, ty, Value::FuncRef(None)).unwrap();
28
29    let ty = MemoryType::new(1, Some(2), false);
30    let memory = Memory::new(store, ty).unwrap();
31
32    let ty = MemoryType::new(1, Some(2), true);
33    let shared_memory = Memory::new(store, ty).unwrap();
34
35    imports! {
36        "spectest" => {
37            "print" => print,
38            "print_i32" => print_i32,
39            "print_i64" => print_i64,
40            "print_f32" => print_f32,
41            "print_f64" => print_f64,
42            "print_i32_f32" => print_i32_f32,
43            "print_f64_f64" => print_f64_f64,
44            "global_i32" => global_i32,
45            "global_i64" => global_i64,
46            "global_f32" => global_f32,
47            "global_f64" => global_f64,
48            "table" => table,
49            "memory" => memory,
50            "shared_memory" => shared_memory,
51        },
52    }
53}