diff --git a/Cargo.toml b/Cargo.toml index cc04736e85..ca777d6c69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,9 +18,6 @@ path = "src/wasm2obj.rs" [dependencies] cranelift-codegen = "0.18.1" -cranelift-frontend = "0.18.1" -cranelift-reader = "0.18.1" -cranelift-wasm = "0.18.1" cranelift-native = "0.18.1" wasmtime-runtime = { path = "lib/runtime" } wasmtime-execute = { path = "lib/execute" } diff --git a/clippy.toml b/clippy.toml index ce7f17cc64..d2012085bb 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -doc-valid-idents = [ "WebAssembly", "NaN" ] +doc-valid-idents = [ "WebAssembly" ] diff --git a/fuzz/fuzz_targets/compile.rs b/fuzz/fuzz_targets/compile.rs index 37ac91f2ef..03e70a0e86 100644 --- a/fuzz/fuzz_targets/compile.rs +++ b/fuzz/fuzz_targets/compile.rs @@ -24,11 +24,10 @@ fuzz_target!(|data: &[u8]| { let isa = isa_builder.finish(settings::Flags::new(flag_builder)); let mut module = Module::new(); let mut runtime = ModuleEnvironment::new(&*isa, &mut module); - match translate_module(&data, &mut runtime) { + let translation = match translate_module(&data, &mut runtime) { Ok(()) => (), Err(_) => return, }; - let translation = runtime.finish_translation(); let _exec = match wasmtime_execute::compile_module(&*isa, &translation) { Ok(x) => x, Err(_) => return, diff --git a/lib/execute/src/execute.rs b/lib/execute/src/execute.rs index 6642da4d3c..3b5c94253b 100644 --- a/lib/execute/src/execute.rs +++ b/lib/execute/src/execute.rs @@ -37,7 +37,7 @@ fn relocate(compilation: &mut Compilation, relocations: &[Vec]) { match r.reloc { Reloc::Abs8 => unsafe { let reloc_address = body.as_mut_ptr().offset(r.offset as isize) as i64; - let reloc_addend = r.addend as i64; + let reloc_addend = r.addend; let reloc_abs = target_func_address as i64 + reloc_addend; write_unaligned(reloc_address as *mut i64, reloc_abs); }, diff --git a/lib/execute/src/lib.rs b/lib/execute/src/lib.rs index 9a669da581..6898f635ab 100644 --- a/lib/execute/src/lib.rs +++ b/lib/execute/src/lib.rs @@ -1,6 +1,16 @@ //! JIT-style runtime for WebAssembly using Cranelift. -#![deny(missing_docs)] +#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates, unstable_features)] +#![warn(unused_import_braces)] +#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] +#![cfg_attr(feature = "cargo-clippy", allow(new_without_default, new_without_default_derive))] +#![cfg_attr( + feature = "cargo-clippy", + warn( + float_arithmetic, mut_mut, nonminimal_bool, option_map_unwrap_or, option_map_unwrap_or_else, + print_stdout, unicode_not_nfc, use_self + ) +)] extern crate cranelift_codegen; extern crate cranelift_wasm; diff --git a/lib/obj/Cargo.toml b/lib/obj/Cargo.toml index 4c7e72b776..247430311b 100644 --- a/lib/obj/Cargo.toml +++ b/lib/obj/Cargo.toml @@ -7,6 +7,5 @@ license = "Apache-2.0 WITH LLVM-exception" [dependencies] cranelift-codegen = "0.18.1" -cranelift-wasm = "0.18.1" wasmtime-runtime = { path = "../runtime" } faerie = "0.4.4" diff --git a/lib/obj/src/lib.rs b/lib/obj/src/lib.rs index dcaa6462fa..e7597c5785 100644 --- a/lib/obj/src/lib.rs +++ b/lib/obj/src/lib.rs @@ -1,5 +1,18 @@ +//! Object-file writing library using the wasmtime runtime. + +#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates, unstable_features)] +#![warn(unused_import_braces)] +#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] +#![cfg_attr(feature = "cargo-clippy", allow(new_without_default, new_without_default_derive))] +#![cfg_attr( + feature = "cargo-clippy", + warn( + float_arithmetic, mut_mut, nonminimal_bool, option_map_unwrap_or, option_map_unwrap_or_else, + print_stdout, unicode_not_nfc, use_self + ) +)] + extern crate cranelift_codegen; -extern crate cranelift_wasm; extern crate faerie; extern crate wasmtime_runtime; diff --git a/lib/runtime/src/compilation.rs b/lib/runtime/src/compilation.rs index 0f0ce6e557..d849eef0a0 100644 --- a/lib/runtime/src/compilation.rs +++ b/lib/runtime/src/compilation.rs @@ -71,8 +71,8 @@ impl binemit::RelocSink for RelocSink { } impl RelocSink { - fn new() -> RelocSink { - RelocSink { + fn new() -> Self { + Self { func_relocs: Vec::new(), } } diff --git a/lib/runtime/src/environ.rs b/lib/runtime/src/environ.rs index cadbe1362f..07ae4e90a4 100644 --- a/lib/runtime/src/environ.rs +++ b/lib/runtime/src/environ.rs @@ -8,10 +8,9 @@ use cranelift_codegen::ir::{ }; use cranelift_codegen::isa; use cranelift_codegen::settings; -use cranelift_wasm; use cranelift_wasm::{ - FunctionIndex, Global, GlobalIndex, GlobalVariable, Memory, MemoryIndex, SignatureIndex, Table, - TableIndex, WasmResult, + self, FunctionIndex, Global, GlobalIndex, GlobalVariable, Memory, MemoryIndex, SignatureIndex, Table, + TableIndex, WasmResult, translate_module, }; use module::{DataInitializer, Export, LazyContents, Module, TableElements}; use target_lexicon::Triple; @@ -23,7 +22,7 @@ pub fn get_func_name(func_index: FunctionIndex) -> ir::ExternalName { } /// Object containing the standalone runtime information. To be passed after creation as argument -/// to `cranelift_wasm::translatemodule`. +/// to `compile_module`. pub struct ModuleEnvironment<'data, 'module> { /// Compilation setting flags. pub isa: &'module isa::TargetIsa, @@ -54,16 +53,18 @@ impl<'data, 'module> ModuleEnvironment<'data, 'module> { self.func_env().pointer_type() } - /// Declare that translation of the module is complete. This consumes the - /// `ModuleEnvironment` with its mutable reference to the `Module` and - /// produces a `ModuleTranslation` with an immutable reference to the - /// `Module`. - pub fn finish_translation(self) -> ModuleTranslation<'data, 'module> { - ModuleTranslation { + /// Translate the given wasm module data using this environment. This consumes the + /// `ModuleEnvironment` with its mutable reference to the `Module` and produces a + /// `ModuleTranslation` with an immutable reference to the `Module` (which has + /// become fully populated). + pub fn translate(mut self, data: &'data [u8]) -> WasmResult> { + translate_module(data, &mut self)?; + + Ok(ModuleTranslation { isa: self.isa, module: self.module, lazy: self.lazy, - } + }) } } @@ -117,7 +118,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> { } /// This trait is useful for -/// `cranelift_wasm::translatemodule` because it +/// `cranelift_wasm::translate_module` because it /// tells how to translate runtime-dependent wasm instructions. These functions should not be /// called by the user. impl<'data, 'module> cranelift_wasm::ModuleEnvironment<'data> @@ -176,7 +177,7 @@ impl<'data, 'module> cranelift_wasm::ModuleEnvironment<'data> self.module.globals.push(global); } - fn get_global(&self, global_index: GlobalIndex) -> &cranelift_wasm::Global { + fn get_global(&self, global_index: GlobalIndex) -> &Global { &self.module.globals[global_index] } @@ -273,7 +274,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m self.globals_base = Some(new_base); new_base }); - let offset = index as usize * pointer_bytes; + let offset = index * pointer_bytes; let offset32 = offset as i32; debug_assert_eq!(offset32 as usize, offset); let gv = func.create_global_value(ir::GlobalValueData::Deref { @@ -295,7 +296,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m self.globals_base = Some(new_base); new_base }); - let offset = index as usize * pointer_bytes; + let offset = index * pointer_bytes; let offset32 = offset as i32; debug_assert_eq!(offset32 as usize, offset); let heap_base_addr = func.create_global_value(ir::GlobalValueData::Deref { diff --git a/lib/runtime/src/lib.rs b/lib/runtime/src/lib.rs index a60da84b1f..7907040462 100644 --- a/lib/runtime/src/lib.rs +++ b/lib/runtime/src/lib.rs @@ -3,7 +3,17 @@ //! the translation the base addresses of regions of memory that will hold the globals, tables and //! linear memories. -#![deny(missing_docs)] +#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates, unstable_features)] +#![warn(unused_import_braces)] +#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] +#![cfg_attr(feature = "cargo-clippy", allow(new_without_default, new_without_default_derive))] +#![cfg_attr( + feature = "cargo-clippy", + warn( + float_arithmetic, mut_mut, nonminimal_bool, option_map_unwrap_or, option_map_unwrap_or_else, + print_stdout, unicode_not_nfc, use_self + ) +)] extern crate cranelift_codegen; extern crate cranelift_wasm; diff --git a/src/main.rs b/src/main.rs index 6a685425a9..40c96ee16b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,9 +5,20 @@ //! IL. Can also executes the `start` function of the module by laying out the memories, globals //! and tables, then emitting the translated code with hardcoded addresses to memory. +#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates, unstable_features)] +#![warn(unused_import_braces)] +#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] +#![cfg_attr(feature = "cargo-clippy", allow(new_without_default, new_without_default_derive))] +#![cfg_attr( + feature = "cargo-clippy", + warn( + float_arithmetic, mut_mut, nonminimal_bool, option_map_unwrap_or, option_map_unwrap_or_else, + unicode_not_nfc, use_self + ) +)] + extern crate cranelift_codegen; extern crate cranelift_native; -extern crate cranelift_wasm; extern crate docopt; extern crate wasmtime_execute; extern crate wasmtime_runtime; @@ -18,7 +29,6 @@ extern crate tempdir; use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::settings; use cranelift_codegen::settings::Configurable; -use cranelift_wasm::translate_module; use docopt::Docopt; use std::error::Error; use std::fs::File; @@ -119,9 +129,8 @@ fn handle_module(args: &Args, path: PathBuf, isa: &TargetIsa) -> Result<(), Stri data = read_to_end(file_path).map_err(|err| String::from(err.description()))?; } let mut module = Module::new(); - let mut environ = ModuleEnvironment::new(isa, &mut module); - translate_module(&data, &mut environ).map_err(|e| e.to_string())?; - let translation = environ.finish_translation(); + let environ = ModuleEnvironment::new(isa, &mut module); + let translation = environ.translate(&data).map_err(|e| e.to_string())?; let instance = match compile_and_link_module(isa, &translation) { Ok(compilation) => { let mut instance = diff --git a/src/wasm2obj.rs b/src/wasm2obj.rs index 96b2f265cf..f0c6d5e146 100644 --- a/src/wasm2obj.rs +++ b/src/wasm2obj.rs @@ -4,9 +4,20 @@ //! IL, then translates it to native code, and writes it out to a native //! object file with relocations. +#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates, unstable_features)] +#![warn(unused_import_braces)] +#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))] +#![cfg_attr(feature = "cargo-clippy", allow(new_without_default, new_without_default_derive))] +#![cfg_attr( + feature = "cargo-clippy", + warn( + float_arithmetic, mut_mut, nonminimal_bool, option_map_unwrap_or, option_map_unwrap_or_else, + unicode_not_nfc, use_self + ) +)] + extern crate cranelift_codegen; extern crate cranelift_native; -extern crate cranelift_wasm; extern crate docopt; extern crate wasmtime_obj; extern crate wasmtime_runtime; @@ -15,7 +26,6 @@ extern crate serde_derive; extern crate faerie; use cranelift_codegen::settings; -use cranelift_wasm::translate_module; use docopt::Docopt; use faerie::Artifact; use std::error::Error; @@ -91,21 +101,19 @@ fn handle_module(path: PathBuf, output: &str) -> Result<(), String> { }); let isa = isa_builder.finish(settings::Flags::new(flag_builder)); - let mut module = wasmtime_runtime::Module::new(); - let mut environ = wasmtime_runtime::ModuleEnvironment::new(&*isa, &mut module); - translate_module(&data, &mut environ).map_err(|e| e.to_string())?; - let mut obj = Artifact::new(isa.triple().clone(), String::from(output)); + let mut module = wasmtime_runtime::Module::new(); + let environ = wasmtime_runtime::ModuleEnvironment::new(&*isa, &mut module); + let translation = environ.translate(&data).map_err(|e| e.to_string())?; + // FIXME: We need to initialize memory in a way that supports alternate // memory spaces, imported base addresses, and offsets. - for init in &environ.lazy.data_initializers { + for init in &translation.lazy.data_initializers { obj.define("memory", Vec::from(init.data)) .map_err(|err| format!("{}", err))?; } - let translation = environ.finish_translation(); - let (compilation, relocations) = compile_module(&translation, &*isa)?; emit_module(&mut obj, &translation.module, &compilation, &relocations)?;