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

Function main

examples/gcd.cc:16–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16int main() {
17 // Load our WebAssembly (parsed WAT in our case), and then load it into a
18 // `Module` which is attached to a `Store`. After we've got that we
19 // can instantiate it.
20 Engine engine;
21 Store store(engine);
22 auto module = Module::compile(engine, readFile("examples/gcd.wat")).unwrap();
23 auto instance = Instance::create(store, module, {}).unwrap();
24
25 // Invoke `gcd` export
26 auto gcd = std::get<Func>(*instance.get(store, "gcd"));
27 auto results = gcd.call(store, {6, 27}).unwrap();
28
29 std::cout << "gcd(6, 27) = " << results[0].i32() << "\n";
30}

Callers

nothing calls this directly

Calls 7

readFileFunction · 0.70
compileFunction · 0.50
createFunction · 0.50
unwrapMethod · 0.45
getMethod · 0.45
callMethod · 0.45
i32Method · 0.45

Tested by

no test coverage detected