MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / runFunction

Method runFunction

lib/executor/engine/engine.cpp:23–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23Expect<void>
24Executor::runFunction(Runtime::StackManager &StackMgr,
25 const Runtime::Instance::FunctionInstance &Func,
26 Span<const ValVariant> Params) {
27 // Set start time.
28 if (Stat && Conf.getStatisticsConfigure().isTimeMeasuring()) {
29 Stat->startRecordWasm();
30 }
31
32 // Reset and push a dummy frame into stack.
33 StackMgr.pushFrame(nullptr, AST::InstrView::iterator(), 0, 0);
34
35 // Push arguments.
36 const auto &PTypes = Func.getFuncType().getParamTypes();
37 for (uint32_t I = 0; I < Params.size(); I++) {
38 // For the references, transform to non-null reference type if the value not
39 // null.
40 if (PTypes[I].isRefType() && Params[I].get<RefVariant>().getPtr<void>() &&
41 Params[I].get<RefVariant>().getType().isNullableRefType()) {
42 auto Val = Params[I];
43 Val.get<RefVariant>().getType().toNonNullableRef();
44 StackMgr.push(Val);
45 } else {
46 StackMgr.push(Params[I]);
47 }
48 }
49
50 // Enter and execute function.
51 Expect<void> Res =
52 enterFunction(StackMgr, Func, Func.getInstrs().end())
53 .and_then([&](AST::InstrView::iterator StartIt) {
54 // If not terminated, execute the instructions in interpreter mode.
55 // For the entered AOT or host functions, `StartIt` is equal to
56 // the end of instruction list, therefore the execution will return
57 // immediately.
58 return execute(StackMgr, StartIt, Func.getInstrs().end());
59 });
60
61 if (Res) {
62 spdlog::debug(" Execution succeeded."sv);
63 } else if (likely(Res.error() == ErrCode::Value::Terminated)) {
64 spdlog::debug(" Terminated."sv);
65 }
66
67 if (Stat && Conf.getStatisticsConfigure().isTimeMeasuring()) {
68 Stat->stopRecordWasm();
69 }
70
71 // If statistics are enabled, dump them here.
72 if (Stat) {
73 Stat->dumpToLog(Conf);
74 }
75
76 if (!Res && likely(Res.error() == ErrCode::Value::Terminated)) {
77 StackMgr.reset();
78 }
79
80 return Res;

Callers

nothing calls this directly

Calls 15

debugFunction · 0.85
isTimeMeasuringMethod · 0.80
startRecordWasmMethod · 0.80
pushFrameMethod · 0.80
getParamTypesMethod · 0.80
isRefTypeMethod · 0.80
isNullableRefTypeMethod · 0.80
pushMethod · 0.80
stopRecordWasmMethod · 0.80
dumpToLogMethod · 0.80
iteratorClass · 0.50
likelyFunction · 0.50

Tested by

no test coverage detected