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() { return wasm_importtype_type(ptr); }
32
33 public:
35 Ref(const wasm_importtype_t *ptr) : ptr(ptr) {}
36
38 std::string_view module() {
39 const auto *name = wasm_importtype_module(ptr);
40 return std::string_view(name->data, name->size);
41 }
42
44 std::string_view name() {
45 const auto *name = wasm_importtype_name(ptr);
46 return std::string_view(name->data, name->size);
47 }
48 };
49
51 Ref ref() const { return Ref(ptr.get()); }
52
54 class List {
55 friend class Module;
57
58 public:
60 List() : list{} {
61 list.size = 0;
62 list.data = nullptr;
63 }
64 List(const List &other) = delete;
66 List(List &&other) noexcept : list(other.list) { other.list.size = 0; }
67 ~List() {
68 if (list.size > 0) {
70 }
71 }
72
73 List &operator=(const List &other) = delete;
75 List &operator=(List &&other) noexcept {
76 std::swap(list, other.list);
77 return *this;
78 }
79
82 typedef const Ref *iterator;
84 iterator begin() const {
85 return reinterpret_cast<iterator>(&list.data[0]); // NOLINT
86 }
88 iterator end() const {
89 return reinterpret_cast<iterator>(&list.data[list.size]); // NOLINT
90 }
92 size_t size() const { return list.size; }
93 };
94};
95
96}; // namespace wasmtime
97
98#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:293
wasm_importtype_t ** data
Pointer to the base of this vector.
Definition: wasm.h:293
size_t size
Length of this vector.
Definition: wasm.h:293
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.