Wasmtime
global.hh
Go to the documentation of this file.
1
5#ifndef WASMTIME_TYPES_GLOBAL_HH
6#define WASMTIME_TYPES_GLOBAL_HH
7
9
10namespace wasmtime {
11
16 friend class Global;
17
18 struct deleter {
19 void operator()(wasm_globaltype_t *p) const { wasm_globaltype_delete(p); }
20 };
21
22 std::unique_ptr<wasm_globaltype_t, deleter> ptr;
23
24public:
27 class Ref {
28 friend class GlobalType;
29 const wasm_globaltype_t *ptr;
30
31 public:
33 Ref(const wasm_globaltype_t *ptr) : ptr(ptr) {}
35 Ref(const GlobalType &ty) : Ref(ty.ptr.get()) {}
36
38 bool is_mutable() const {
39 return wasm_globaltype_mutability(ptr) == WASM_VAR;
40 }
41
44 };
45
46private:
47 Ref ref;
48 GlobalType(wasm_globaltype_t *ptr) : ptr(ptr), ref(ptr) {}
49
50public:
52 GlobalType(ValType ty, bool mut)
54 ty.ptr.release(),
55 (wasm_mutability_t)(mut ? WASM_VAR : WASM_CONST))) {}
59 GlobalType(const GlobalType &other)
60 : GlobalType(wasm_globaltype_copy(other.ptr.get())) {}
63 ptr.reset(wasm_globaltype_copy(other.ptr.get()));
64 return *this;
65 }
66 ~GlobalType() = default;
68 GlobalType(GlobalType &&other) = default;
70 GlobalType &operator=(GlobalType &&other) = default;
71
74 Ref *operator->() { return &ref; }
77 Ref *operator*() { return &ref; }
78};
79
80}; // namespace wasmtime
81
82#endif // WASMTIME_TYPES_GLOBAL_HH
Definition: global.hh:27
bool is_mutable() const
Returns whether or not this global type is mutable.
Definition: global.hh:38
Ref(const GlobalType &ty)
Creates a new reference to the specified type.
Definition: global.hh:35
Ref(const wasm_globaltype_t *ptr)
Creates a new reference from the raw underlying C API representation.
Definition: global.hh:33
ValType::Ref content() const
Returns the type of value stored within this global type.
Definition: global.hh:43
Type information about a WebAssembly global.
Definition: global.hh:15
GlobalType & operator=(GlobalType &&other)=default
Moves the underlying type information from another global into this one.
Ref * operator->()
Returns the underlying Ref, a non-owning reference pointing to this instance.
Definition: global.hh:74
GlobalType(Ref other)
Clones a reference into a uniquely owned global type.
Definition: global.hh:57
GlobalType & operator=(const GlobalType &other)
Copies other type information into this one.
Definition: global.hh:62
GlobalType(ValType ty, bool mut)
Creates a new global type from the specified value type and mutability.
Definition: global.hh:52
Ref * operator*()
Returns the underlying Ref, a non-owning reference pointing to this instance.
Definition: global.hh:77
GlobalType(const GlobalType &other)
Copies other type information into this one.
Definition: global.hh:59
GlobalType(GlobalType &&other)=default
Moves the underlying type information from another global into this one.
A WebAssembly global.
Definition: wasmtime.hh:707
Non-owning reference to a ValType, must not be used after the original ValType is deleted.
Definition: types/val.hh:91
Type information about a WebAssembly value.
Definition: types/val.hh:66
An opaque object representing the type of a global.
wasm_globaltype_t * wasm_globaltype_copy(const wasm_globaltype_t *)
Creates a new value which matches the provided one.
const wasm_valtype_t * wasm_globaltype_content(const wasm_globaltype_t *)
Returns the type of value contained in a global.
wasm_globaltype_t * wasm_globaltype_new(wasm_valtype_t *, wasm_mutability_t)
Creates a new global type.
void wasm_globaltype_delete(wasm_globaltype_t *)
Deletes a type.
wasm_mutability_t wasm_globaltype_mutability(const wasm_globaltype_t *)
Returns whether or not a global is mutable.
uint8_t wasm_mutability_t
Boolean flag for whether a global is mutable or not.
Definition: wasm.h:158