#ifndef WASMTIME_TYPES_EXTERN_HH
#define WASMTIME_TYPES_EXTERN_HH
#include <variant>
#include <wasm.h>
#include <wasmtime/types/export.hh>
#include <wasmtime/types/func.hh>
#include <wasmtime/types/global.hh>
#include <wasmtime/types/import.hh>
#include <wasmtime/types/memory.hh>
#include <wasmtime/types/table.hh>
#include <wasmtime/types/tag.hh>
namespace wasmtime {
class ExternType {
friend class ExportType;
friend class ImportType;
public:
typedef std::variant<FuncType::Ref, GlobalType::Ref, TableType::Ref,
MemoryType::Ref, TagType::Ref>
Ref;
static Ref from_import(ImportType::Ref ty) {
return ref_from_c(ty.raw_type());
}
static Ref from_export(ExportType::Ref ty) {
return ref_from_c(ty.raw_type());
}
private:
static Ref ref_from_c(const wasm_externtype_t *ptr) {
switch (wasm_externtype_kind(ptr)) {
case WASM_EXTERN_FUNC:
return wasm_externtype_as_functype_const(ptr);
case WASM_EXTERN_GLOBAL:
return wasm_externtype_as_globaltype_const(ptr);
case WASM_EXTERN_TABLE:
return wasm_externtype_as_tabletype_const(ptr);
case WASM_EXTERN_MEMORY:
return wasm_externtype_as_memorytype_const(ptr);
case WASM_EXTERN_TAG:
return wasm_externtype_as_tagtype_const(ptr);
}
std::abort();
}
};
};
#endif