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

Method arrayInitData

lib/executor/engine/refInstr.cpp:589–617  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

587}
588
589Expect<void>
590Executor::arrayInitData(Runtime::StackManager &StackMgr, const RefVariant &Ref,
591 const uint32_t TypeIdx, const uint32_t DataIdx,
592 const uint32_t DstIdx, const uint32_t SrcIdx,
593 const uint32_t Cnt) const noexcept {
594 auto *Inst = Ref.getPtr<Runtime::Instance::ArrayInstance>();
595 if (Inst == nullptr) {
596 return Unexpect(ErrCode::Value::AccessNullArray);
597 }
598 if (static_cast<uint64_t>(DstIdx) + static_cast<uint64_t>(Cnt) >
599 Inst->getLength()) {
600 return Unexpect(ErrCode::Value::ArrayOutOfBounds);
601 }
602 const auto &VType = getArrayStorageTypeByIdx(StackMgr, TypeIdx);
603 const uint32_t BSize = VType.getBitWidth() / 8;
604 auto *DataInst = getDataInstByIdx(StackMgr, DataIdx);
605 assuming(DataInst);
606 if (static_cast<uint64_t>(SrcIdx) + static_cast<uint64_t>(Cnt) * BSize >
607 DataInst->getData().size()) {
608 return Unexpect(ErrCode::Value::MemoryOutOfBounds);
609 }
610
611 for (uint32_t Idx = 0; Idx < Cnt; Idx++) {
612 // The value has been packed.
613 Inst->getData(DstIdx + Idx) =
614 DataInst->loadValue(SrcIdx + Idx * BSize, BSize);
615 }
616 return {};
617}
618
619Expect<void>
620Executor::arrayInitElem(Runtime::StackManager &StackMgr, const RefVariant &Ref,

Callers

nothing calls this directly

Calls 6

UnexpectFunction · 0.85
getLengthMethod · 0.80
getBitWidthMethod · 0.80
sizeMethod · 0.45
getDataMethod · 0.45
loadValueMethod · 0.45

Tested by

no test coverage detected