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
11namespace wasmtime {
12
17public:
20 class Ref {
21 friend class ExternType;
22
23 const wasm_importtype_t *ptr;
24
25 // TODO: can this circle be broken another way?
26 const wasm_externtype_t *raw_type() { return wasm_importtype_type(ptr); }
27
28 public:
30 Ref(const wasm_importtype_t *ptr) : ptr(ptr) {}
31
33 std::string_view module() {
34 const auto *name = wasm_importtype_module(ptr);
35 return std::string_view(name->data, name->size);
36 }
37
39 std::string_view name() {
40 const auto *name = wasm_importtype_name(ptr);
41 return std::string_view(name->data, name->size);
42 }
43 };
44
46 class List {
47 friend class Module;
49
50 public:
52 List() : list{} {
53 list.size = 0;
54 list.data = nullptr;
55 }
56 List(const List &other) = delete;
58 List(List &&other) noexcept : list(other.list) { other.list.size = 0; }
59 ~List() {
60 if (list.size > 0) {
62 }
63 }
64
65 List &operator=(const List &other) = delete;
67 List &operator=(List &&other) noexcept {
68 std::swap(list, other.list);
69 return *this;
70 }
71
74 typedef const Ref *iterator;
76 iterator begin() const {
77 return reinterpret_cast<iterator>(&list.data[0]); // NOLINT
78 }
80 iterator end() const {
81 return reinterpret_cast<iterator>(&list.data[list.size]); // NOLINT
82 }
84 size_t size() const { return list.size; }
85 };
86};
87
88}; // namespace wasmtime
89
90#endif // WASMTIME_TYPES_IMPORT_HH
Generic type of a WebAssembly item.
Definition: extern.hh:22
An owned list of ImportType instances.
Definition: import.hh:46
size_t size() const
Returns the size of this list.
Definition: import.hh:84
List & operator=(List &&other) noexcept
Moves another list into this one.
Definition: import.hh:67
const Ref * iterator
Definition: import.hh:74
List(List &&other) noexcept
Moves another list into this one.
Definition: import.hh:58
iterator begin() const
Returns the start of iteration.
Definition: import.hh:76
iterator end() const
Returns the end of iteration.
Definition: import.hh:80
List()
Creates an empty list.
Definition: import.hh:52
Definition: import.hh:20
Ref(const wasm_importtype_t *ptr)
Creates a new reference from the raw underlying C API representation.
Definition: import.hh:30
std::string_view module()
Returns the module name associated with this import.
Definition: import.hh:33
std::string_view name()
Returns the field name associated with this import.
Definition: import.hh:39
Type information about a WebAssembly import.
Definition: import.hh:16
Representation of a compiled WebAssembly module.
Definition: module.hh:27
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.