forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathext.rs
More file actions
108 lines (95 loc) · 2.85 KB
/
ext.rs
File metadata and controls
108 lines (95 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! This file defines the extern "C" API extension, which are specific
//! to the wasmtime implementation.
use crate::{wasm_byte_vec_t, wasm_config_t, wasm_engine_t};
use std::str;
use wasmtime::{OptLevel, Strategy};
#[repr(u8)]
#[derive(Clone)]
pub enum wasmtime_strategy_t {
WASMTIME_STRATEGY_AUTO,
WASMTIME_STRATEGY_CRANELIFT,
WASMTIME_STRATEGY_LIGHTBEAM,
}
#[repr(u8)]
#[derive(Clone)]
pub enum wasmtime_opt_level_t {
WASMTIME_OPT_LEVEL_NONE,
WASMTIME_OPT_LEVEL_SPEED,
WASMTIME_OPT_LEVEL_SPEED_AND_SIZE,
}
#[no_mangle]
pub unsafe extern "C" fn wasmtime_config_debug_info_set(c: *mut wasm_config_t, enable: bool) {
(*c).config.debug_info(enable);
}
#[no_mangle]
pub unsafe extern "C" fn wasmtime_config_wasm_threads_set(c: *mut wasm_config_t, enable: bool) {
(*c).config.wasm_threads(enable);
}
#[no_mangle]
pub unsafe extern "C" fn wasmtime_config_wasm_reference_types_set(
c: *mut wasm_config_t,
enable: bool,
) {
(*c).config.wasm_reference_types(enable);
}
#[no_mangle]
pub unsafe extern "C" fn wasmtime_config_wasm_simd_set(c: *mut wasm_config_t, enable: bool) {
(*c).config.wasm_simd(enable);
}
#[no_mangle]
pub unsafe extern "C" fn wasmtime_config_wasm_bulk_memory_set(c: *mut wasm_config_t, enable: bool) {
(*c).config.wasm_bulk_memory(enable);
}
#[no_mangle]
pub unsafe extern "C" fn wasmtime_config_wasm_multi_value_set(c: *mut wasm_config_t, enable: bool) {
(*c).config.wasm_multi_value(enable);
}
#[no_mangle]
pub unsafe extern "C" fn wasmtime_config_strategy_set(
c: *mut wasm_config_t,
strategy: wasmtime_strategy_t,
) {
use wasmtime_strategy_t::*;
drop((*c).config.strategy(match strategy {
WASMTIME_STRATEGY_AUTO => Strategy::Auto,
WASMTIME_STRATEGY_CRANELIFT => Strategy::Cranelift,
WASMTIME_STRATEGY_LIGHTBEAM => Strategy::Lightbeam,
}));
}
#[no_mangle]
pub unsafe extern "C" fn wasmtime_config_cranelift_debug_verifier_set(
c: *mut wasm_config_t,
enable: bool,
) {
(*c).config.cranelift_debug_verifier(enable);
}
#[no_mangle]
pub unsafe extern "C" fn wasmtime_config_cranelift_opt_level_set(
c: *mut wasm_config_t,
opt_level: wasmtime_opt_level_t,
) {
use wasmtime_opt_level_t::*;
(*c).config.cranelift_opt_level(match opt_level {
WASMTIME_OPT_LEVEL_NONE => OptLevel::None,
WASMTIME_OPT_LEVEL_SPEED => OptLevel::Speed,
WASMTIME_OPT_LEVEL_SPEED_AND_SIZE => OptLevel::SpeedAndSize,
});
}
#[no_mangle]
pub unsafe extern "C" fn wasmtime_wat2wasm(
_engine: *mut wasm_engine_t,
wat: *const wasm_byte_vec_t,
ret: *mut wasm_byte_vec_t,
) -> bool {
let wat = match str::from_utf8((*wat).as_slice()) {
Ok(s) => s,
Err(_) => return false,
};
match wat::parse_str(wat) {
Ok(bytes) => {
(*ret).set_from_slice(&bytes);
true
}
Err(_) => false,
}
}