/src/wasmer/lib/compiler/src/engine/builder.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use super::Engine; |
2 | | use crate::CompilerConfig; |
3 | | use wasmer_types::{Features, HashAlgorithm, Target}; |
4 | | |
5 | | /// The Builder contents of `Engine` |
6 | | pub struct EngineBuilder { |
7 | | /// The compiler |
8 | | compiler_config: Option<Box<dyn CompilerConfig>>, |
9 | | /// The machine target |
10 | | target: Option<Target>, |
11 | | /// The features to compile the Wasm module with |
12 | | features: Option<Features>, |
13 | | /// The hashing algorithm |
14 | | hash_algorithm: Option<HashAlgorithm>, |
15 | | } |
16 | | |
17 | | impl EngineBuilder { |
18 | | /// Create a new builder with pre-made components |
19 | 27.9k | pub fn new<T>(compiler_config: T) -> Self |
20 | 27.9k | where |
21 | 27.9k | T: Into<Box<dyn CompilerConfig>>, |
22 | 27.9k | { |
23 | 27.9k | Self { |
24 | 27.9k | compiler_config: Some(compiler_config.into()), |
25 | 27.9k | target: None, |
26 | 27.9k | features: None, |
27 | 27.9k | hash_algorithm: None, |
28 | 27.9k | } |
29 | 27.9k | } <wasmer_compiler::engine::builder::EngineBuilder>::new::<wasmer_compiler_llvm::config::LLVM> Line | Count | Source | 19 | 214 | pub fn new<T>(compiler_config: T) -> Self | 20 | 214 | where | 21 | 214 | T: Into<Box<dyn CompilerConfig>>, | 22 | 214 | { | 23 | 214 | Self { | 24 | 214 | compiler_config: Some(compiler_config.into()), | 25 | 214 | target: None, | 26 | 214 | features: None, | 27 | 214 | hash_algorithm: None, | 28 | 214 | } | 29 | 214 | } |
Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::new::<alloc::boxed::Box<dyn wasmer_compiler::compiler::CompilerConfig>> Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::new::<wasmer_compiler_cranelift::config::Cranelift> Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::new::<alloc::boxed::Box<dyn wasmer_compiler::compiler::CompilerConfig>> <wasmer_compiler::engine::builder::EngineBuilder>::new::<wasmer_compiler_singlepass::config::Singlepass> Line | Count | Source | 19 | 12.6k | pub fn new<T>(compiler_config: T) -> Self | 20 | 12.6k | where | 21 | 12.6k | T: Into<Box<dyn CompilerConfig>>, | 22 | 12.6k | { | 23 | 12.6k | Self { | 24 | 12.6k | compiler_config: Some(compiler_config.into()), | 25 | 12.6k | target: None, | 26 | 12.6k | features: None, | 27 | 12.6k | hash_algorithm: None, | 28 | 12.6k | } | 29 | 12.6k | } |
Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::new::<alloc::boxed::Box<dyn wasmer_compiler::compiler::CompilerConfig>> Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::new::<wasmer_compiler_cranelift::config::Cranelift> Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::new::<alloc::boxed::Box<dyn wasmer_compiler::compiler::CompilerConfig>> <wasmer_compiler::engine::builder::EngineBuilder>::new::<wasmer_compiler_cranelift::config::Cranelift> Line | Count | Source | 19 | 5.00k | pub fn new<T>(compiler_config: T) -> Self | 20 | 5.00k | where | 21 | 5.00k | T: Into<Box<dyn CompilerConfig>>, | 22 | 5.00k | { | 23 | 5.00k | Self { | 24 | 5.00k | compiler_config: Some(compiler_config.into()), | 25 | 5.00k | target: None, | 26 | 5.00k | features: None, | 27 | 5.00k | hash_algorithm: None, | 28 | 5.00k | } | 29 | 5.00k | } |
<wasmer_compiler::engine::builder::EngineBuilder>::new::<wasmer_compiler_llvm::config::LLVM> Line | Count | Source | 19 | 5.00k | pub fn new<T>(compiler_config: T) -> Self | 20 | 5.00k | where | 21 | 5.00k | T: Into<Box<dyn CompilerConfig>>, | 22 | 5.00k | { | 23 | 5.00k | Self { | 24 | 5.00k | compiler_config: Some(compiler_config.into()), | 25 | 5.00k | target: None, | 26 | 5.00k | features: None, | 27 | 5.00k | hash_algorithm: None, | 28 | 5.00k | } | 29 | 5.00k | } |
<wasmer_compiler::engine::builder::EngineBuilder>::new::<wasmer_compiler_singlepass::config::Singlepass> Line | Count | Source | 19 | 5.00k | pub fn new<T>(compiler_config: T) -> Self | 20 | 5.00k | where | 21 | 5.00k | T: Into<Box<dyn CompilerConfig>>, | 22 | 5.00k | { | 23 | 5.00k | Self { | 24 | 5.00k | compiler_config: Some(compiler_config.into()), | 25 | 5.00k | target: None, | 26 | 5.00k | features: None, | 27 | 5.00k | hash_algorithm: None, | 28 | 5.00k | } | 29 | 5.00k | } |
Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::new::<wasmer_compiler_singlepass::config::Singlepass> |
30 | | |
31 | | /// Create a new headless Backend |
32 | 0 | pub fn headless() -> Self { |
33 | 0 | Self { |
34 | 0 | compiler_config: None, |
35 | 0 | target: None, |
36 | 0 | features: None, |
37 | 0 | hash_algorithm: None, |
38 | 0 | } |
39 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::headless Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::headless Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::headless Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::headless |
40 | | |
41 | | /// Set the target |
42 | 0 | pub fn set_target(mut self, target: Option<Target>) -> Self { |
43 | 0 | self.target = target; |
44 | 0 | self |
45 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::set_target Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::set_target |
46 | | |
47 | | /// Set the features |
48 | 0 | pub fn set_features(mut self, features: Option<Features>) -> Self { |
49 | 0 | self.features = features; |
50 | 0 | self |
51 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::set_features Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::set_features |
52 | | |
53 | | /// Set the hashing algorithm |
54 | 0 | pub fn set_hash_algorithm(mut self, hash_algorithm: Option<HashAlgorithm>) -> Self { |
55 | 0 | self.hash_algorithm = hash_algorithm; |
56 | 0 | self |
57 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::set_hash_algorithm Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::set_hash_algorithm |
58 | | |
59 | | /// Build the `Engine` for this configuration |
60 | | #[cfg(feature = "compiler")] |
61 | 27.9k | pub fn engine(self) -> Engine { |
62 | 27.9k | let target = self.target.unwrap_or_default(); |
63 | 27.9k | if let Some(compiler_config) = self.compiler_config { |
64 | 27.9k | let features = self |
65 | 27.9k | .features |
66 | 27.9k | .unwrap_or_else(|| compiler_config.default_features_for_target(&target)); <wasmer_compiler::engine::builder::EngineBuilder>::engine::{closure#0}Line | Count | Source | 66 | 15.2k | .unwrap_or_else(|| compiler_config.default_features_for_target(&target)); |
<wasmer_compiler::engine::builder::EngineBuilder>::engine::{closure#0}Line | Count | Source | 66 | 12.6k | .unwrap_or_else(|| compiler_config.default_features_for_target(&target)); |
|
67 | 27.9k | let mut engine = Engine::new(compiler_config, target, features); |
68 | 27.9k | |
69 | 27.9k | engine.set_hash_algorithm(self.hash_algorithm); |
70 | 27.9k | |
71 | 27.9k | engine |
72 | | } else { |
73 | 0 | Engine::headless() |
74 | | } |
75 | 27.9k | } <wasmer_compiler::engine::builder::EngineBuilder>::engine Line | Count | Source | 61 | 15.2k | pub fn engine(self) -> Engine { | 62 | 15.2k | let target = self.target.unwrap_or_default(); | 63 | 15.2k | if let Some(compiler_config) = self.compiler_config { | 64 | 15.2k | let features = self | 65 | 15.2k | .features | 66 | 15.2k | .unwrap_or_else(|| compiler_config.default_features_for_target(&target)); | 67 | 15.2k | let mut engine = Engine::new(compiler_config, target, features); | 68 | 15.2k | | 69 | 15.2k | engine.set_hash_algorithm(self.hash_algorithm); | 70 | 15.2k | | 71 | 15.2k | engine | 72 | | } else { | 73 | 0 | Engine::headless() | 74 | | } | 75 | 15.2k | } |
<wasmer_compiler::engine::builder::EngineBuilder>::engine Line | Count | Source | 61 | 12.6k | pub fn engine(self) -> Engine { | 62 | 12.6k | let target = self.target.unwrap_or_default(); | 63 | 12.6k | if let Some(compiler_config) = self.compiler_config { | 64 | 12.6k | let features = self | 65 | 12.6k | .features | 66 | 12.6k | .unwrap_or_else(|| compiler_config.default_features_for_target(&target)); | 67 | 12.6k | let mut engine = Engine::new(compiler_config, target, features); | 68 | 12.6k | | 69 | 12.6k | engine.set_hash_algorithm(self.hash_algorithm); | 70 | 12.6k | | 71 | 12.6k | engine | 72 | | } else { | 73 | 0 | Engine::headless() | 74 | | } | 75 | 12.6k | } |
|
76 | | |
77 | | /// Build the `Engine` for this configuration |
78 | | #[cfg(not(feature = "compiler"))] |
79 | | pub fn engine(self) -> Engine { |
80 | | Engine::headless() |
81 | | } |
82 | | |
83 | | /// The Wasm features |
84 | 0 | pub fn features(&self) -> Option<&Features> { |
85 | 0 | self.features.as_ref() |
86 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::features Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::features |
87 | | |
88 | | /// The target |
89 | 0 | pub fn target(&self) -> Option<&Target> { |
90 | 0 | self.target.as_ref() |
91 | 0 | } Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::target Unexecuted instantiation: <wasmer_compiler::engine::builder::EngineBuilder>::target |
92 | | } |