From 6ca311f92df94a5c8d2f3df3466bbe30c5f648b1 Mon Sep 17 00:00:00 2001 From: Brandon Fish Date: Sun, 26 May 2019 11:13:37 -0500 Subject: [PATCH] Fix compilation errors and warnings --- Cargo.lock | 14 +++--- lib/clif-backend/src/code.rs | 53 ++++++++++------------- lib/llvm-backend/src/code.rs | 4 +- lib/runtime-core/src/parse.rs | 2 +- lib/singlepass-backend/src/codegen_x64.rs | 8 +++- 5 files changed, 38 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a69746302..226c85da6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -309,7 +309,7 @@ dependencies = [ [[package]] name = "cranelift-bforest" version = "0.30.0" -source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#50eaeb72cfd02e508d9416b599f0882767ced69f" +source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#84ec31b0fdfc10db491ef950815ee2961db057cb" dependencies = [ "cranelift-entity 0.30.0 (git+https://github.com/wasmerio/cranelift.git?branch=wasmer)", ] @@ -317,7 +317,7 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.30.0" -source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#50eaeb72cfd02e508d9416b599f0882767ced69f" +source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#84ec31b0fdfc10db491ef950815ee2961db057cb" dependencies = [ "cranelift-bforest 0.30.0 (git+https://github.com/wasmerio/cranelift.git?branch=wasmer)", "cranelift-codegen-meta 0.30.0 (git+https://github.com/wasmerio/cranelift.git?branch=wasmer)", @@ -331,7 +331,7 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.30.0" -source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#50eaeb72cfd02e508d9416b599f0882767ced69f" +source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#84ec31b0fdfc10db491ef950815ee2961db057cb" dependencies = [ "cranelift-entity 0.30.0 (git+https://github.com/wasmerio/cranelift.git?branch=wasmer)", ] @@ -339,12 +339,12 @@ dependencies = [ [[package]] name = "cranelift-entity" version = "0.30.0" -source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#50eaeb72cfd02e508d9416b599f0882767ced69f" +source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#84ec31b0fdfc10db491ef950815ee2961db057cb" [[package]] name = "cranelift-frontend" version = "0.30.0" -source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#50eaeb72cfd02e508d9416b599f0882767ced69f" +source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#84ec31b0fdfc10db491ef950815ee2961db057cb" dependencies = [ "cranelift-codegen 0.30.0 (git+https://github.com/wasmerio/cranelift.git?branch=wasmer)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -354,7 +354,7 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.30.0" -source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#50eaeb72cfd02e508d9416b599f0882767ced69f" +source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#84ec31b0fdfc10db491ef950815ee2961db057cb" dependencies = [ "cranelift-codegen 0.30.0 (git+https://github.com/wasmerio/cranelift.git?branch=wasmer)", "raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -364,7 +364,7 @@ dependencies = [ [[package]] name = "cranelift-wasm" version = "0.30.0" -source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#50eaeb72cfd02e508d9416b599f0882767ced69f" +source = "git+https://github.com/wasmerio/cranelift.git?branch=wasmer#84ec31b0fdfc10db491ef950815ee2961db057cb" dependencies = [ "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "cranelift-codegen 0.30.0 (git+https://github.com/wasmerio/cranelift.git?branch=wasmer)", diff --git a/lib/clif-backend/src/code.rs b/lib/clif-backend/src/code.rs index 71412b7c2..1080fb8bd 100644 --- a/lib/clif-backend/src/code.rs +++ b/lib/clif-backend/src/code.rs @@ -2,29 +2,18 @@ // and subject to the license https://github.com/CraneStation/cranelift/blob/c47ca7bafc8fc48358f1baa72360e61fc1f7a0f2/cranelift-wasm/LICENSE use crate::{ - cache::{BackendCache, CacheGenerator}, - func_env::FuncEnv, - get_isa, module, - module::{Converter, Module}, - relocation::call_names, - resolver::FuncResolverBuilder, - signal::Caller, - trampoline::Trampolines, + cache::CacheGenerator, get_isa, module, module::Converter, relocation::call_names, + resolver::FuncResolverBuilder, signal::Caller, trampoline::Trampolines, }; use cranelift_codegen::entity::EntityRef; -use cranelift_codegen::flowgraph::BasicBlock; -use cranelift_codegen::ir::{self, Ebb, Function, InstBuilder, ValueLabel}; -use cranelift_codegen::packed_option::ReservedValue; -use cranelift_codegen::timing; +use cranelift_codegen::ir::{self, Ebb, Function, InstBuilder}; use cranelift_codegen::{cursor::FuncCursor, isa}; -use cranelift_entity::packed_option::PackedOption; -use cranelift_frontend::{Block, FunctionBuilder, FunctionBuilderContext, Position, Variable}; -use cranelift_wasm::{self, translate_module, FuncTranslator, ModuleEnvironment}; -use cranelift_wasm::{get_vmctx_value_label, translate_operator, TranslationState}; -use cranelift_wasm::{FuncEnvironment, ReturnMode, WasmError, WasmResult}; +use cranelift_frontend::{FunctionBuilder, Position, Variable}; +use cranelift_wasm::{self, FuncTranslator}; +use cranelift_wasm::{get_vmctx_value_label, translate_operator}; +use cranelift_wasm::{FuncEnvironment, ReturnMode, WasmError}; use std::mem; -use std::rc::Rc; use std::sync::{Arc, RwLock}; use wasmer_runtime_core::error::CompileError; use wasmer_runtime_core::{ @@ -35,13 +24,11 @@ use wasmer_runtime_core::{ module::{ModuleInfo, ModuleInner}, structures::{Map, TypedIndex}, types::{ - ElementType, FuncIndex, FuncSig, GlobalDescriptor, GlobalIndex, GlobalInit, Initializer, - LocalFuncIndex, LocalOrImport, MemoryDescriptor, MemoryIndex, SigIndex, TableDescriptor, - TableIndex, Value, + FuncIndex, FuncSig, GlobalIndex, LocalFuncIndex, LocalOrImport, MemoryIndex, SigIndex, + TableIndex, }, vm, }; -use wasmparser::Operator; use wasmparser::Type as WpType; pub struct CraneliftModuleCodeGenerator { @@ -50,11 +37,8 @@ pub struct CraneliftModuleCodeGenerator { pub clif_signatures: Map, function_signatures: Option>>, functions: Vec, - func_bodies: Map, } -pub struct ClifFuncEnv {} - impl ModuleCodeGenerator for CraneliftModuleCodeGenerator { @@ -66,7 +50,6 @@ impl ModuleCodeGenerator functions: vec![], function_signatures: None, signatures: None, - func_bodies: Map::new(), } } @@ -84,7 +67,7 @@ impl ModuleCodeGenerator ) -> Result<&mut CraneliftFunctionCodeGenerator, CodegenError> { // define_function_body( - let mut func_translator = FuncTranslator::new(); + let func_translator = FuncTranslator::new(); let func_index = LocalFuncIndex::new(self.functions.len()); let name = ir::ExternalName::user(0, func_index.index() as u32); @@ -97,7 +80,7 @@ impl ModuleCodeGenerator ), ); - let mut func = ir::Function::with_name_signature(name, sig); + let func = ir::Function::with_name_signature(name, sig); //func_translator.translate(body_bytes, body_offset, &mut func, &mut func_env)?; @@ -370,6 +353,14 @@ impl From for CodegenError { } } +impl From for CodegenError { + fn from(other: WasmError) -> CodegenError { + CodegenError { + message: format!("{:?}", other), + } + } +} + pub struct CraneliftFunctionCodeGenerator { func: Function, func_translator: FuncTranslator, @@ -1086,7 +1077,7 @@ impl FunctionCodeGenerator for CraneliftFunctionCodeGenerator { fn feed_local(&mut self, ty: WpType, n: usize) -> Result<(), CodegenError> { let mut next_local = self.next_local; - cranelift_wasm::declare_locals(&mut self.builder(), n as u32, ty, &mut next_local); + cranelift_wasm::declare_locals(&mut self.builder(), n as u32, ty, &mut next_local)?; self.next_local = next_local; Ok(()) } @@ -1112,7 +1103,7 @@ impl FunctionCodeGenerator for CraneliftFunctionCodeGenerator { clif_signatures: self.clif_signatures.clone(), }; - if (self.func_translator.state.control_stack.is_empty()) { + if self.func_translator.state.control_stack.is_empty() { return Ok(()); } @@ -1122,7 +1113,7 @@ impl FunctionCodeGenerator for CraneliftFunctionCodeGenerator { &mut self.position, ); let state = &mut self.func_translator.state; - translate_operator(op, &mut builder, state, &mut function_environment); + translate_operator(op, &mut builder, state, &mut function_environment)?; Ok(()) } diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 54674923e..bb9f95958 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -8,7 +8,7 @@ use inkwell::{ AddressSpace, FloatPredicate, IntPredicate, }; use smallvec::SmallVec; -use std::sync::Arc; +use std::sync::{Arc, RwLock}; use wasmer_runtime_core::{ backend::{Backend, CacheGen, Token}, cache::{Artifact, Error as CacheError}, @@ -2475,7 +2475,7 @@ impl ModuleCodeGenerator fn next_function( &mut self, - _module_info: Arc, + _module_info: Arc>, ) -> Result<&mut LLVMFunctionCodeGenerator, CodegenError> { // Creates a new function and returns the function-scope code generator for it. let (context, builder, intrinsics) = match self.functions.last_mut() { diff --git a/lib/runtime-core/src/parse.rs b/lib/runtime-core/src/parse.rs index dfa5c4eae..0724005c8 100644 --- a/lib/runtime-core/src/parse.rs +++ b/lib/runtime-core/src/parse.rs @@ -54,7 +54,7 @@ pub fn read_module< middlewares: &mut MiddlewareChain, compiler_config: &CompilerConfig, ) -> Result>, LoadError> { - let mut info = Arc::new(RwLock::new(ModuleInfo { + let info = Arc::new(RwLock::new(ModuleInfo { memories: Map::new(), globals: Map::new(), tables: Map::new(), diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index 69937f86e..56e1854f5 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -8,7 +8,11 @@ use dynasmrt::{ }; use smallvec::SmallVec; use std::ptr::NonNull; -use std::{any::Any, collections::HashMap, sync::Arc}; +use std::{ + any::Any, + collections::HashMap, + sync::{Arc, RwLock}, +}; use wasmer_runtime_core::{ backend::{sys::Memory, Backend, CacheGen, RunnableModule, Token}, cache::{Artifact, Error as CacheError}, @@ -302,7 +306,7 @@ impl ModuleCodeGenerator fn next_function( &mut self, - _module_info: Arc, + _module_info: Arc>, ) -> Result<&mut X64FunctionCode, CodegenError> { let (mut assembler, mut function_labels, br_table_data, breakpoints) = match self.functions.last_mut() {