Wasmtime
import.hh
Go to the documentation of this file.
1
5#ifndef WASMTIME_TYPES_IMPORT_HH
6#define WASMTIME_TYPES_IMPORT_HH
7
8#include <string_view>
9#include <wasm.h>
10#include <wasmtime/helpers.hh>
11
12namespace wasmtime {
13
19#define wasm_importtype_clone wasm_importtype_copy
20 WASMTIME_CLONE_WRAPPER(ImportType, wasm_importtype);
21#undef wasm_importtype_clone
22
25 class Ref {
26 friend class ExternType;
27
28 const wasm_importtype_t *ptr;
29
30 // TODO: can this circle be broken another way?
31 const wasm_externtype_t *raw_type() const {
32 return wasm_importtype_type(ptr);
33 }
34
35 public:
37 Ref(const wasm_importtype_t *ptr) : ptr(ptr) {}
38
40 std::string_view module() const {
41 const auto *name = wasm_importtype_module(ptr);
42 return std::string_view(name->data, name->size);
43 }
44
46 std::string_view name() const {
47 const auto *name = wasm_importtype_name(ptr);
48 return std::string_view(name->data, name->size);
49 }
50 };
51
53 Ref ref() const { return Ref(ptr.get()); }
54
56 class List {
57 friend class Module;
59
60 public:
62 List() : list{} {
63 list.size = 0;
64 list.data = nullptr;
65 }
66 List(const List &other) = delete;
68 List(List &&other) noexcept : list(other.list) { other.list.size = 0; }
69 ~List() {
70 if (list.size > 0) {
72 }
73 }
74
75 List &operator=(const List &other) = delete;
77 List &operator=(List &&other) noexcept {
78 std::swap(list, other.list);
79 return *this;
80 }
81
84 typedef const Ref *iterator;
86 iterator begin() const {
87 return reinterpret_cast<iterator>(&list.data[0]); // NOLINT
88 }
90 iterator end() const {
91 return reinterpret_cast<iterator>(&list.data[list.size]); // NOLINT
92 }
94 size_t size() const { return list.size; }
95 };
96};
97
98}; // namespace wasmtime
99
100#endif // WASMTIME_TYPES_IMPORT_HH
Type information about a WebAssembly import.
Definition: import.hh:17
An opaque object representing the type of a external value. Can be seen as a superclass of wasm_funct...
An opaque object representing the type of an import.
A list of wasm_importtype_t values.
Definition: wasm.h:307
wasm_importtype_t ** data
Pointer to the base of this vector.
Definition: wasm.h:307
size_t size
Length of this vector.
Definition: wasm.h:307
const wasm_externtype_t * wasm_importtype_type(const wasm_importtype_t *)
Returns the type of item this import is importing.
const wasm_name_t * wasm_importtype_name(const wasm_importtype_t *)
Returns the name this import is importing from.
const wasm_name_t * wasm_importtype_module(const wasm_importtype_t *)
Returns the module this import is importing from.
void wasm_importtype_vec_delete(wasm_importtype_vec_t *)
Deallocates import for a vector.