5#ifndef WASMTIME_COMPONENT_TYPES_COMPONENT_HH
6#define WASMTIME_COMPONENT_TYPES_COMPONENT_HH
10#ifdef WASMTIME_FEATURE_COMPONENT_MODEL
17#include <wasmtime/helpers.hh>
34 size_t import_count(
const Engine &engine)
const {
42 std::optional<ComponentExtern> import_get(
const Engine &engine,
43 std::string_view name)
const;
49 std::optional<std::pair<std::string_view, ComponentExtern>>
50 import_nth(
const Engine &engine,
size_t nth)
const;
53 size_t export_count(
const Engine &engine)
const {
61 std::optional<ComponentExtern> export_get(
const Engine &engine,
62 std::string_view name)
const;
68 std::optional<std::pair<std::string_view, ComponentExtern>>
69 export_nth(
const Engine &engine,
size_t nth)
const;
153 return *ComponentType::from_capi(&item.
of.
component);
204 std::optional<std::string_view> implements()
const {
207 if (ptr ==
nullptr) {
210 return std::string_view(ptr, len);
220 bool is_implements(std::string_view name)
const {
227 std::optional<std::string_view> external_id()
const {
230 if (ptr ==
nullptr) {
233 return std::string_view(ptr, len);
246wasmtime::component::ComponentExtern::type()
const {
252inline std::optional<wasmtime::component::ComponentExtern>
253wasmtime::component::ComponentType::import_get(
const wasmtime::Engine &engine,
254 std::string_view name)
const {
257 name.data(), name.size(), &e);
265 std::pair<std::string_view, wasmtime::component::ComponentExtern>>
266wasmtime::component::ComponentType::import_nth(
const wasmtime::Engine &engine,
269 const char *name_data;
272 &name_data, &name_size, &e);
276 return std::make_pair(std::string_view(name_data, name_size),
280inline std::optional<wasmtime::component::ComponentExtern>
281wasmtime::component::ComponentType::export_get(
const wasmtime::Engine &engine,
282 std::string_view name)
const {
285 name.data(), name.size(), &e);
293 std::pair<std::string_view, wasmtime::component::ComponentExtern>>
294wasmtime::component::ComponentType::export_nth(
const wasmtime::Engine &engine,
297 const char *name_data;
300 &name_data, &name_size, &e);
304 return std::make_pair(std::string_view(name_data, name_size),
310 assert(is_component_instance());
317 return *ModuleType::from_capi(&item.
of.
module);
322 assert(is_component_func());
328 assert(is_resource());
329 return *ResourceType::from_capi(&item.
of.
resource);
Global compilation state in Wasmtime.
Definition: engine.hh:23
Definition: types/func.hh:29
Full description of a single import or export of a component or a component instance.
Definition: component/types/component.hh:196
Represents the type of a component instance.
Definition: component/types/instance.hh:27
Represents a single item in a component's import or export list.
Definition: component/types/component.hh:81
ComponentItem(ComponentItem &&other)
Moves another item into this one.
Definition: component/types/component.hh:102
ComponentItem & operator=(ComponentItem &&other)
Moves another item into this one.
Definition: component/types/component.hh:108
bool is_core_func() const
Returns true if this is a core function.
Definition: component/types/component.hh:142
const ResourceType & resource() const
Definition: component/types/component.hh:327
const FuncType & component_func() const
Definition: component/types/component.hh:321
bool is_resource() const
Returns true if this is a resource.
Definition: component/types/component.hh:137
ComponentItem(wasmtime_component_item_t &&item)
Creates a component item from the raw C API representation.
Definition: component/types/component.hh:86
const ComponentType & component() const
Definition: component/types/component.hh:151
const ModuleType & module() const
Definition: component/types/component.hh:315
bool is_type() const
Returns true if this is a type.
Definition: component/types/component.hh:147
const ComponentInstanceType & component_instance() const
Definition: component/types/component.hh:309
ComponentItem(const ComponentItem &other)
Copies another item into this one.
Definition: component/types/component.hh:92
bool is_component_instance() const
Returns true if this is a component instance.
Definition: component/types/component.hh:124
ComponentItem & operator=(const ComponentItem &other)
Copies another item into this one.
Definition: component/types/component.hh:97
bool is_module() const
Returns true if this is a module.
Definition: component/types/component.hh:129
bool is_component() const
Returns true if this is a component.
Definition: component/types/component.hh:119
const ValType & type() const
Definition: component/types/component.hh:333
bool is_component_func() const
Returns true if this is a component function.
Definition: component/types/component.hh:132
wasmtime::FuncType::Ref core_func() const
Definition: component/types/component.hh:174
Represents the type of a WebAssembly component.
Definition: component/types/component.hh:30
Type information about a component function.
Definition: component/types/func.hh:21
Represents the type of a module.
Definition: component/types/module.hh:29
Definition: component/types/val.hh:151
Represents a component value type.
Definition: component/types/val.hh:197
static const ValType * from_capi(const wasmtime_component_valtype_t *capi)
Definition: component/types/val.hh:240
WASM_API_EXTERN wasmtime_component_type_t * wasmtime_component_type(const wasmtime_component_t *component)
Returns the type of this component.
#define WASMTIME_COMPONENT_ITEM_COMPONENT
Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a component.
Definition: component/types/component.h:88
#define WASMTIME_COMPONENT_ITEM_COMPONENT_FUNC
Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a component functio...
Definition: component/types/component.h:97
#define WASMTIME_COMPONENT_ITEM_RESOURCE
Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a resource.
Definition: component/types/component.h:100
WASM_API_EXTERN bool wasmtime_component_extern_is_implements(const wasmtime_component_extern_t *e, const char *name, size_t len)
Returns whether this import/export e has an implements attribute which matches the name provided (whi...
#define WASMTIME_COMPONENT_ITEM_COMPONENT_INSTANCE
Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a component instanc...
Definition: component/types/component.h:91
WASM_API_EXTERN const char * wasmtime_component_extern_implements(const wasmtime_component_extern_t *e, size_t *len)
Returns the implements attribute of this import/export.
WASM_API_EXTERN bool wasmtime_component_type_export_nth(const wasmtime_component_type_t *ty, const wasm_engine_t *engine, size_t nth, const char **name_ret, size_t *name_len_ret, struct wasmtime_component_extern_t **ret)
Retrieves the nth export.
WASM_API_EXTERN void wasmtime_component_item_delete(wasmtime_component_item_t *ptr)
Deallocates a component item.
#define WASMTIME_COMPONENT_ITEM_CORE_FUNC
Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a core function.
Definition: component/types/component.h:103
WASM_API_EXTERN bool wasmtime_component_type_import_get(const wasmtime_component_type_t *ty, const wasm_engine_t *engine, const char *name, size_t name_len, struct wasmtime_component_extern_t **ret)
Retrieves the import with the specified name.
WASM_API_EXTERN bool wasmtime_component_type_export_get(const wasmtime_component_type_t *ty, const wasm_engine_t *engine, const char *name, size_t name_len, struct wasmtime_component_extern_t **ret)
Retrieves the export with the specified name.
WASM_API_EXTERN void wasmtime_component_extern_type(const wasmtime_component_extern_t *e, wasmtime_component_item_t *ret)
Returns the type of the item that this import/export refers to.
struct wasmtime_component_extern_t wasmtime_component_extern_t
Full description of a single component or component instance export or import.
Definition: component/types/component.h:166
#define WASMTIME_COMPONENT_ITEM_MODULE
Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a module.
Definition: component/types/component.h:94
WASM_API_EXTERN bool wasmtime_component_type_import_nth(const wasmtime_component_type_t *ty, const wasm_engine_t *engine, size_t nth, const char **name_ret, size_t *name_len_ret, struct wasmtime_component_extern_t **ret)
Retrieves the nth import.
WASM_API_EXTERN size_t wasmtime_component_type_import_count(const wasmtime_component_type_t *ty, const wasm_engine_t *engine)
Returns the number of imports of a component type.
WASM_API_EXTERN size_t wasmtime_component_type_export_count(const wasmtime_component_type_t *ty, const wasm_engine_t *engine)
Returns the number of exports of a component type.
WASM_API_EXTERN void wasmtime_component_item_clone(const wasmtime_component_item_t *item, wasmtime_component_item_t *out)
Clones a component item.
WASM_API_EXTERN const char * wasmtime_component_extern_external_id(const wasmtime_component_extern_t *e, size_t *len)
Returns the external-id attribute of this import/export.
#define WASMTIME_COMPONENT_ITEM_TYPE
Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a type.
Definition: component/types/component.h:106
#define WASMTIME_COMPONENT_VALTYPE_BOOL
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a bool WIT ty...
Definition: component/types/val.h:379
Build-time defines for how the C API was built.
Represents a single item in a component's import or export list.
Definition: component/types/component.h:137
wasmtime_component_item_union_t of
The actual item.
Definition: component/types/component.h:141
wasmtime_component_item_kind_t kind
The type discriminant for the of union.
Definition: component/types/component.h:139
wasmtime_component_valtype_kind_t kind
The type discriminant for the of union.
Definition: component/types/val.h:508
wasmtime_component_valtype_t type
Definition: component/types/component.h:133
wasmtime_component_type_t * component
Definition: component/types/component.h:115
wasmtime_component_func_type_t * component_func
Definition: component/types/component.h:124
wasmtime_module_type_t * module
Definition: component/types/component.h:121
wasmtime_component_resource_type_t * resource
Definition: component/types/component.h:127
wasm_functype_t * core_func
Definition: component/types/component.h:130
wasmtime_component_instance_type_t * component_instance
Definition: component/types/component.h:118