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;
155 return *ComponentType::from_capi(&item.
of.
component);
206 std::optional<std::string_view> implements()
const {
209 if (ptr ==
nullptr) {
212 return std::string_view(ptr, len);
222 bool is_implements(std::string_view name)
const {
229 std::optional<std::string_view> external_id()
const {
232 if (ptr ==
nullptr) {
235 return std::string_view(ptr, len);
248wasmtime::component::ComponentExtern::type()
const {
254inline std::optional<wasmtime::component::ComponentExtern>
255wasmtime::component::ComponentType::import_get(
const wasmtime::Engine &engine,
256 std::string_view name)
const {
259 name.data(), name.size(), &e);
267 std::pair<std::string_view, wasmtime::component::ComponentExtern>>
268wasmtime::component::ComponentType::import_nth(
const wasmtime::Engine &engine,
271 const char *name_data;
274 &name_data, &name_size, &e);
278 return std::make_pair(std::string_view(name_data, name_size),
282inline std::optional<wasmtime::component::ComponentExtern>
283wasmtime::component::ComponentType::export_get(
const wasmtime::Engine &engine,
284 std::string_view name)
const {
287 name.data(), name.size(), &e);
295 std::pair<std::string_view, wasmtime::component::ComponentExtern>>
296wasmtime::component::ComponentType::export_nth(
const wasmtime::Engine &engine,
299 const char *name_data;
302 &name_data, &name_size, &e);
306 return std::make_pair(std::string_view(name_data, name_size),
312 assert(is_component_instance());
319 return *ModuleType::from_capi(&item.
of.
module);
324 assert(is_component_func());
330 assert(is_resource());
331 return *ResourceType::from_capi(&item.
of.
resource);
Global compilation state in Wasmtime.
Definition: engine.hh:22
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:198
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:104
ComponentItem & operator=(ComponentItem &&other)
Moves another item into this one.
Definition: component/types/component.hh:110
bool is_core_func() const
Returns true if this is a core function.
Definition: component/types/component.hh:144
const ResourceType & resource() const
Definition: component/types/component.hh:329
const FuncType & component_func() const
Definition: component/types/component.hh:323
bool is_resource() const
Returns true if this is a resource.
Definition: component/types/component.hh:139
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:153
const ModuleType & module() const
Definition: component/types/component.hh:317
bool is_type() const
Returns true if this is a type.
Definition: component/types/component.hh:149
const ComponentInstanceType & component_instance() const
Definition: component/types/component.hh:311
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:126
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:131
bool is_component() const
Returns true if this is a component.
Definition: component/types/component.hh:121
const ValType & type() const
Definition: component/types/component.hh:335
bool is_component_func() const
Returns true if this is a component function.
Definition: component/types/component.hh:134
wasmtime::FuncType::Ref core_func() const
Definition: component/types/component.hh:176
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:244
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