| 21 | } |
| 22 | |
| 23 | Expect<void> |
| 24 | Executor::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; |
nothing calls this directly
no test coverage detected