use alloc::boxed::Box;
use wasmi::{CompilationMode, Config};
#[repr(C)]
#[derive(Clone)]
pub struct wasm_config_t {
pub(crate) inner: Config,
}
wasmi_c_api_macros::declare_own!(wasm_config_t);
#[cfg_attr(not(feature = "prefix-symbols"), unsafe(no_mangle))]
#[cfg_attr(feature = "prefix-symbols", wasmi_c_api_macros::prefix_symbol)]
pub extern "C" fn wasm_config_new() -> Box<wasm_config_t> {
Box::new(wasm_config_t {
inner: Config::default(),
})
}
#[unsafe(no_mangle)]
pub extern "C" fn wasmi_config_wasm_mutable_globals_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_mutable_global(enable);
}
#[unsafe(no_mangle)]
pub extern "C" fn wasmi_config_wasm_multi_value_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_multi_value(enable);
}
#[unsafe(no_mangle)]
pub extern "C" fn wasmi_config_wasm_sign_extension_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_sign_extension(enable);
}
#[unsafe(no_mangle)]
pub extern "C" fn wasmi_config_wasm_saturating_float_to_int_set(
c: &mut wasm_config_t,
enable: bool,
) {
c.inner.wasm_saturating_float_to_int(enable);
}
#[unsafe(no_mangle)]
pub extern "C" fn wasmi_config_wasm_bulk_memory_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_bulk_memory(enable);
}
#[unsafe(no_mangle)]
pub extern "C" fn wasmi_config_wasm_reference_types_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_reference_types(enable);
}
#[unsafe(no_mangle)]
pub extern "C" fn wasmi_config_wasm_tail_call_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_tail_call(enable);
}
#[unsafe(no_mangle)]
pub extern "C" fn wasmi_config_wasm_extended_const_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_extended_const(enable);
}
#[unsafe(no_mangle)]
pub extern "C" fn wasmi_config_floats_set(config: &mut wasm_config_t, enable: bool) {
config.inner.floats(enable);
}
#[unsafe(no_mangle)]
pub extern "C" fn wasmi_config_consume_fuel_set(config: &mut wasm_config_t, enable: bool) {
config.inner.consume_fuel(enable);
}
#[repr(u8)]
#[derive(Clone)]
pub enum wasmi_compilation_mode_t {
WASMI_COMPILATION_MODE_EAGER,
WASMI_COMPILATION_MODE_LAZY_TRANSLATION,
WASMI_COMPILATION_MODE_LAZY,
}
#[unsafe(no_mangle)]
pub extern "C" fn wasmi_config_compilation_mode_set(
config: &mut wasm_config_t,
mode: wasmi_compilation_mode_t,
) {
use wasmi_compilation_mode_t::*;
config.inner.compilation_mode(match mode {
WASMI_COMPILATION_MODE_EAGER => CompilationMode::Eager,
WASMI_COMPILATION_MODE_LAZY_TRANSLATION => CompilationMode::LazyTranslation,
WASMI_COMPILATION_MODE_LAZY => CompilationMode::Lazy,
});
}
#[unsafe(no_mangle)]
pub extern "C" fn wasmi_config_ignore_custom_sections_set(
config: &mut wasm_config_t,
enable: bool,
) {
config.inner.ignore_custom_sections(enable);
}