mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-12 08:31:21 +00:00
Enable compilation for specific target
By exposing the target information through `CompilerConfig`, compiler(only LLVM at the moment) could create a machine with different CPU feature flags other than current host, which makes it capable to "cross compile" to some degree. Update #959
This commit is contained in:
@ -129,6 +129,11 @@ pub struct CompilerConfig {
|
||||
pub enforce_stack_check: bool,
|
||||
pub track_state: bool,
|
||||
pub features: Features,
|
||||
|
||||
// target info used by LLVM
|
||||
pub triple: Option<String>,
|
||||
pub cpu_name: Option<String>,
|
||||
pub cpu_features: Option<String>,
|
||||
}
|
||||
|
||||
pub trait Compiler {
|
||||
|
@ -74,6 +74,13 @@ pub trait ModuleCodeGenerator<FCG: FunctionCodeGenerator<E>, RM: RunnableModule,
|
||||
/// Creates a new module code generator.
|
||||
fn new() -> Self;
|
||||
|
||||
/// Creates a new module code generator for specified target.
|
||||
fn new_with_target(
|
||||
triple: Option<String>,
|
||||
cpu_name: Option<String>,
|
||||
cpu_features: Option<String>,
|
||||
) -> Self;
|
||||
|
||||
/// Returns the backend id associated with this MCG.
|
||||
fn backend_id() -> Backend;
|
||||
|
||||
@ -206,7 +213,14 @@ impl<
|
||||
validate_with_features(wasm, &compiler_config.features)?;
|
||||
}
|
||||
|
||||
let mut mcg = MCG::new();
|
||||
let mut mcg = match MCG::backend_id() {
|
||||
Backend::LLVM => MCG::new_with_target(
|
||||
compiler_config.triple.clone(),
|
||||
compiler_config.cpu_name.clone(),
|
||||
compiler_config.cpu_features.clone(),
|
||||
),
|
||||
_ => MCG::new(),
|
||||
};
|
||||
let mut chain = (self.middleware_chain_generator)();
|
||||
let info = crate::parse::read_module(
|
||||
wasm,
|
||||
|
Reference in New Issue
Block a user