Add the ability to pass backend specific options through CompilerConfig.

Use this to replace wasmer_llvm_backend::GLOBAL_OPTIONS.
This commit is contained in:
Nick Lewycky
2019-12-04 10:38:28 -08:00
parent af7a368320
commit 8d3cf874cd
5 changed files with 95 additions and 46 deletions

View File

@ -200,6 +200,19 @@ pub struct Features {
pub threads: bool,
}
/// Use this to point to a compiler config struct provided by the backend.
/// The backend struct must support runtime reflection with `Any`, which is any
/// struct that does not contain a non-`'static` reference.
#[derive(Debug)]
pub struct BackendCompilerConfig(pub Box<dyn Any + 'static>);
impl BackendCompilerConfig {
/// Obtain the backend-specific compiler config struct.
pub fn get_specific<T: 'static>(&self) -> Option<&T> {
self.0.downcast_ref::<T>()
}
}
/// Configuration data for the compiler
#[derive(Debug, Default)]
pub struct CompilerConfig {
@ -210,10 +223,12 @@ pub struct CompilerConfig {
pub track_state: bool,
pub features: Features,
// target info used by LLVM
// Target info. Presently only supported by LLVM.
pub triple: Option<String>,
pub cpu_name: Option<String>,
pub cpu_features: Option<String>,
pub backend_specific_config: Option<BackendCompilerConfig>,
}
pub trait Compiler {