linera_wasmer_compiler_singlepass/
config.rs

1// Allow unused imports while developing
2#![allow(unused_imports, dead_code)]
3
4use crate::compiler::SinglepassCompiler;
5use std::sync::Arc;
6use wasmer_compiler::{Compiler, CompilerConfig, Engine, EngineBuilder, ModuleMiddleware};
7use wasmer_types::{CpuFeature, Features, Target};
8
9#[derive(Debug, Clone)]
10pub struct Singlepass {
11    pub(crate) enable_nan_canonicalization: bool,
12    /// The middleware chain.
13    pub(crate) middlewares: Vec<Arc<dyn ModuleMiddleware>>,
14}
15
16impl Singlepass {
17    /// Creates a new configuration object with the default configuration
18    /// specified.
19    pub fn new() -> Self {
20        Self {
21            enable_nan_canonicalization: true,
22            middlewares: vec![],
23        }
24    }
25
26    pub fn canonicalize_nans(&mut self, enable: bool) -> &mut Self {
27        self.enable_nan_canonicalization = enable;
28        self
29    }
30}
31
32impl CompilerConfig for Singlepass {
33    fn enable_pic(&mut self) {
34        // Do nothing, since singlepass already emits
35        // PIC code.
36    }
37
38    /// Transform it into the compiler
39    fn compiler(self: Box<Self>) -> Box<dyn Compiler> {
40        Box::new(SinglepassCompiler::new(*self))
41    }
42
43    /// Gets the default features for this compiler in the given target
44    fn default_features_for_target(&self, _target: &Target) -> Features {
45        let mut features = Features::default();
46        features.multi_value(false);
47        features
48    }
49
50    /// Pushes a middleware onto the back of the middleware chain.
51    fn push_middleware(&mut self, middleware: Arc<dyn ModuleMiddleware>) {
52        self.middlewares.push(middleware);
53    }
54}
55
56impl Default for Singlepass {
57    fn default() -> Singlepass {
58        Self::new()
59    }
60}
61
62impl From<Singlepass> for Engine {
63    fn from(config: Singlepass) -> Self {
64        EngineBuilder::new(config).engine()
65    }
66}