/rust/registry/src/index.crates.io-6f17d22bba15001f/wasmi-0.20.0/src/engine/config.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use super::stack::StackLimits; |
2 | | use wasmparser::WasmFeatures; |
3 | | |
4 | | /// Configuration for an [`Engine`]. |
5 | | /// |
6 | | /// [`Engine`]: [`crate::Engine`] |
7 | 0 | #[derive(Debug, Copy, Clone)] |
8 | | pub struct Config { |
9 | | /// The limits set on the value stack and call stack. |
10 | | stack_limits: StackLimits, |
11 | | /// Is `true` if the `mutable-global` Wasm proposal is enabled. |
12 | | mutable_global: bool, |
13 | | /// Is `true` if the `sign-extension` Wasm proposal is enabled. |
14 | | sign_extension: bool, |
15 | | /// Is `true` if the `saturating-float-to-int` Wasm proposal is enabled. |
16 | | saturating_float_to_int: bool, |
17 | | /// Is `true` if the [`multi-value`] Wasm proposal is enabled. |
18 | | multi_value: bool, |
19 | | } |
20 | | |
21 | | impl Default for Config { |
22 | 4.47k | fn default() -> Self { |
23 | 4.47k | Self { |
24 | 4.47k | stack_limits: StackLimits::default(), |
25 | 4.47k | mutable_global: true, |
26 | 4.47k | sign_extension: true, |
27 | 4.47k | saturating_float_to_int: true, |
28 | 4.47k | multi_value: true, |
29 | 4.47k | } |
30 | 4.47k | } |
31 | | } |
32 | | |
33 | | impl Config { |
34 | | /// Sets the [`StackLimits`] for the [`Config`]. |
35 | 0 | pub fn set_stack_limits(&mut self, stack_limits: StackLimits) -> &mut Self { |
36 | 0 | self.stack_limits = stack_limits; |
37 | 0 | self |
38 | 0 | } |
39 | | |
40 | | /// Returns the [`StackLimits`] of the [`Config`]. |
41 | 4.47k | pub(super) fn stack_limits(&self) -> StackLimits { |
42 | 4.47k | self.stack_limits |
43 | 4.47k | } |
44 | | |
45 | | /// Enable or disable the [`mutable-global`] Wasm proposal for the [`Config`]. |
46 | | /// |
47 | | /// # Note |
48 | | /// |
49 | | /// Enabled by default. |
50 | | /// |
51 | | /// [`mutable-global`]: https://github.com/WebAssembly/mutable-global |
52 | 0 | pub fn wasm_mutable_global(&mut self, enable: bool) -> &mut Self { |
53 | 0 | self.mutable_global = enable; |
54 | 0 | self |
55 | 0 | } |
56 | | |
57 | | /// Enable or disable the [`sign-extension`] Wasm proposal for the [`Config`]. |
58 | | /// |
59 | | /// # Note |
60 | | /// |
61 | | /// Enabled by default. |
62 | | /// |
63 | | /// [`sign-extension`]: https://github.com/WebAssembly/sign-extension-ops |
64 | 0 | pub fn wasm_sign_extension(&mut self, enable: bool) -> &mut Self { |
65 | 0 | self.sign_extension = enable; |
66 | 0 | self |
67 | 0 | } |
68 | | |
69 | | /// Enable or disable the [`saturating-float-to-int`] Wasm proposal for the [`Config`]. |
70 | | /// |
71 | | /// # Note |
72 | | /// |
73 | | /// Enabled by default. |
74 | | /// |
75 | | /// [`saturating-float-to-int`]: |
76 | | /// https://github.com/WebAssembly/nontrapping-float-to-int-conversions |
77 | 0 | pub fn wasm_saturating_float_to_int(&mut self, enable: bool) -> &mut Self { |
78 | 0 | self.saturating_float_to_int = enable; |
79 | 0 | self |
80 | 0 | } |
81 | | |
82 | | /// Enable or disable the [`multi-value`] Wasm proposal for the [`Config`]. |
83 | | /// |
84 | | /// # Note |
85 | | /// |
86 | | /// Enabled by default. |
87 | | /// |
88 | | /// [`multi-value`]: https://github.com/WebAssembly/multi-value |
89 | 0 | pub fn wasm_multi_value(&mut self, enable: bool) -> &mut Self { |
90 | 0 | self.multi_value = enable; |
91 | 0 | self |
92 | 0 | } |
93 | | |
94 | | /// Returns the [`WasmFeatures`] represented by the [`Config`]. |
95 | 4.33k | pub fn wasm_features(&self) -> WasmFeatures { |
96 | 4.33k | WasmFeatures { |
97 | 4.33k | multi_value: self.multi_value, |
98 | 4.33k | mutable_global: self.mutable_global, |
99 | 4.33k | saturating_float_to_int: self.saturating_float_to_int, |
100 | 4.33k | sign_extension: self.sign_extension, |
101 | 4.33k | reference_types: false, |
102 | 4.33k | bulk_memory: false, |
103 | 4.33k | component_model: false, |
104 | 4.33k | simd: false, |
105 | 4.33k | relaxed_simd: false, |
106 | 4.33k | threads: false, |
107 | 4.33k | tail_call: false, |
108 | 4.33k | deterministic_only: true, |
109 | 4.33k | multi_memory: false, |
110 | 4.33k | exceptions: false, |
111 | 4.33k | memory64: false, |
112 | 4.33k | extended_const: false, |
113 | 4.33k | } |
114 | 4.33k | } |
115 | | } |