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

Method initTable

lib/executor/instantiate/elem.cpp:73–113  ·  view source on GitHub ↗

Initialize table with Element section. See "include/executor/executor.h".

Source from the content-addressed store, hash-verified

71
72// Initialize table with Element section. See "include/executor/executor.h".
73Expect<void> Executor::initTable(Runtime::StackManager &StackMgr,
74 const AST::ElementSection &ElemSec) {
75 // Initialize tables.
76 uint32_t Idx = 0;
77 for (const auto &ElemSeg : ElemSec.getContent()) {
78 // Element index is checked in validation phase.
79 auto *ElemInst = getElemInstByIdx(StackMgr, Idx);
80 assuming(ElemInst);
81 if (ElemSeg.getMode() == AST::ElementSegment::ElemMode::Active) {
82 // Table index is checked in validation phase.
83 auto *TabInst = getTabInstByIdx(StackMgr, ElemSeg.getIdx());
84 assuming(TabInst);
85 const uint64_t Off = ElemInst->getOffset();
86
87 // Replace table[Off : Off + n] with elem[0 : n].
88 EXPECTED_TRY(
89 TabInst
90 ->setRefs(ElemInst->getRefs(), Off, 0, ElemInst->getRefs().size())
91 .map_error([](auto E) {
92 spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Seg_Element));
93 return E;
94 }));
95
96 // Drop the element instance.
97 ElemInst->clear();
98
99 // Operation above is equal to the following instruction sequence:
100 // expr(init) -> i32.const off
101 // i32.const 0
102 // i32.const n
103 // table.init idx
104 // elem.drop idx
105 } else if (ElemSeg.getMode() ==
106 AST::ElementSegment::ElemMode::Declarative) {
107 // Drop the element instance.
108 ElemInst->clear();
109 }
110 Idx++;
111 }
112 return {};
113}
114
115} // namespace Executor
116} // namespace WasmEdge

Callers

nothing calls this directly

Calls 11

InfoASTClass · 0.85
setRefsMethod · 0.80
EXPECTED_TRYFunction · 0.50
errorFunction · 0.50
getContentMethod · 0.45
getModeMethod · 0.45
getIdxMethod · 0.45
getOffsetMethod · 0.45
getRefsMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected