/src/WasmEdge/include/common/symbol.h
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 | | //===-- wasmedge/common/symbol.h - Symbol definition ----------------------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains the declaration of the Symbol, which holds the handle to |
12 | | /// the loaded shared library. |
13 | | /// |
14 | | //===----------------------------------------------------------------------===// |
15 | | #pragma once |
16 | | |
17 | | #include <memory> |
18 | | |
19 | | namespace WasmEdge { |
20 | | class Executable; |
21 | | |
22 | | /// Holder class for library symbol |
23 | | template <typename T = void> class Symbol { |
24 | | private: |
25 | | friend class Executable; |
26 | | template <typename> friend class Symbol; |
27 | | |
28 | | Symbol(std::shared_ptr<const Executable> H, T *S) noexcept |
29 | 0 | : Library(std::move(H)), Pointer(S) {} Unexecuted instantiation: WasmEdge::Symbol<void* const (*) [38]>::Symbol(std::__1::shared_ptr<WasmEdge::Executable const>, void* const (**) [38]) Unexecuted instantiation: WasmEdge::Symbol<void (void*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)>::Symbol(std::__1::shared_ptr<WasmEdge::Executable const>, void (*)(void*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)) Unexecuted instantiation: WasmEdge::Symbol<void>::Symbol(std::__1::shared_ptr<WasmEdge::Executable const>, void*) Unexecuted instantiation: WasmEdge::Symbol<WasmEdge::Plugin::Plugin::PluginDescriptor const* ()>::Symbol(std::__1::shared_ptr<WasmEdge::Executable const>, WasmEdge::Plugin::Plugin::PluginDescriptor const* (*)()) Unexecuted instantiation: WasmEdge::Symbol<WasmEdge_PluginDescriptor const* ()>::Symbol(std::__1::shared_ptr<WasmEdge::Executable const>, WasmEdge_PluginDescriptor const* (*)()) Unexecuted instantiation: WasmEdge::Symbol<unsigned int>::Symbol(std::__1::shared_ptr<WasmEdge::Executable const>, unsigned int*) Unexecuted instantiation: WasmEdge::Symbol<unsigned char>::Symbol(std::__1::shared_ptr<WasmEdge::Executable const>, unsigned char*) |
30 | | |
31 | | public: |
32 | 1.11M | Symbol() = default; WasmEdge::Symbol<void (void*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)>::Symbol() Line | Count | Source | 32 | 8.02k | Symbol() = default; |
WasmEdge::Symbol<void* const (*) [38]>::Symbol() Line | Count | Source | 32 | 9.14k | Symbol() = default; |
WasmEdge::Symbol<void>::Symbol() Line | Count | Source | 32 | 1.09M | Symbol() = default; |
|
33 | 0 | Symbol(const Symbol &) = default; Unexecuted instantiation: WasmEdge::Symbol<void (void*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)>::Symbol(WasmEdge::Symbol<void (void*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)> const&) Unexecuted instantiation: WasmEdge::Symbol<void>::Symbol(WasmEdge::Symbol<void> const&) Unexecuted instantiation: WasmEdge::Symbol<void* const (*) [38]>::Symbol(WasmEdge::Symbol<void* const (*) [38]> const&) |
34 | 0 | Symbol &operator=(const Symbol &) = default; |
35 | 12.2k | Symbol(Symbol &&) = default; Unexecuted instantiation: WasmEdge::Symbol<void* const (*) [38]>::Symbol(WasmEdge::Symbol<void* const (*) [38]>&&) WasmEdge::Symbol<void (void*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)>::Symbol(WasmEdge::Symbol<void (void*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)>&&) Line | Count | Source | 35 | 12.2k | Symbol(Symbol &&) = default; |
Unexecuted instantiation: WasmEdge::Symbol<void>::Symbol(WasmEdge::Symbol<void>&&) |
36 | 0 | Symbol &operator=(Symbol &&) = default; Unexecuted instantiation: WasmEdge::Symbol<void (void*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)>::operator=(WasmEdge::Symbol<void (void*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)>&&) Unexecuted instantiation: WasmEdge::Symbol<void>::operator=(WasmEdge::Symbol<void>&&) Unexecuted instantiation: WasmEdge::Symbol<void* const (*) [38]>::operator=(WasmEdge::Symbol<void* const (*) [38]>&&) |
37 | | |
38 | | explicit Symbol(T *S) noexcept : Pointer(S) {} |
39 | | |
40 | 0 | operator bool() const noexcept { return Pointer != nullptr; } Unexecuted instantiation: WasmEdge::Symbol<void (void*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)>::operator bool() const Unexecuted instantiation: WasmEdge::Symbol<void>::operator bool() const Unexecuted instantiation: WasmEdge::Symbol<unsigned int>::operator bool() const Unexecuted instantiation: WasmEdge::Symbol<unsigned char>::operator bool() const Unexecuted instantiation: WasmEdge::Symbol<void* const (*) [38]>::operator bool() const Unexecuted instantiation: WasmEdge::Symbol<WasmEdge::Plugin::Plugin::PluginDescriptor const* ()>::operator bool() const Unexecuted instantiation: WasmEdge::Symbol<WasmEdge_PluginDescriptor const* ()>::operator bool() const |
41 | 0 | auto &operator*() const noexcept { return *Pointer; } Unexecuted instantiation: WasmEdge::Symbol<unsigned int>::operator*() const Unexecuted instantiation: WasmEdge::Symbol<void* const (*) [38]>::operator*() const |
42 | | auto operator->() const noexcept { return Pointer; } |
43 | | |
44 | | template <typename... ArgT> |
45 | | auto operator()(ArgT... Args) const |
46 | 0 | noexcept(noexcept(this->Pointer(std::forward<ArgT>(Args)...))) { |
47 | 0 | return Pointer(std::forward<ArgT>(Args)...); |
48 | 0 | } Unexecuted instantiation: auto WasmEdge::Symbol<WasmEdge::Plugin::Plugin::PluginDescriptor const* ()>::operator()<>() const Unexecuted instantiation: auto WasmEdge::Symbol<WasmEdge_PluginDescriptor const* ()>::operator()<>() const Unexecuted instantiation: auto WasmEdge::Symbol<void (void*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)>::operator()<WasmEdge::Executor::Executor::ExecutionContextStruct*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*>(WasmEdge::Executor::Executor::ExecutionContextStruct*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*) const |
49 | | |
50 | 0 | auto get() const noexcept { return Pointer; } Unexecuted instantiation: WasmEdge::Symbol<unsigned char>::get() const Unexecuted instantiation: WasmEdge::Symbol<void>::get() const Unexecuted instantiation: WasmEdge::Symbol<void (void*, void*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)>::get() const |
51 | | auto deref() & { return Symbol<std::remove_pointer_t<T>>(Library, *Pointer); } |
52 | | auto deref() && { |
53 | | return Symbol<std::remove_pointer_t<T>>(std::move(Library), *Pointer); |
54 | | } |
55 | | |
56 | | private: |
57 | | std::shared_ptr<const Executable> Library; |
58 | | T *Pointer = nullptr; |
59 | | }; |
60 | | |
61 | | template <typename T> class Symbol<T[]> { |
62 | | private: |
63 | | friend class Executable; |
64 | | template <typename> friend class Symbol; |
65 | | |
66 | | Symbol(std::shared_ptr<const Executable> H, T (*S)[]) noexcept |
67 | | : Library(std::move(H)), Pointer(*S) {} |
68 | | |
69 | | public: |
70 | | Symbol() = default; |
71 | | Symbol(const Symbol &) = default; |
72 | | Symbol &operator=(const Symbol &) = default; |
73 | | Symbol(Symbol &&) = default; |
74 | | Symbol &operator=(Symbol &&) = default; |
75 | | |
76 | | explicit Symbol(T *S) noexcept : Pointer(S) {} |
77 | | |
78 | | operator bool() const noexcept { return Pointer != nullptr; } |
79 | | auto &operator[](size_t Index) const noexcept { return Pointer[Index]; } |
80 | | |
81 | | auto get() const noexcept { return Pointer; } |
82 | | auto index(size_t Index) & { return Symbol<T>(Library, &Pointer[Index]); } |
83 | | auto index(size_t Index) && { |
84 | | return Symbol<T>(std::move(Library), &Pointer[Index]); |
85 | | } |
86 | | |
87 | | private: |
88 | | std::shared_ptr<const Executable> Library; |
89 | | T *Pointer = nullptr; |
90 | | }; |
91 | | |
92 | | } // namespace WasmEdge |