mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-16 17:18:57 +00:00
Remove target from CompilerConfig
This commit is contained in:
@@ -33,25 +33,17 @@ use wasmer_compiler::{
|
||||
/// A compiler that compiles a WebAssembly module with Cranelift, translating the Wasm to Cranelift IR,
|
||||
/// optimizing it and then translating to assembly.
|
||||
pub struct CraneliftCompiler {
|
||||
isa: Box<dyn isa::TargetIsa>,
|
||||
config: CraneliftConfig,
|
||||
}
|
||||
|
||||
impl CraneliftCompiler {
|
||||
/// Creates a new Cranelift compiler
|
||||
pub fn new(config: &CraneliftConfig) -> Self {
|
||||
let isa = config.isa();
|
||||
Self {
|
||||
isa,
|
||||
config: config.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieves the starget ISA
|
||||
fn isa(&self) -> &dyn isa::TargetIsa {
|
||||
&*self.isa
|
||||
}
|
||||
|
||||
/// Gets the WebAssembly features for this Compiler
|
||||
pub fn config(&self) -> &CraneliftConfig {
|
||||
&self.config
|
||||
@@ -59,20 +51,16 @@ impl CraneliftCompiler {
|
||||
}
|
||||
|
||||
impl Compiler for CraneliftCompiler {
|
||||
/// Gets the target associated to the Cranelift ISA.
|
||||
fn target(&self) -> &Target {
|
||||
self.config.target()
|
||||
}
|
||||
|
||||
/// Compile the module using Cranelift, producing a compilation result with
|
||||
/// associated relocations.
|
||||
fn compile_module(
|
||||
&self,
|
||||
target: &Target,
|
||||
compile_info: &CompileModuleInfo,
|
||||
module_translation: &ModuleTranslationState,
|
||||
function_body_inputs: PrimaryMap<LocalFunctionIndex, FunctionBodyData<'_>>,
|
||||
) -> Result<Compilation, CompileError> {
|
||||
let isa = self.isa();
|
||||
let isa = self.config().isa(target);
|
||||
let frontend_config = isa.frontend_config();
|
||||
let memory_plans = &compile_info.memory_plans;
|
||||
let table_plans = &compile_info.table_plans;
|
||||
@@ -87,7 +75,7 @@ impl Compiler for CraneliftCompiler {
|
||||
#[cfg(feature = "unwind")]
|
||||
let dwarf_frametable = {
|
||||
use std::sync::{Arc, Mutex};
|
||||
match self.target().triple().default_calling_convention() {
|
||||
match target.triple().default_calling_convention() {
|
||||
Ok(CallingConvention::SystemV) => {
|
||||
match isa.create_systemv_cie() {
|
||||
Some(cie) => {
|
||||
@@ -139,17 +127,17 @@ impl Compiler for CraneliftCompiler {
|
||||
let mut stackmap_sink = binemit::NullStackmapSink {};
|
||||
context
|
||||
.compile_and_emit(
|
||||
isa,
|
||||
&*isa,
|
||||
&mut code_buf,
|
||||
&mut reloc_sink,
|
||||
&mut trap_sink,
|
||||
&mut stackmap_sink,
|
||||
)
|
||||
.map_err(|error| {
|
||||
CompileError::Codegen(pretty_error(&context.func, Some(isa), error))
|
||||
CompileError::Codegen(pretty_error(&context.func, Some(&*isa), error))
|
||||
})?;
|
||||
|
||||
let unwind_info = match compiled_function_unwind_info(isa, &context)? {
|
||||
let unwind_info = match compiled_function_unwind_info(&*isa, &context)? {
|
||||
#[cfg(feature = "unwind")]
|
||||
CraneliftUnwindInfo::FDE(fde) => {
|
||||
if let Some((dwarf_frametable, cie_id)) = &dwarf_frametable {
|
||||
@@ -176,7 +164,7 @@ impl Compiler for CraneliftCompiler {
|
||||
other => other.maybe_into_to_windows_unwind(),
|
||||
};
|
||||
|
||||
let address_map = get_function_address_map(&context, input, code_buf.len(), isa);
|
||||
let address_map = get_function_address_map(&context, input, code_buf.len(), &*isa);
|
||||
|
||||
// We transform the Cranelift JumpTable's into compiler JumpTables
|
||||
let func_jt_offsets = transform_jump_table(context.func.jt_offsets);
|
||||
@@ -202,9 +190,7 @@ impl Compiler for CraneliftCompiler {
|
||||
let (custom_sections, dwarf) = {
|
||||
let mut custom_sections = PrimaryMap::new();
|
||||
let dwarf = if let Some((dwarf_frametable, _cie_id)) = dwarf_frametable {
|
||||
let mut eh_frame = EhFrame(WriterRelocate::new(
|
||||
self.target().triple().endianness().ok(),
|
||||
));
|
||||
let mut eh_frame = EhFrame(WriterRelocate::new(target.triple().endianness().ok()));
|
||||
dwarf_frametable
|
||||
.lock()
|
||||
.unwrap()
|
||||
@@ -229,7 +215,7 @@ impl Compiler for CraneliftCompiler {
|
||||
.collect::<Vec<_>>()
|
||||
.par_iter()
|
||||
.map_init(FunctionBuilderContext::new, |mut cx, sig| {
|
||||
make_trampoline_function_call(&*self.isa, &mut cx, sig)
|
||||
make_trampoline_function_call(&*isa, &mut cx, sig)
|
||||
})
|
||||
.collect::<Result<Vec<FunctionBody>, CompileError>>()?
|
||||
.into_iter()
|
||||
@@ -243,7 +229,7 @@ impl Compiler for CraneliftCompiler {
|
||||
.collect::<Vec<_>>()
|
||||
.par_iter()
|
||||
.map_init(FunctionBuilderContext::new, |mut cx, func_type| {
|
||||
make_trampoline_dynamic_function(&*self.isa, &offsets, &mut cx, &func_type)
|
||||
make_trampoline_dynamic_function(&*isa, &offsets, &mut cx, &func_type)
|
||||
})
|
||||
.collect::<Result<Vec<_>, CompileError>>()?
|
||||
.into_iter()
|
||||
|
||||
@@ -49,8 +49,6 @@ pub struct CraneliftConfig {
|
||||
/// The optimization levels when optimizing the IR.
|
||||
pub opt_level: OptLevel,
|
||||
|
||||
target: Target,
|
||||
|
||||
/// The middleware chain.
|
||||
pub(crate) middlewares: Vec<Arc<dyn FunctionMiddlewareGenerator>>,
|
||||
}
|
||||
@@ -58,21 +56,19 @@ pub struct CraneliftConfig {
|
||||
impl CraneliftConfig {
|
||||
/// Creates a new configuration object with the default configuration
|
||||
/// specified.
|
||||
pub fn new(target: Target) -> Self {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
enable_nan_canonicalization: false,
|
||||
enable_verifier: false,
|
||||
opt_level: OptLevel::Speed,
|
||||
enable_pic: false,
|
||||
enable_simd: false,
|
||||
target,
|
||||
middlewares: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
/// Generates the ISA for the current target
|
||||
pub fn isa(&self) -> Box<dyn TargetIsa> {
|
||||
let target = self.target();
|
||||
/// Generates the ISA for the provided target
|
||||
pub fn isa(&self, target: &Target) -> Box<dyn TargetIsa> {
|
||||
let mut builder =
|
||||
lookup(target.triple().clone()).expect("construct Cranelift ISA for triple");
|
||||
// Cpu Features
|
||||
@@ -126,7 +122,7 @@ impl CraneliftConfig {
|
||||
builder.finish(self.flags())
|
||||
}
|
||||
|
||||
/// Generates the flags for the current target
|
||||
/// Generates the flags for the compiler
|
||||
pub fn flags(&self) -> settings::Flags {
|
||||
let mut flags = settings::builder();
|
||||
|
||||
@@ -187,12 +183,6 @@ impl CompilerConfig for CraneliftConfig {
|
||||
self.enable_pic = true;
|
||||
}
|
||||
|
||||
/// Gets the target that we will use for compiling
|
||||
/// the WebAssembly module
|
||||
fn target(&self) -> &Target {
|
||||
&self.target
|
||||
}
|
||||
|
||||
/// Transform it into the compiler
|
||||
fn compiler(&self) -> Box<dyn Compiler + Send> {
|
||||
Box::new(CraneliftCompiler::new(&self))
|
||||
@@ -206,6 +196,6 @@ impl CompilerConfig for CraneliftConfig {
|
||||
|
||||
impl Default for CraneliftConfig {
|
||||
fn default() -> Self {
|
||||
Self::new(Default::default())
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user