/src/WasmEdge/lib/executor/instantiate/table.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: 2019-2024 Second State INC |
3 | | |
4 | | #include "executor/executor.h" |
5 | | |
6 | | #include <cstdint> |
7 | | |
8 | | namespace WasmEdge { |
9 | | namespace Executor { |
10 | | |
11 | | // Instantiate table instance. See "include/executor/executor.h". |
12 | | Expect<void> Executor::instantiate(Runtime::StackManager &StackMgr, |
13 | | Runtime::Instance::ModuleInstance &ModInst, |
14 | 0 | const AST::TableSection &TabSec) { |
15 | | // A frame with temp. module is pushed into the stack in caller. |
16 | | |
17 | | // Iterate through the table segments to instantiate and initialize table |
18 | | // instances. |
19 | 0 | for (const auto &TabSeg : TabSec.getContent()) { |
20 | 0 | if (TabSeg.getExpr().getInstrs().size() > 0) { |
21 | | // Run initialize expression. |
22 | 0 | EXPECTED_TRY(runExpression(StackMgr, TabSeg.getExpr().getInstrs()) |
23 | 0 | .map_error([](auto E) { |
24 | 0 | spdlog::error( |
25 | 0 | ErrInfo::InfoAST(ASTNodeAttr::Expression)); |
26 | 0 | return E; |
27 | 0 | })); |
28 | | // Pop result from stack. |
29 | 0 | RefVariant InitTabValue = StackMgr.pop().get<RefVariant>(); |
30 | | // Create and add the table instance into the module instance. |
31 | 0 | ModInst.addTable(TabSeg.getTableType(), InitTabValue); |
32 | 0 | } else { |
33 | | // No init expression case. Use the null reference to initialize. |
34 | 0 | ModInst.addTable(TabSeg.getTableType()); |
35 | 0 | } |
36 | 0 | } |
37 | 0 | return {}; |
38 | 0 | } |
39 | | |
40 | | } // namespace Executor |
41 | | } // namespace WasmEdge |