wasmi_c_api/config.rs
1use alloc::boxed::Box;
2use wasmi::{CompilationMode, Config};
3
4/// The Wasm configuration.
5///
6/// Wraps [`wasmi::Config`]
7#[repr(C)]
8#[derive(Clone)]
9pub struct wasm_config_t {
10 pub(crate) inner: Config,
11}
12
13wasmi_c_api_macros::declare_own!(wasm_config_t);
14
15/// Creates a new default initialized [`wasm_config_t`].
16///
17/// The returned [`wasm_config_t`] must be freed using [`wasm_config_delete`]
18/// or consumed by [`wasm_engine_new_with_config`].
19///
20/// Wraps [`wasmi::Config::default`].
21///
22/// [`wasm_engine_new_with_config`]: crate::wasm_engine_new_with_config
23#[cfg_attr(not(feature = "prefix-symbols"), no_mangle)]
24#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
25pub extern "C" fn wasm_config_new() -> Box<wasm_config_t> {
26 Box::new(wasm_config_t {
27 inner: Config::default(),
28 })
29}
30
31/// Enables or disables support for the Wasm [`mutable-global`] proposal.
32///
33/// Wraps [`wasmi::Config::wasm_multi_value`]
34///
35/// [`mutable-global`]: <https://github.com/WebAssembly/mutable-global>
36#[no_mangle]
37pub extern "C" fn wasmi_config_wasm_mutable_globals_set(c: &mut wasm_config_t, enable: bool) {
38 c.inner.wasm_mutable_global(enable);
39}
40
41/// Enables or disables support for the Wasm [`multi-value`] proposal.
42///
43/// Wraps [`wasmi::Config::wasm_multi_value`]
44///
45/// [`multi-value`]: <https://github.com/WebAssembly/multi-value>
46#[no_mangle]
47pub extern "C" fn wasmi_config_wasm_multi_value_set(c: &mut wasm_config_t, enable: bool) {
48 c.inner.wasm_multi_value(enable);
49}
50
51/// Enables or disables support for the Wasm [`sign-extension-ops`] proposal.
52///
53/// Wraps [`wasmi::Config::wasm_sign_extension`]
54///
55/// [`sign-extension-ops`]: <https://github.com/WebAssembly/sign-extension-ops>
56#[no_mangle]
57pub extern "C" fn wasmi_config_wasm_sign_extension_set(c: &mut wasm_config_t, enable: bool) {
58 c.inner.wasm_sign_extension(enable);
59}
60
61/// Enables or disables support for the Wasm [`nontrapping-float-to-int-conversions`] proposal.
62///
63/// Wraps [`wasmi::Config::wasm_saturating_float_to_int`]
64///
65/// [`nontrapping-float-to-int-conversions`]: <https://github.com/WebAssembly/nontrapping-float-to-int-conversions>
66#[no_mangle]
67pub extern "C" fn wasmi_config_wasm_saturating_float_to_int_set(
68 c: &mut wasm_config_t,
69 enable: bool,
70) {
71 c.inner.wasm_saturating_float_to_int(enable);
72}
73
74/// Enables or disables support for the Wasm [`bulk-memory-operations`] proposal.
75///
76/// Wraps [`wasmi::Config::wasm_bulk_memory`]
77///
78/// [`bulk-memory-operations`]: <https://github.com/WebAssembly/bulk-memory-operations>
79#[no_mangle]
80pub extern "C" fn wasmi_config_wasm_bulk_memory_set(c: &mut wasm_config_t, enable: bool) {
81 c.inner.wasm_bulk_memory(enable);
82}
83
84/// Enables or disables support for the Wasm [`reference-types`] proposal.
85///
86/// Wraps [`wasmi::Config::wasm_reference_types`]
87///
88/// [`reference-types`]: <https://github.com/WebAssembly/reference-types>
89#[no_mangle]
90pub extern "C" fn wasmi_config_wasm_reference_types_set(c: &mut wasm_config_t, enable: bool) {
91 c.inner.wasm_reference_types(enable);
92}
93
94/// Enables or disables support for the Wasm [`tail-call`] proposal.
95///
96/// Wraps [`wasmi::Config::wasm_tail_call`]
97///
98/// [`tail-call`]: <https://github.com/WebAssembly/tail-call>
99#[no_mangle]
100pub extern "C" fn wasmi_config_wasm_tail_call_set(c: &mut wasm_config_t, enable: bool) {
101 c.inner.wasm_tail_call(enable);
102}
103
104/// Enables or disables support for the Wasm [`extended-const`] proposal.
105///
106/// Wraps [`wasmi::Config::wasm_extended_const`]
107///
108/// [`extended-const`]: <https://github.com/WebAssembly/extended-const>
109#[no_mangle]
110pub extern "C" fn wasmi_config_wasm_extended_const_set(c: &mut wasm_config_t, enable: bool) {
111 c.inner.wasm_extended_const(enable);
112}
113
114/// Enables or disables support for floating point numbers for the config.
115///
116/// Wraps [`wasmi::Config::floats`]
117#[no_mangle]
118pub extern "C" fn wasmi_config_floats_set(config: &mut wasm_config_t, enable: bool) {
119 config.inner.floats(enable);
120}
121
122/// Enables or disables fuel consumption for the config.
123///
124/// Wraps [`wasmi::Config::consume_fuel`]
125#[no_mangle]
126pub extern "C" fn wasmi_config_consume_fuel_set(config: &mut wasm_config_t, enable: bool) {
127 config.inner.consume_fuel(enable);
128}
129
130/// Compilation modes supported by the Wasmi execution engine.
131///
132/// Wraps [`wasmi::CompilationMode`]
133#[repr(u8)]
134#[derive(Clone)]
135pub enum wasmi_compilation_mode_t {
136 WASMI_COMPILATION_MODE_EAGER,
137 WASMI_COMPILATION_MODE_LAZY_TRANSLATION,
138 WASMI_COMPILATION_MODE_LAZY,
139}
140
141/// Sets the compilation mode for the config.
142///
143/// Wraps [`wasmi::Config::compilation_mode`]
144#[no_mangle]
145pub extern "C" fn wasmi_config_compilation_mode_set(
146 config: &mut wasm_config_t,
147 mode: wasmi_compilation_mode_t,
148) {
149 use wasmi_compilation_mode_t::*;
150 config.inner.compilation_mode(match mode {
151 WASMI_COMPILATION_MODE_EAGER => CompilationMode::Eager,
152 WASMI_COMPILATION_MODE_LAZY_TRANSLATION => CompilationMode::LazyTranslation,
153 WASMI_COMPILATION_MODE_LAZY => CompilationMode::Lazy,
154 });
155}
156
157/// Enables or disables processing of Wasm custom sections.
158///
159/// Wraps [`wasmi::Config::ignore_custom_sections`]
160#[no_mangle]
161pub extern "C" fn wasmi_config_ignore_custom_sections_set(
162 config: &mut wasm_config_t,
163 enable: bool,
164) {
165 config.inner.ignore_custom_sections(enable);
166}