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

Method arrayNewData

lib/executor/engine/refInstr.cpp:493–516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

491}
492
493Expect<RefVariant>
494Executor::arrayNewData(Runtime::StackManager &StackMgr, const uint32_t TypeIdx,
495 const uint32_t DataIdx, const uint32_t Start,
496 const uint32_t Length) const noexcept {
497 const auto &VType = getArrayStorageTypeByIdx(StackMgr, TypeIdx);
498 const uint32_t BSize = VType.getBitWidth() / 8;
499 auto *DataInst = getDataInstByIdx(StackMgr, DataIdx);
500 assuming(DataInst);
501 if (static_cast<uint64_t>(Start) + static_cast<uint64_t>(Length) * BSize >
502 DataInst->getData().size()) {
503 return Unexpect(ErrCode::Value::MemoryOutOfBounds);
504 }
505 Runtime::Instance::ModuleInstance *ModInst =
506 const_cast<Runtime::Instance::ModuleInstance *>(StackMgr.getModule());
507 std::vector<ValVariant> Args;
508 Args.reserve(Length);
509 for (uint32_t Idx = 0; Idx < Length; Idx++) {
510 // The value has been packed.
511 Args.push_back(DataInst->loadValue(Start + Idx * BSize, BSize));
512 }
513 WasmEdge::Runtime::Instance::ArrayInstance *Inst =
514 ModInst->newArray(TypeIdx, std::move(Args));
515 return RefVariant(Inst->getDefType(), Inst);
516}
517
518Expect<RefVariant>
519Executor::arrayNewElem(Runtime::StackManager &StackMgr, const uint32_t TypeIdx,

Callers

nothing calls this directly

Calls 9

UnexpectFunction · 0.85
RefVariantClass · 0.85
getBitWidthMethod · 0.80
newArrayMethod · 0.80
sizeMethod · 0.45
getDataMethod · 0.45
getModuleMethod · 0.45
loadValueMethod · 0.45
getDefTypeMethod · 0.45

Tested by

no test coverage detected