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>
33 size_t import_count(
const Engine &engine)
const {
38 std::optional<ComponentItem> import_get(
const Engine &engine,
39 std::string_view name)
const;
42 std::optional<std::pair<std::string_view, ComponentItem>>
43 import_nth(
const Engine &engine,
size_t nth)
const;
46 size_t export_count(
const Engine &engine)
const {
51 std::optional<ComponentItem> export_get(
const Engine &engine,
52 std::string_view name)
const;
55 std::optional<std::pair<std::string_view, ComponentItem>>
56 export_nth(
const Engine &engine,
size_t nth)
const;
142 return *ComponentType::from_capi(&item.
of.
component);
181inline std::optional<wasmtime::component::ComponentItem>
182wasmtime::component::ComponentType::import_get(
const wasmtime::Engine &engine,
183 std::string_view name)
const {
186 capi(), engine.capi(), name.data(), name.size(), &item);
194 std::pair<std::string_view, wasmtime::component::ComponentItem>>
195wasmtime::component::ComponentType::import_nth(
const wasmtime::Engine &engine,
198 const char *name_data;
201 capi(), engine.capi(), nth, &name_data, &name_size, &item);
205 return std::make_pair(std::string_view(name_data, name_size),
209inline std::optional<wasmtime::component::ComponentItem>
210wasmtime::component::ComponentType::export_get(
const wasmtime::Engine &engine,
211 std::string_view name)
const {
214 capi(), engine.capi(), name.data(), name.size(), &item);
222 std::pair<std::string_view, wasmtime::component::ComponentItem>>
223wasmtime::component::ComponentType::export_nth(
const wasmtime::Engine &engine,
226 const char *name_data;
229 capi(), engine.capi(), nth, &name_data, &name_size, &item);
233 return std::make_pair(std::string_view(name_data, name_size),
239 assert(is_component_instance());
246 return *ModuleType::from_capi(&item.
of.
module);
251 assert(is_component_func());
257 assert(is_resource());
258 return *ResourceType::from_capi(&item.
of.
resource);
Global compilation state in Wasmtime.
Definition: engine.hh:22
Definition: types/func.hh:28
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:68
ComponentItem(ComponentItem &&other)
Moves another item into this one.
Definition: component/types/component.hh:91
ComponentItem & operator=(ComponentItem &&other)
Moves another item into this one.
Definition: component/types/component.hh:97
bool is_core_func() const
Returns true if this is a core function.
Definition: component/types/component.hh:131
const ResourceType & resource() const
Definition: component/types/component.hh:256
const FuncType & component_func() const
Definition: component/types/component.hh:250
bool is_resource() const
Returns true if this is a resource.
Definition: component/types/component.hh:126
ComponentItem(wasmtime_component_item_t &&item)
Creates a component item from the raw C API representation.
Definition: component/types/component.hh:73
const ComponentType & component() const
Definition: component/types/component.hh:140
const ModuleType & module() const
Definition: component/types/component.hh:244
bool is_type() const
Returns true if this is a type.
Definition: component/types/component.hh:136
const ComponentInstanceType & component_instance() const
Definition: component/types/component.hh:238
ComponentItem(const ComponentItem &other)
Copies another item into this one.
Definition: component/types/component.hh:79
bool is_component_instance() const
Returns true if this is a component instance.
Definition: component/types/component.hh:113
ComponentItem & operator=(const ComponentItem &other)
Copies another item into this one.
Definition: component/types/component.hh:84
bool is_module() const
Returns true if this is a module.
Definition: component/types/component.hh:118
bool is_component() const
Returns true if this is a component.
Definition: component/types/component.hh:108
const ValType & type() const
Definition: component/types/component.hh:262
bool is_component_func() const
Returns true if this is a component function.
Definition: component/types/component.hh:121
wasmtime::FuncType::Ref core_func() const
Definition: component/types/component.hh:163
Represents the type of a WebAssembly component.
Definition: component/types/component.hh:29
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:184
static const ValType * from_capi(const wasmtime_component_valtype_t *capi)
Definition: component/types/val.hh:231
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
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_item_t *ret)
Retrieves the export with the specified name.
#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_type_import_get(const wasmtime_component_type_t *ty, const wasm_engine_t *engine, const char *name, size_t name_len, struct wasmtime_component_item_t *ret)
Retrieves the import with the specified name.
#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 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_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_item_t *type_ret)
Retrieves the nth import.
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_item_t *type_ret)
Retrieves the nth export.
#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 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.
#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:342
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:465
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