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

Method arrayInitElem

lib/executor/engine/refInstr.cpp:619–647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

617}
618
619Expect<void>
620Executor::arrayInitElem(Runtime::StackManager &StackMgr, const RefVariant &Ref,
621 const uint32_t TypeIdx, const uint32_t ElemIdx,
622 const uint32_t DstIdx, const uint32_t SrcIdx,
623 const uint32_t Cnt) const noexcept {
624 auto *Inst = Ref.getPtr<Runtime::Instance::ArrayInstance>();
625 if (Inst == nullptr) {
626 return Unexpect(ErrCode::Value::AccessNullArray);
627 }
628 if (static_cast<uint64_t>(DstIdx) + static_cast<uint64_t>(Cnt) >
629 Inst->getLength()) {
630 return Unexpect(ErrCode::Value::ArrayOutOfBounds);
631 }
632 const auto &VType = getArrayStorageTypeByIdx(StackMgr, TypeIdx);
633 auto *ElemInst = getElemInstByIdx(StackMgr, ElemIdx);
634 assuming(ElemInst);
635 auto ElemSrc = ElemInst->getRefs();
636 if (static_cast<uint64_t>(SrcIdx) + static_cast<uint64_t>(Cnt) >
637 ElemSrc.size()) {
638 return Unexpect(ErrCode::Value::TableOutOfBounds);
639 }
640
641 auto Arr = Inst->getArray();
642 // The value has been packed.
643 std::transform(ElemSrc.begin() + SrcIdx, ElemSrc.begin() + SrcIdx + Cnt,
644 Arr.begin() + DstIdx,
645 [&](const RefVariant &V) { return packVal(VType, V); });
646 return {};
647}
648
649Expect<void>
650Executor::arrayCopy(Runtime::StackManager &StackMgr, const RefVariant &DstRef,

Callers

nothing calls this directly

Calls 6

UnexpectFunction · 0.85
getLengthMethod · 0.80
getRefsMethod · 0.45
sizeMethod · 0.45
getArrayMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected