MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / RefVariant

Class RefVariant

include/common/types.h:368–429  ·  view source on GitHub ↗

RefType variant definition.

Source from the content-addressed store, hash-verified

366
367/// RefType variant definition.
368struct RefVariant {
369 // Constructors.
370 RefVariant() noexcept { setData<void>(TypeCode::ExternRef); }
371 RefVariant(const ValType &VT) noexcept { setData<void>(VT); }
372 RefVariant(const ValType &VT, const RefVariant &Val) noexcept {
373 setData(VT, Val.getPtr<void>());
374 }
375
376 template <typename T> RefVariant(const T *P) noexcept {
377 setData(TypeCode::ExternRef, reinterpret_cast<const void *>(P));
378 }
379 template <typename T> RefVariant(const ValType &VT, const T *P) noexcept {
380 setData(VT, reinterpret_cast<const void *>(P));
381 }
382 RefVariant(const Runtime::Instance::FunctionInstance *P) noexcept {
383 setData(TypeCode::FuncRef, reinterpret_cast<const void *>(P));
384 }
385 RefVariant(const Runtime::Instance::StructInstance *P) noexcept {
386 setData(TypeCode::StructRef, reinterpret_cast<const void *>(P));
387 }
388 RefVariant(const Runtime::Instance::ArrayInstance *P) noexcept {
389 setData(TypeCode::ArrayRef, reinterpret_cast<const void *>(P));
390 }
391
392 // Getter for type.
393 const ValType &getType() const noexcept {
394 return reinterpret_cast<const ValType &>(toArray()[0]);
395 }
396 ValType &getType() noexcept {
397 return reinterpret_cast<ValType &>(toArray()[0]);
398 }
399
400 // Getter for pointer.
401 template <typename T> T *getPtr() const noexcept {
402 return reinterpret_cast<T *>(toArray()[1]);
403 }
404
405 // Check whether it is null.
406 bool isNull() const { return getPtr<void>() == nullptr; }
407
408 // Getter for the raw data.
409 uint64x2_t getRawData() const noexcept { return Data; }
410
411private:
412 // Helper function for converting data to array.
413 const std::array<uint64_t, 2> &toArray() const noexcept {
414 return reinterpret_cast<const std::array<uint64_t, 2> &>(Data);
415 }
416 std::array<uint64_t, 2> &toArray() noexcept {
417 return reinterpret_cast<std::array<uint64_t, 2> &>(Data);
418 }
419
420 // Helper function to set the content.
421 template <typename T>
422 void setData(const ValType &VT, const T *Ptr = nullptr) noexcept {
423 getType() = VT;
424 toArray()[1] = reinterpret_cast<uintptr_t>(Ptr);
425 }

Callers 15

throwExceptionMethod · 0.85
runRefNullOpMethod · 0.85
runRefFuncOpMethod · 0.85
runRefConvOpMethod · 0.85
runRefI31OpMethod · 0.85
structNewMethod · 0.85
arrayNewMethod · 0.85
arrayNewDataMethod · 0.85
arrayNewElemMethod · 0.85
proxyRefFuncMethod · 0.85

Calls

no outgoing calls

Tested by 3

TESTFunction · 0.68
parseValueListFunction · 0.68
SpecTestModuleMethod · 0.68