Coverage Report

Created: 2025-07-01 06:18

/src/WasmEdge/include/executor/engine/memory.ipp
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
#include "runtime/instance/memory.h"
6
7
#include <cstdint>
8
9
namespace WasmEdge {
10
namespace Executor {
11
12
template <typename T, uint32_t BitWidth>
13
TypeT<T> Executor::runLoadOp(Runtime::StackManager &StackMgr,
14
                             Runtime::Instance::MemoryInstance &MemInst,
15
0
                             const AST::Instruction &Instr) {
16
  // Calculate EA
17
0
  ValVariant &Val = StackMgr.getTop();
18
0
  if (Val.get<uint32_t>() >
19
0
      std::numeric_limits<uint32_t>::max() - Instr.getMemoryOffset()) {
20
0
    spdlog::error(ErrCode::Value::MemoryOutOfBounds);
21
0
    spdlog::error(ErrInfo::InfoBoundary(
22
0
        Val.get<uint32_t>() + static_cast<uint64_t>(Instr.getMemoryOffset()),
23
0
        BitWidth / 8, MemInst.getBoundIdx()));
24
0
    spdlog::error(
25
0
        ErrInfo::InfoInstruction(Instr.getOpCode(), Instr.getOffset()));
26
0
    return Unexpect(ErrCode::Value::MemoryOutOfBounds);
27
0
  }
28
0
  uint32_t EA = Val.get<uint32_t>() + Instr.getMemoryOffset();
29
30
  // Value = Mem.Data[EA : N / 8]
31
0
  return MemInst.loadValue<T, BitWidth / 8>(Val.emplace<T>(), EA)
32
0
      .map_error([&Instr](auto E) {
33
0
        spdlog::error(
34
0
            ErrInfo::InfoInstruction(Instr.getOpCode(), Instr.getOffset()));
35
0
        return E;
36
0
      });
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<unsigned int, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<unsigned long, 64u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<float, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<double, 64u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<int, 8u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<unsigned int, 8u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<int, 16u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<unsigned int, 16u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<long, 8u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<unsigned long, 8u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<long, 16u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<unsigned long, 16u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<long, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<unsigned long, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<unsigned __int128, 128u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<unsigned __int128, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadOp<unsigned __int128, 64u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
37
0
}
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<unsigned int>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<unsigned int, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<unsigned long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<unsigned long, 64u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<float>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<float, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<double>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<double, 64u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<int>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<int, 8u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<unsigned int>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<unsigned int, 8u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<int>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<int, 16u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<unsigned int>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<unsigned int, 16u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<long, 8u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<unsigned long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<unsigned long, 8u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<long, 16u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<unsigned long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<unsigned long, 16u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<long, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<unsigned long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<unsigned long, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<unsigned __int128>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<unsigned __int128, 128u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<unsigned __int128>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<unsigned __int128, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNumV<unsigned __int128>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runLoadOp<unsigned __int128, 64u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
38
39
template <typename T, uint32_t BitWidth>
40
TypeN<T> Executor::runStoreOp(Runtime::StackManager &StackMgr,
41
                              Runtime::Instance::MemoryInstance &MemInst,
42
0
                              const AST::Instruction &Instr) {
43
  // Pop the value t.const c from the Stack
44
0
  T C = StackMgr.pop().get<T>();
45
46
  // Calculate EA = i + offset
47
0
  uint32_t I = StackMgr.pop().get<uint32_t>();
48
0
  if (I > std::numeric_limits<uint32_t>::max() - Instr.getMemoryOffset()) {
49
0
    spdlog::error(ErrCode::Value::MemoryOutOfBounds);
50
0
    spdlog::error(ErrInfo::InfoBoundary(
51
0
        I + static_cast<uint64_t>(Instr.getMemoryOffset()), BitWidth / 8,
52
0
        MemInst.getBoundIdx()));
53
0
    spdlog::error(
54
0
        ErrInfo::InfoInstruction(Instr.getOpCode(), Instr.getOffset()));
55
0
    return Unexpect(ErrCode::Value::MemoryOutOfBounds);
56
0
  }
57
0
  uint32_t EA = I + Instr.getMemoryOffset();
58
59
  // Store value to bytes.
60
0
  return MemInst.storeValue<T, BitWidth / 8>(C, EA).map_error([&Instr](auto E) {
61
0
    spdlog::error(
62
0
        ErrInfo::InfoInstruction(Instr.getOpCode(), Instr.getOffset()));
63
0
    return E;
64
0
  });
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreOp<unsigned int, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreOp<unsigned long, 64u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreOp<float, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreOp<double, 64u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreOp<unsigned int, 8u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreOp<unsigned int, 16u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreOp<unsigned long, 8u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreOp<unsigned long, 16u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreOp<unsigned long, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreOp<unsigned __int128, 128u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
65
0
}
Unexecuted instantiation: std::__1::enable_if<IsWasmNativeNumV<unsigned int>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runStoreOp<unsigned int, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNativeNumV<unsigned long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runStoreOp<unsigned long, 64u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNativeNumV<float>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runStoreOp<float, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNativeNumV<double>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runStoreOp<double, 64u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNativeNumV<unsigned int>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runStoreOp<unsigned int, 8u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNativeNumV<unsigned int>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runStoreOp<unsigned int, 16u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNativeNumV<unsigned long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runStoreOp<unsigned long, 8u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNativeNumV<unsigned long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runStoreOp<unsigned long, 16u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNativeNumV<unsigned long>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runStoreOp<unsigned long, 32u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: std::__1::enable_if<IsWasmNativeNumV<unsigned __int128>, cxx20::expected<void, WasmEdge::ErrCode> >::type WasmEdge::Executor::Executor::runStoreOp<unsigned __int128, 128u>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
66
67
template <typename TIn, typename TOut>
68
Expect<void>
69
Executor::runLoadExpandOp(Runtime::StackManager &StackMgr,
70
                          Runtime::Instance::MemoryInstance &MemInst,
71
0
                          const AST::Instruction &Instr) {
72
0
  static_assert(sizeof(TOut) == sizeof(TIn) * 2);
73
  // Calculate EA
74
0
  ValVariant &Val = StackMgr.getTop();
75
0
  if (Val.get<uint32_t>() >
76
0
      std::numeric_limits<uint32_t>::max() - Instr.getMemoryOffset()) {
77
0
    spdlog::error(ErrCode::Value::MemoryOutOfBounds);
78
0
    spdlog::error(ErrInfo::InfoBoundary(
79
0
        Val.get<uint32_t>() + static_cast<uint64_t>(Instr.getMemoryOffset()), 8,
80
0
        MemInst.getBoundIdx()));
81
0
    spdlog::error(
82
0
        ErrInfo::InfoInstruction(Instr.getOpCode(), Instr.getOffset()));
83
0
    return Unexpect(ErrCode::Value::MemoryOutOfBounds);
84
0
  }
85
0
  uint32_t EA = Val.get<uint32_t>() + Instr.getMemoryOffset();
86
87
  // Value = Mem.Data[EA : N / 8]
88
0
  uint64_t Buffer;
89
0
  return MemInst.loadValue<decltype(Buffer), 8>(Buffer, EA)
90
0
      .map_error([&Instr](auto E) {
91
0
        spdlog::error(
92
0
            ErrInfo::InfoInstruction(Instr.getOpCode(), Instr.getOffset()));
93
0
        return E;
94
0
      })
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadExpandOp<signed char, short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadExpandOp<unsigned char, unsigned short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadExpandOp<short, int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadExpandOp<unsigned short, unsigned int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadExpandOp<int, long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadExpandOp<unsigned int, unsigned long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
95
0
      .map([&]() {
96
0
        using VTIn = SIMDArray<TIn, 8>;
97
0
        using VTOut = SIMDArray<TOut, 16>;
98
99
0
        VTIn Value;
100
0
        std::memcpy(&Value, &Buffer, 8);
101
102
0
        if constexpr (sizeof(TOut) == 2) {
103
0
          Val.emplace<VTOut>(VTOut{Value[0], Value[1], Value[2], Value[3],
104
0
                                   Value[4], Value[5], Value[6], Value[7]});
105
0
        } else if constexpr (sizeof(TOut) == 4) {
106
0
          Val.emplace<VTOut>(VTOut{Value[0], Value[1], Value[2], Value[3]});
107
0
        } else if constexpr (sizeof(TOut) == 8) {
108
0
          Val.emplace<VTOut>(VTOut{Value[0], Value[1]});
109
0
        }
110
0
      });
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadExpandOp<signed char, short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadExpandOp<unsigned char, unsigned short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadExpandOp<short, int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadExpandOp<unsigned short, unsigned int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadExpandOp<int, long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadExpandOp<unsigned int, unsigned long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
111
0
}
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadExpandOp<signed char, short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadExpandOp<unsigned char, unsigned short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadExpandOp<short, int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadExpandOp<unsigned short, unsigned int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadExpandOp<int, long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadExpandOp<unsigned int, unsigned long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
112
113
template <typename T>
114
Expect<void>
115
Executor::runLoadSplatOp(Runtime::StackManager &StackMgr,
116
                         Runtime::Instance::MemoryInstance &MemInst,
117
0
                         const AST::Instruction &Instr) {
118
  // Calculate EA
119
0
  ValVariant &Val = StackMgr.getTop();
120
0
  if (Val.get<uint32_t>() >
121
0
      std::numeric_limits<uint32_t>::max() - Instr.getMemoryOffset()) {
122
0
    spdlog::error(ErrCode::Value::MemoryOutOfBounds);
123
0
    spdlog::error(ErrInfo::InfoBoundary(
124
0
        Val.get<uint32_t>() + static_cast<uint64_t>(Instr.getMemoryOffset()),
125
0
        sizeof(T), MemInst.getBoundIdx()));
126
0
    spdlog::error(
127
0
        ErrInfo::InfoInstruction(Instr.getOpCode(), Instr.getOffset()));
128
0
    return Unexpect(ErrCode::Value::MemoryOutOfBounds);
129
0
  }
130
0
  uint32_t EA = Val.get<uint32_t>() + Instr.getMemoryOffset();
131
132
  // Value = Mem.Data[EA : N / 8]
133
0
  using VT = SIMDArray<T, 16>;
134
0
  uint64_t Buffer;
135
0
  return MemInst.loadValue<decltype(Buffer), sizeof(T)>(Buffer, EA)
136
0
      .map_error([&Instr](auto E) {
137
0
        spdlog::error(
138
0
            ErrInfo::InfoInstruction(Instr.getOpCode(), Instr.getOffset()));
139
0
        return E;
140
0
      })
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadSplatOp<unsigned char>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadSplatOp<unsigned short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadSplatOp<unsigned int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadSplatOp<unsigned long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
141
0
      .map([&]() {
142
0
        const T Part = static_cast<T>(Buffer);
143
144
0
        if constexpr (sizeof(T) == 1) {
145
0
          Val.emplace<VT>(VT{Part, Part, Part, Part, Part, Part, Part, Part,
146
0
                             Part, Part, Part, Part, Part, Part, Part, Part});
147
0
        } else if constexpr (sizeof(T) == 2) {
148
0
          Val.emplace<VT>(VT{Part, Part, Part, Part, Part, Part, Part, Part});
149
0
        } else if constexpr (sizeof(T) == 4) {
150
0
          Val.emplace<VT>(VT{Part, Part, Part, Part});
151
0
        } else if constexpr (sizeof(T) == 8) {
152
0
          Val.emplace<VT>(VT{Part, Part});
153
0
        }
154
0
      });
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadSplatOp<unsigned char>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadSplatOp<unsigned short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadSplatOp<unsigned int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadSplatOp<unsigned long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
155
0
}
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadSplatOp<unsigned char>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadSplatOp<unsigned short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadSplatOp<unsigned int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadSplatOp<unsigned long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
156
157
template <typename T>
158
Expect<void> Executor::runLoadLaneOp(Runtime::StackManager &StackMgr,
159
                                     Runtime::Instance::MemoryInstance &MemInst,
160
0
                                     const AST::Instruction &Instr) {
161
0
  using VT = SIMDArray<T, 16>;
162
0
  VT Result = StackMgr.pop().get<VT>();
163
164
  // Calculate EA
165
0
  ValVariant &Val = StackMgr.getTop();
166
0
  const uint32_t Offset = Val.get<uint32_t>();
167
0
  if (Offset > std::numeric_limits<uint32_t>::max() - Instr.getMemoryOffset()) {
168
0
    spdlog::error(ErrCode::Value::MemoryOutOfBounds);
169
0
    spdlog::error(ErrInfo::InfoBoundary(
170
0
        Offset + static_cast<uint64_t>(Instr.getMemoryOffset()), sizeof(T),
171
0
        MemInst.getBoundIdx()));
172
0
    spdlog::error(
173
0
        ErrInfo::InfoInstruction(Instr.getOpCode(), Instr.getOffset()));
174
0
    return Unexpect(ErrCode::Value::MemoryOutOfBounds);
175
0
  }
176
0
  const uint32_t EA = Offset + Instr.getMemoryOffset();
177
178
  // Value = Mem.Data[EA : N / 8]
179
0
  uint64_t Buffer;
180
0
  return MemInst.loadValue<decltype(Buffer), sizeof(T)>(Buffer, EA)
181
0
      .map_error([&Instr](auto E) {
182
0
        spdlog::error(
183
0
            ErrInfo::InfoInstruction(Instr.getOpCode(), Instr.getOffset()));
184
0
        return E;
185
0
      })
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadLaneOp<unsigned char>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadLaneOp<unsigned short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadLaneOp<unsigned int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runLoadLaneOp<unsigned long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
186
0
      .map([&]() {
187
0
        Result[Instr.getMemoryLane()] = static_cast<T>(Buffer);
188
0
        Val.emplace<VT>(Result);
189
0
      });
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadLaneOp<unsigned char>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadLaneOp<unsigned short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadLaneOp<unsigned int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
Unexecuted instantiation: WasmEdge::Executor::Executor::runLoadLaneOp<unsigned long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda()#1}::operator()() const
190
0
}
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadLaneOp<unsigned char>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadLaneOp<unsigned short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadLaneOp<unsigned int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runLoadLaneOp<unsigned long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
191
192
template <typename T>
193
Expect<void>
194
Executor::runStoreLaneOp(Runtime::StackManager &StackMgr,
195
                         Runtime::Instance::MemoryInstance &MemInst,
196
0
                         const AST::Instruction &Instr) {
197
0
  using VT = SIMDArray<T, 16>;
198
0
  using TBuf = std::conditional_t<sizeof(T) < 4, uint32_t, T>;
199
0
  const TBuf C = StackMgr.pop().get<VT>()[Instr.getMemoryLane()];
200
201
  // Calculate EA = i + offset
202
0
  uint32_t I = StackMgr.pop().get<uint32_t>();
203
0
  if (I > std::numeric_limits<uint32_t>::max() - Instr.getMemoryOffset()) {
204
0
    spdlog::error(ErrCode::Value::MemoryOutOfBounds);
205
0
    spdlog::error(ErrInfo::InfoBoundary(
206
0
        I + static_cast<uint64_t>(Instr.getMemoryOffset()), sizeof(T),
207
0
        MemInst.getBoundIdx()));
208
0
    spdlog::error(
209
0
        ErrInfo::InfoInstruction(Instr.getOpCode(), Instr.getOffset()));
210
0
    return Unexpect(ErrCode::Value::MemoryOutOfBounds);
211
0
  }
212
0
  uint32_t EA = I + Instr.getMemoryOffset();
213
214
  // Store value to bytes.
215
0
  return MemInst.storeValue<decltype(C), sizeof(T)>(C, EA).map_error(
216
0
      [&Instr](auto E) {
217
0
        spdlog::error(
218
0
            ErrInfo::InfoInstruction(Instr.getOpCode(), Instr.getOffset()));
219
0
        return E;
220
0
      });
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreLaneOp<unsigned char>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreLaneOp<unsigned short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreLaneOp<unsigned int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
Unexecuted instantiation: auto WasmEdge::Executor::Executor::runStoreLaneOp<unsigned long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)::{lambda(auto:1)#1}::operator()<WasmEdge::ErrCode>(WasmEdge::ErrCode) const
221
0
}
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runStoreLaneOp<unsigned char>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runStoreLaneOp<unsigned short>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runStoreLaneOp<unsigned int>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
Unexecuted instantiation: cxx20::expected<void, WasmEdge::ErrCode> WasmEdge::Executor::Executor::runStoreLaneOp<unsigned long>(WasmEdge::Runtime::StackManager&, WasmEdge::Runtime::Instance::MemoryInstance&, WasmEdge::AST::Instruction const&)
222
223
} // namespace Executor
224
} // namespace WasmEdge