Fix most compile issues in compiler-llvm.

Still to be fixed are MemoryPlan, MemoryStyle, TablePlan, and TableStyle.
This commit is contained in:
Nick Lewycky
2020-04-22 15:50:10 -07:00
parent f909355f4c
commit 4e6371c3ce
8 changed files with 44 additions and 31 deletions

View File

@@ -2,18 +2,17 @@
// Allow unused imports while developing.
#![allow(unused_imports, dead_code)]
use crate::code::FuncTranslator;
use crate::config::LLVMConfig;
use crate::translator::FuncTranslator;
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use wasm_common::entity::{EntityRef, PrimaryMap};
use wasm_common::Features;
use wasm_common::{LocalFuncIndex, FuncIndex, FuncType};
use wasm_common::{FuncIndex, FuncType, LocalFuncIndex, MemoryIndex, TableIndex};
use wasmer_compiler::FunctionBodyData;
use wasmer_compiler::Module;
use wasmer_compiler::TrapInformation;
use wasmer_compiler::{Compilation, CompileError, CompiledFunction, Compiler};
use wasmer_compiler::{CompilerConfig, ModuleTranslationState, Target};
use wasmer_compiler::TrapInformation;
use wasmer_runtime::TrapCode;
use wasmer_runtime::{MemoryPlan, Module, TablePlan, TrapCode};
use inkwell::targets::{InitializationConfig, Target as InkwellTarget};
@@ -50,11 +49,13 @@ impl Compiler for LLVMCompiler {
/// Compile the module using LLVM, producing a compilation result with
/// associated relocations.
fn compile_module(
fn compile_module<'data, 'module>(
&self,
module: &Module,
module: &'module Module,
_module_translation: &ModuleTranslationState,
function_body_inputs: PrimaryMap<LocalFuncIndex, FunctionBodyData<'_>>,
function_body_inputs: PrimaryMap<LocalFuncIndex, FunctionBodyData<'data>>,
_memory_plans: PrimaryMap<MemoryIndex, MemoryPlan>,
_table_plans: PrimaryMap<TableIndex, TablePlan>,
) -> Result<Compilation, CompileError> {
let functions = function_body_inputs
.into_iter()

View File

@@ -10,7 +10,6 @@ use itertools::Itertools;
use target_lexicon::Architecture;
use wasmer_compiler::{Compiler, CompilerConfig, CpuFeature, Features, Target};
/// The InkWell Module type
pub type InkwellModule<'ctx> = inkwell::module::Module<'ctx>;

View File

@@ -17,10 +17,10 @@
#![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")]
mod compiler;
mod translator;
mod config;
mod structs;
mod translator;
// mod structs;
// mod trampoline;
pub use crate::compiler::LLVMCompiler;
pub use crate::config::{LLVMConfig, LLVMCallbacks, InkwellModule, InkwellMemoryBuffer};
pub use crate::config::{InkwellMemoryBuffer, InkwellModule, LLVMCallbacks, LLVMConfig};

View File

@@ -32,16 +32,17 @@ use std::any::Any;
use crate::config::LLVMConfig;
use wasm_common::entity::SecondaryMap;
use wasm_common::{
LocalFuncIndex, FuncIndex, FuncType, GlobalIndex, MemoryIndex, SignatureIndex, TableIndex,
Type,
FuncIndex, FuncType, GlobalIndex, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex, Type,
};
use wasmer_compiler::CompiledFunctionUnwindInfo;
use wasmer_compiler::FunctionAddressMap;
use wasmer_compiler::FunctionBodyData;
use wasmer_compiler::MemoryStyle;
use wasmer_compiler::Module as WasmerCompilerModule;
use wasmer_compiler::SourceLoc;
use wasmer_compiler::{
to_wasm_error, wasm_unsupported, CompileError, CompiledFunction, WasmResult,
};
use wasmer_runtime::MemoryStyle;
use wasmer_runtime::Module as WasmerCompilerModule;
use wasmparser::{BinaryReader, MemoryImmediate, Operator};
// TODO
@@ -103,7 +104,6 @@ impl FuncTranslator {
module.set_triple(&target_triple);
module.set_data_layout(&target_machine.get_target_data().get_data_layout());
let wasm_fn_type = wasm_module
.local
.signatures
.get(*wasm_module.functions.get(func_index).unwrap())
.unwrap();
@@ -261,7 +261,16 @@ impl FuncTranslator {
// TODO: grab text section, use it to fill in 'body'.
let address_map = FunctionAddressMap {
instructions: vec![],
start_srcloc: SourceLoc::default(),
end_srcloc: SourceLoc::default(),
body_offset: 0,
body_len: 0, // TODO
};
Ok(CompiledFunction {
address_map,
body: vec![],
jt_offsets: SecondaryMap::new(),
unwind_info: CompiledFunctionUnwindInfo::None,
@@ -8629,11 +8638,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
Operator::MemoryGrow { reserved } => {
let mem_index = MemoryIndex::from_u32(reserved);
let func_value = if let Some(local_mem_index) =
module.local_memory_index(mem_index)
let func_value = if let Some(local_mem_index) = module.local_memory_index(mem_index)
{
match module
.local
.memory_plans
.get(module.memory_index(local_mem_index))
.unwrap()
@@ -8664,11 +8671,9 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
}
Operator::MemorySize { reserved } => {
let mem_index = MemoryIndex::from_u32(reserved);
let func_value = if let Some(local_mem_index) =
module.local_memory_index(mem_index)
let func_value = if let Some(local_mem_index) = module.local_memory_index(mem_index)
{
match module
.local
.memory_plans
.get(module.memory_index(local_mem_index))
.unwrap()

View File

@@ -33,9 +33,9 @@ use wasm_common::entity::EntityRef;
use wasm_common::{
FuncIndex, GlobalIndex, MemoryIndex, Mutability, SignatureIndex, TableIndex, Type,
};
use wasmer_compiler::MemoryStyle;
use wasmer_compiler::Module as WasmerCompilerModule;
use wasmer_compiler::VMOffsets;
use wasmer_runtime::MemoryStyle;
use wasmer_runtime::Module as WasmerCompilerModule;
use wasmer_runtime::VMOffsets;
fn type_to_llvm_ptr<'ctx>(intrinsics: &Intrinsics<'ctx>, ty: Type) -> PointerType<'ctx> {
match ty {
@@ -699,7 +699,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> {
&self.cache_builder,
);
// TODO: pointer width
let offsets = VMOffsets::new(8, &self.wasm_module.local);
let offsets = VMOffsets::new(8, &self.wasm_module);
*cached_memories.entry(index).or_insert_with(|| {
let (memory_array_ptr_ptr, index, memory_type, minimum, maximum, field_name) = {
@@ -825,7 +825,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> {
&self.cache_builder,
);
// TODO: pointer width
let offsets = VMOffsets::new(8, &self.wasm_module.local);
let offsets = VMOffsets::new(8, &self.wasm_module);
let TableCache {
ptr_to_base_ptr,
@@ -939,7 +939,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> {
&self.cache_builder,
);
// TODO: pointer width
let offsets = VMOffsets::new(8, &self.wasm_module.local);
let offsets = VMOffsets::new(8, &self.wasm_module);
*cached_sigindices.entry(index).or_insert_with(|| {
let sigindex_array_ptr_ptr = unsafe {
@@ -981,7 +981,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> {
&self.cache_builder,
);
// TODO: pointer width
let offsets = VMOffsets::new(8, &self.wasm_module.local);
let offsets = VMOffsets::new(8, &self.wasm_module);
*cached_globals.entry(index).or_insert_with(|| {
let (globals_array_ptr_ptr, index, mutable, wasmer_ty, field_name) = {
@@ -1082,7 +1082,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> {
&self.cache_builder,
);
// TODO: pointer width
let offsets = VMOffsets::new(8, &self.wasm_module.local);
let offsets = VMOffsets::new(8, &self.wasm_module);
let imported_func_cache = cached_imported_functions.entry(index).or_insert_with(|| {
let func_array_ptr_ptr = unsafe {

View File

@@ -3,3 +3,5 @@ mod intrinsics;
mod read_info;
//mod stackmap;
mod state;
pub use self::code::FuncTranslator;