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

Function ToolOnComponent

lib/driver/runtimeTool.cpp:205–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203}
204
205static int
206ToolOnComponent(WasmEdge::VM::VM &VM, const std::string &FuncName,
207 std::optional<std::chrono::system_clock::time_point> Timeout,
208 struct DriverToolOptions &Opt,
209 const AST::Component::FuncType &FuncType) noexcept {
210 std::vector<ComponentValVariant> FuncArgs;
211 std::vector<ComponentValType> FuncArgTypes;
212
213 const size_t Expected = FuncType.getParamList().size();
214 const size_t Got = Opt.Args.value().size() - 1;
215 if (Got < Expected) {
216 spdlog::error("function `{}` expects {} argument(s), got {}"sv, FuncName,
217 Expected, Got);
218 return EXIT_FAILURE;
219 }
220
221 for (size_t I = 0;
222 I < FuncType.getParamList().size() && I + 1 < Opt.Args.value().size();
223 ++I) {
224 const auto TCode = FuncType.getParamList()[I].getValType().getCode();
225 const auto &ArgValue = Opt.Args.value()[I + 1];
226
227 switch (TCode) {
228 case ComponentTypeCode::S32: {
229 if (!parseNumericArg(
230 ArgValue, I, "s32"sv,
231 [](const std::string &S) {
232 return ValVariant(static_cast<uint32_t>(std::stol(S)));
233 },
234 FuncArgs, FuncArgTypes, TCode)) {
235 return EXIT_FAILURE;
236 }
237 break;
238 }
239 case ComponentTypeCode::U32: {
240 if (!parseNumericArg(
241 ArgValue, I, "u32"sv,
242 [](const std::string &S) {
243 return ValVariant(static_cast<uint32_t>(std::stol(S)));
244 },
245 FuncArgs, FuncArgTypes, TCode)) {
246 return EXIT_FAILURE;
247 }
248 break;
249 }
250 case ComponentTypeCode::S64: {
251 if (!parseNumericArg(
252 ArgValue, I, "s64"sv,
253 [](const std::string &S) {
254 return ValVariant(static_cast<uint64_t>(std::stoll(S)));
255 },
256 FuncArgs, FuncArgTypes, TCode)) {
257 return EXIT_FAILURE;
258 }
259 break;
260 }
261 case ComponentTypeCode::U64: {
262 if (!parseNumericArg(

Callers 1

ToolFunction · 0.85

Calls 12

parseNumericArgFunction · 0.85
printFunction · 0.85
getParamListMethod · 0.80
getValTypeMethod · 0.80
waitUntilMethod · 0.80
cancelMethod · 0.80
errorFunction · 0.50
sizeMethod · 0.45
valueMethod · 0.45
getCodeMethod · 0.45
has_valueMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected