/src/WasmEdge/include/runtime/callingframe.h
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: 2019-2024 Second State INC |
3 | | |
4 | | //===-- wasmedge/runtime/callingframe.h - Calling frame definition --------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains the definition of CallingFrame class. |
12 | | /// |
13 | | //===----------------------------------------------------------------------===// |
14 | | #pragma once |
15 | | |
16 | | #include "runtime/instance/module.h" |
17 | | |
18 | | namespace WasmEdge { |
19 | | |
20 | | namespace Executor { |
21 | | class Executor; |
22 | | } |
23 | | |
24 | | namespace Runtime { |
25 | | |
26 | | class CallingFrame { |
27 | | public: |
28 | | CallingFrame(Executor::Executor *E, |
29 | | const Instance::ModuleInstance *M) noexcept |
30 | 0 | : Exec(E), Module(M) {} |
31 | | |
32 | | /// Get the current executor. |
33 | 0 | Executor::Executor *getExecutor() const noexcept { return Exec; } |
34 | | |
35 | | /// Get the current module on this frame. |
36 | 0 | const Instance::ModuleInstance *getModule() const noexcept { return Module; } |
37 | | |
38 | | /// Helper function of getting the WASI module. |
39 | 0 | const Instance::ModuleInstance *getWASIModule() const noexcept { |
40 | 0 | if (Module) { |
41 | 0 | return Module->getWASIModule(); |
42 | 0 | } |
43 | 0 | return nullptr; |
44 | 0 | } |
45 | | |
46 | | /// Helper function of getting the memory instance by index from the module. |
47 | 0 | Instance::MemoryInstance *getMemoryByIndex(uint32_t Index) const noexcept { |
48 | 0 | if (Module) { |
49 | 0 | if (auto Res = Module->getMemory(Index); Res) { |
50 | 0 | return *Res; |
51 | 0 | } |
52 | 0 | } |
53 | 0 | return nullptr; |
54 | 0 | } |
55 | | |
56 | | private: |
57 | | Executor::Executor *Exec; |
58 | | const Instance::ModuleInstance *Module; |
59 | | }; |
60 | | |
61 | | } // namespace Runtime |
62 | | } // namespace WasmEdge |