mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-09 22:28:21 +00:00
Refactored Compilers
This commit is contained in:
@@ -3,13 +3,11 @@ use crate::trampoline::FuncTrampoline;
|
||||
use crate::translator::FuncTranslator;
|
||||
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
||||
use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap};
|
||||
use wasm_common::Features;
|
||||
use wasm_common::{LocalFunctionIndex, MemoryIndex, TableIndex};
|
||||
use wasm_common::LocalFunctionIndex;
|
||||
use wasmer_compiler::{
|
||||
Compilation, CompileError, Compiler, CompilerConfig, FunctionBodyData, ModuleTranslationState,
|
||||
RelocationTarget, SectionIndex, Target,
|
||||
Compilation, CompileError, CompileModuleInfo, Compiler, CompilerConfig, FunctionBodyData,
|
||||
ModuleTranslationState, RelocationTarget, SectionIndex, Target,
|
||||
};
|
||||
use wasmer_runtime::{MemoryPlan, ModuleInfo, TablePlan};
|
||||
|
||||
//use std::sync::{Arc, Mutex};
|
||||
|
||||
@@ -27,18 +25,13 @@ impl LLVMCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the WebAssembly features for this Compiler
|
||||
/// Gets the config for this Compiler
|
||||
fn config(&self) -> &LLVMConfig {
|
||||
&self.config
|
||||
}
|
||||
}
|
||||
|
||||
impl Compiler for LLVMCompiler {
|
||||
/// Gets the WebAssembly features for this Compiler
|
||||
fn features(&self) -> &Features {
|
||||
self.config.features()
|
||||
}
|
||||
|
||||
/// Gets the target associated to this Compiler.
|
||||
fn target(&self) -> &Target {
|
||||
self.config.target()
|
||||
@@ -48,14 +41,15 @@ impl Compiler for LLVMCompiler {
|
||||
/// associated relocations.
|
||||
fn compile_module<'data, 'module>(
|
||||
&self,
|
||||
module: &'module ModuleInfo,
|
||||
compile_info: &'module CompileModuleInfo,
|
||||
module_translation: &ModuleTranslationState,
|
||||
function_body_inputs: PrimaryMap<LocalFunctionIndex, FunctionBodyData<'data>>,
|
||||
memory_plans: PrimaryMap<MemoryIndex, MemoryPlan>,
|
||||
table_plans: PrimaryMap<TableIndex, TablePlan>,
|
||||
) -> Result<Compilation, CompileError> {
|
||||
//let data = Arc::new(Mutex::new(0));
|
||||
let mut func_names = SecondaryMap::new();
|
||||
let memory_plans = &compile_info.memory_plans;
|
||||
let table_plans = &compile_info.table_plans;
|
||||
let module = &compile_info.module;
|
||||
|
||||
// TODO: merge constants in sections.
|
||||
|
||||
@@ -75,7 +69,7 @@ impl Compiler for LLVMCompiler {
|
||||
// TODO: remove (to serialize)
|
||||
//let mut data = data.lock().unwrap();
|
||||
func_translator.translate(
|
||||
module,
|
||||
&module,
|
||||
module_translation,
|
||||
i,
|
||||
input,
|
||||
|
||||
@@ -8,9 +8,7 @@ use itertools::Itertools;
|
||||
use std::sync::Arc;
|
||||
use target_lexicon::Architecture;
|
||||
use wasm_common::{FunctionType, LocalFunctionIndex};
|
||||
use wasmer_compiler::{
|
||||
Compiler, CompilerConfig, Features, FunctionMiddlewareGenerator, Target, Triple,
|
||||
};
|
||||
use wasmer_compiler::{Compiler, CompilerConfig, FunctionMiddlewareGenerator, Target, Triple};
|
||||
|
||||
/// The InkWell ModuleInfo type
|
||||
pub type InkwellModule<'ctx> = inkwell::module::Module<'ctx>;
|
||||
@@ -66,25 +64,24 @@ pub struct LLVMConfig {
|
||||
/// The middleware chain.
|
||||
pub(crate) middlewares: Vec<Arc<dyn FunctionMiddlewareGenerator>>,
|
||||
|
||||
features: Features,
|
||||
target: Target,
|
||||
}
|
||||
|
||||
impl LLVMConfig {
|
||||
/// Creates a new configuration object with the default configuration
|
||||
/// specified.
|
||||
pub fn new(features: Features, target: Target) -> Self {
|
||||
pub fn new(target: Target) -> Self {
|
||||
Self {
|
||||
enable_nan_canonicalization: true,
|
||||
enable_verifier: false,
|
||||
opt_level: OptimizationLevel::Aggressive,
|
||||
is_pic: false,
|
||||
features,
|
||||
target,
|
||||
callbacks: None,
|
||||
middlewares: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn reloc_mode(&self) -> RelocMode {
|
||||
if self.is_pic {
|
||||
RelocMode::PIC
|
||||
@@ -171,11 +168,6 @@ impl LLVMConfig {
|
||||
}
|
||||
|
||||
impl CompilerConfig for LLVMConfig {
|
||||
/// Gets the WebAssembly features.
|
||||
fn features(&self) -> &Features {
|
||||
&self.features
|
||||
}
|
||||
|
||||
/// Emit code suitable for dlopen.
|
||||
fn enable_pic(&mut self) {
|
||||
// TODO: although we can emit PIC, the object file parser does not yet
|
||||
@@ -202,6 +194,6 @@ impl CompilerConfig for LLVMConfig {
|
||||
|
||||
impl Default for LLVMConfig {
|
||||
fn default() -> LLVMConfig {
|
||||
Self::new(Default::default(), Default::default())
|
||||
Self::new(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user