Wasmtime
types/extern.hh
Go to the documentation of this file.
1
5#ifndef WASMTIME_TYPES_EXTERN_HH
6#define WASMTIME_TYPES_EXTERN_HH
7
8#include <variant>
9#include <wasm.h>
16#include <wasmtime/types/tag.hh>
17
18namespace wasmtime {
19
24 friend class ExportType;
25 friend class ImportType;
26
27public:
34 typedef std::variant<FuncType::Ref, GlobalType::Ref, TableType::Ref,
37
39 static Ref from_import(ImportType::Ref ty) {
40 // TODO: this would ideally be some sort of implicit constructor, unsure how
41 // to do that though...
42 return ref_from_c(ty.raw_type());
43 }
44
46 static Ref from_export(ExportType::Ref ty) {
47 // TODO: this would ideally be some sort of implicit constructor, unsure how
48 // to do that though...
49 return ref_from_c(ty.raw_type());
50 }
51
52private:
53 static Ref ref_from_c(const wasm_externtype_t *ptr) {
54 switch (wasm_externtype_kind(ptr)) {
55 case WASM_EXTERN_FUNC:
57 case WASM_EXTERN_GLOBAL:
59 case WASM_EXTERN_TABLE:
61 case WASM_EXTERN_MEMORY:
63 case WASM_EXTERN_TAG:
65 }
66 std::abort();
67 }
68};
69
70}; // namespace wasmtime
71
72#endif // WASMTIME_TYPES_EXTERN_HH
Type information about a WebAssembly export.
Definition: export.hh:17
Generic type of a WebAssembly item.
Definition: types/extern.hh:23
static Ref from_import(ImportType::Ref ty)
Extract the type of the item imported by the provided type.
Definition: types/extern.hh:39
std::variant< FuncType::Ref, GlobalType::Ref, TableType::Ref, MemoryType::Ref, TagType::Ref > Ref
Non-owning reference to an item's type.
Definition: types/extern.hh:36
static Ref from_export(ExportType::Ref ty)
Extract the type of the item exported by the provided type.
Definition: types/extern.hh:46
Definition: types/func.hh:29
Definition: types/global.hh:27
Type information about a WebAssembly import.
Definition: import.hh:17
Non-owning reference to a MemoryType, must not be used after the original owner has been deleted.
Definition: types/memory.hh:34
Definition: types/table.hh:28
Definition: tag.hh:30
An opaque object representing the type of a external value. Can be seen as a superclass of wasm_funct...
const wasm_functype_t * wasm_externtype_as_functype_const(const wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_functype_t.
const wasm_globaltype_t * wasm_externtype_as_globaltype_const(const wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_globaltype_t.
const wasm_tabletype_t * wasm_externtype_as_tabletype_const(const wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_tabletype_t.
const wasm_tagtype_t * wasm_externtype_as_tagtype_const(const wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_tagtype_t.
wasm_externkind_t wasm_externtype_kind(const wasm_externtype_t *)
Returns the kind of external item this type represents.
const wasm_memorytype_t * wasm_externtype_as_memorytype_const(const wasm_externtype_t *)
Attempts to convert a wasm_externtype_t to a wasm_memorytype_t.