diff --git a/cranelift/fuzz/fuzz_reader_parse_test.rs b/cranelift/fuzz/fuzz_reader_parse_test.rs index fc5709e4b2..8ef582af05 100644 --- a/cranelift/fuzz/fuzz_reader_parse_test.rs +++ b/cranelift/fuzz/fuzz_reader_parse_test.rs @@ -4,8 +4,6 @@ extern crate libfuzzer_sys; extern crate cranelift_reader; use std::str; -fuzz_target!(|data: &[u8]| { - if let Ok(s) = str::from_utf8(data) { - let _ = cranelift_reader::parse_test(s); - } +fuzz_target!(|data: &[u8]| if let Ok(s) = str::from_utf8(data) { + let _ = cranelift_reader::parse_test(s); }); diff --git a/cranelift/src/wasm.rs b/cranelift/src/wasm.rs index 34fcb26ad0..f446bb6ccc 100644 --- a/cranelift/src/wasm.rs +++ b/cranelift/src/wasm.rs @@ -4,9 +4,9 @@ //! Reads Wasm binary files, translates the functions' code to Cranelift IR. #![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments, cyclomatic_complexity))] -use cranelift_codegen::Context; use cranelift_codegen::print_errors::{pretty_error, pretty_verifier_error}; use cranelift_codegen::settings::FlagsOrIsa; +use cranelift_codegen::Context; use cranelift_entity::EntityRef; use cranelift_wasm::{translate_module, DummyEnvironment, FuncIndex, ModuleEnvironment}; use std::error::Error; @@ -80,7 +80,8 @@ fn handle_module( vprint!(flag_verbose, "Translating... "); terminal.reset().unwrap(); - let mut module_binary = read_to_end(path.clone()).map_err(|err| String::from(err.description()))?; + let mut module_binary = + read_to_end(path.clone()).map_err(|err| String::from(err.description()))?; if !module_binary.starts_with(&[b'\0', b'a', b's', b'm']) { module_binary = match wat2wasm(&module_binary) { @@ -91,7 +92,11 @@ fn handle_module( let isa = match fisa.isa { Some(isa) => isa, - None => return Err(String::from("Error: the wasm command requires an explicit isa.")) + None => { + return Err(String::from( + "Error: the wasm command requires an explicit isa.", + )) + } }; let mut dummy_environ = @@ -118,7 +123,9 @@ fn handle_module( } } vprintln!(flag_verbose, ""); - for export_name in &dummy_environ.info.functions[FuncIndex::new(func_index)].export_names { + for export_name in + &dummy_environ.info.functions[FuncIndex::new(func_index)].export_names + { println!("; Exported as \"{}\"", export_name); } println!("{}", context.func.display(None)); @@ -163,7 +170,8 @@ fn handle_module( total_module_code_size += compiled_size; println!( "Function #{} bytecode size: {} bytes", - func_index, dummy_environ.func_bytecode_sizes[def_index.index()] + func_index, + dummy_environ.func_bytecode_sizes[def_index.index()] ); } } @@ -175,7 +183,9 @@ fn handle_module( println!("; Selected as wasm start function"); } } - for export_name in &dummy_environ.info.functions[FuncIndex::new(func_index)].export_names { + for export_name in + &dummy_environ.info.functions[FuncIndex::new(func_index)].export_names + { println!("; Exported as \"{}\"", export_name); } println!("{}", context.func.display(fisa.isa)); diff --git a/lib/codegen/src/constant_hash.rs b/lib/codegen/src/constant_hash.rs index 553543ec60..0aaa3c51c2 100644 --- a/lib/codegen/src/constant_hash.rs +++ b/lib/codegen/src/constant_hash.rs @@ -1,7 +1,7 @@ //! Runtime support for precomputed constant hash tables. //! -//! The `lib/codegen/meta-python/constant_hash.py` Python module can generate constant hash tables using -//! open addressing and quadratic probing. The hash tables are arrays that are guaranteed to: +//! The `lib/codegen/meta-python/constant_hash.py` Python module can generate constant hash tables +//! using open addressing and quadratic probing. The hash tables are arrays that are guaranteed to: //! //! - Have a power-of-two size. //! - Contain at least one empty slot. diff --git a/lib/codegen/src/isa/mod.rs b/lib/codegen/src/isa/mod.rs index f5dd62f294..b95c32f967 100644 --- a/lib/codegen/src/isa/mod.rs +++ b/lib/codegen/src/isa/mod.rs @@ -23,8 +23,8 @@ //! # extern crate cranelift_codegen; //! # #[macro_use] extern crate target_lexicon; //! # fn main() { -//! use cranelift_codegen::settings::{self, Configurable}; //! use cranelift_codegen::isa; +//! use cranelift_codegen::settings::{self, Configurable}; //! use std::str::FromStr; //! use target_lexicon::Triple; //! diff --git a/lib/codegen/src/isa/x86/abi.rs b/lib/codegen/src/isa/x86/abi.rs index 21796e2a10..6028fa507d 100644 --- a/lib/codegen/src/isa/x86/abi.rs +++ b/lib/codegen/src/isa/x86/abi.rs @@ -433,8 +433,8 @@ fn insert_common_prologue( if let Some(stack_limit_arg) = pos.func.special_param(ArgumentPurpose::StackLimit) { // Total stack size is the size of all stack area used by the function, including // pushed CSRs, frame pointer. - // Also, the size of a return address, implicitly pushed by a x86 `call` instruction, also - // should be accounted for. + // Also, the size of a return address, implicitly pushed by a x86 `call` instruction, + // also should be accounted for. // TODO: Check if the function body actually contains a `call` instruction. let word_size = isa.pointer_bytes(); let total_stack_size = (csrs.iter(GPR).len() + 1 + 1) as i64 * word_size as i64; diff --git a/lib/codegen/src/isa/x86/enc_tables.rs b/lib/codegen/src/isa/x86/enc_tables.rs index 52af977ad6..ebaaa526f7 100644 --- a/lib/codegen/src/isa/x86/enc_tables.rs +++ b/lib/codegen/src/isa/x86/enc_tables.rs @@ -367,23 +367,27 @@ fn expand_fcvt_to_sint( let output_bits = ty.lane_bits(); let flimit = match xty { ir::types::F32 => - // An f32 can represent `i16::min_value() - 1` exactly with precision to spare, so - // there are values less than -2^(N-1) that convert correctly to INT_MIN. + // An f32 can represent `i16::min_value() - 1` exactly with precision to spare, so + // there are values less than -2^(N-1) that convert correctly to INT_MIN. + { pos.ins().f32const(if output_bits < 32 { overflow_cc = FloatCC::LessThanOrEqual; Ieee32::fcvt_to_sint_negative_overflow(output_bits) } else { Ieee32::pow2(output_bits - 1).neg() - }), + }) + } ir::types::F64 => - // An f64 can represent `i32::min_value() - 1` exactly with precision to spare, so - // there are values less than -2^(N-1) that convert correctly to INT_MIN. + // An f64 can represent `i32::min_value() - 1` exactly with precision to spare, so + // there are values less than -2^(N-1) that convert correctly to INT_MIN. + { pos.ins().f64const(if output_bits < 64 { overflow_cc = FloatCC::LessThanOrEqual; Ieee64::fcvt_to_sint_negative_overflow(output_bits) } else { Ieee64::pow2(output_bits - 1).neg() - }), + }) + } _ => panic!("Can't convert {}", xty), }; let overflow = pos.ins().fcmp(overflow_cc, x, flimit); @@ -464,23 +468,27 @@ fn expand_fcvt_to_sint_sat( let output_bits = ty.lane_bits(); let flimit = match xty { ir::types::F32 => - // An f32 can represent `i16::min_value() - 1` exactly with precision to spare, so - // there are values less than -2^(N-1) that convert correctly to INT_MIN. + // An f32 can represent `i16::min_value() - 1` exactly with precision to spare, so + // there are values less than -2^(N-1) that convert correctly to INT_MIN. + { pos.ins().f32const(if output_bits < 32 { overflow_cc = FloatCC::LessThanOrEqual; Ieee32::fcvt_to_sint_negative_overflow(output_bits) } else { Ieee32::pow2(output_bits - 1).neg() - }), + }) + } ir::types::F64 => - // An f64 can represent `i32::min_value() - 1` exactly with precision to spare, so - // there are values less than -2^(N-1) that convert correctly to INT_MIN. + // An f64 can represent `i32::min_value() - 1` exactly with precision to spare, so + // there are values less than -2^(N-1) that convert correctly to INT_MIN. + { pos.ins().f64const(if output_bits < 64 { overflow_cc = FloatCC::LessThanOrEqual; Ieee64::fcvt_to_sint_negative_overflow(output_bits) } else { Ieee64::pow2(output_bits - 1).neg() - }), + }) + } _ => panic!("Can't convert {}", xty), }; diff --git a/lib/codegen/src/legalizer/heap.rs b/lib/codegen/src/legalizer/heap.rs index 44f434ff8a..143a01e234 100644 --- a/lib/codegen/src/legalizer/heap.rs +++ b/lib/codegen/src/legalizer/heap.rs @@ -65,8 +65,8 @@ fn dynamic_addr( .ins() .icmp(IntCC::UnsignedGreaterThanOrEqual, offset, bound); } else if access_size <= min_size { - // We know that bound >= min_size, so here we can compare `offset > bound - access_size` without - // wrapping. + // We know that bound >= min_size, so here we can compare `offset > bound - access_size` + // without wrapping. let adj_bound = pos.ins().iadd_imm(bound, -access_size); oob = pos .ins() diff --git a/lib/codegen/src/regalloc/coalescing.rs b/lib/codegen/src/regalloc/coalescing.rs index c7db253767..053d7f7dee 100644 --- a/lib/codegen/src/regalloc/coalescing.rs +++ b/lib/codegen/src/regalloc/coalescing.rs @@ -876,8 +876,8 @@ struct VirtualCopies { // Filter for the currently active node iterator. // - // An ebb => (set_id, num) entry means that branches to `ebb` are active in `set_id` with branch - // argument number `num`. + // An ebb => (set_id, num) entry means that branches to `ebb` are active in `set_id` with + // branch argument number `num`. filter: FxHashMap, } diff --git a/lib/codegen/src/regalloc/liveness.rs b/lib/codegen/src/regalloc/liveness.rs index 6e71345b13..01f72d9adb 100644 --- a/lib/codegen/src/regalloc/liveness.rs +++ b/lib/codegen/src/regalloc/liveness.rs @@ -97,8 +97,8 @@ //! //! Cranelift uses a very similar data structures and algorithms to LLVM, with the important //! difference that live ranges are computed per SSA value instead of per virtual register, and the -//! uses in Cranelift IR refers to SSA values instead of virtual registers. This means that Cranelift -//! can skip the last step of reconstructing SSA form for the virtual register uses. +//! uses in Cranelift IR refers to SSA values instead of virtual registers. This means that +//! Cranelift can skip the last step of reconstructing SSA form for the virtual register uses. //! //! ## Fast Liveness Checking for SSA-Form Programs //! diff --git a/lib/frontend/src/lib.rs b/lib/frontend/src/lib.rs index 07a79f4357..aec18899cb 100644 --- a/lib/frontend/src/lib.rs +++ b/lib/frontend/src/lib.rs @@ -66,11 +66,11 @@ //! extern crate cranelift_frontend; //! //! use cranelift_codegen::entity::EntityRef; -//! use cranelift_codegen::ir::{ExternalName, Function, Signature, AbiParam, InstBuilder}; //! use cranelift_codegen::ir::types::*; +//! use cranelift_codegen::ir::{AbiParam, ExternalName, Function, InstBuilder, Signature}; //! use cranelift_codegen::settings::{self, CallConv}; -//! use cranelift_frontend::{FunctionBuilderContext, FunctionBuilder, Variable}; //! use cranelift_codegen::verifier::verify_function; +//! use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable}; //! //! fn main() { //! let mut sig = Signature::new(CallConv::SystemV); diff --git a/lib/reader/src/parser.rs b/lib/reader/src/parser.rs index 7959d0688a..ff155fc195 100644 --- a/lib/reader/src/parser.rs +++ b/lib/reader/src/parser.rs @@ -92,8 +92,8 @@ struct Context<'a> { /// Reference to the unique_isa for things like parsing target-specific instruction encoding /// information. This is only `Some` if exactly one set of `isa` directives were found in the - /// prologue (it is valid to have directives for multiple different targets, but in that case we - /// couldn't know which target the provided encodings are intended for) + /// prologue (it is valid to have directives for multiple different targets, but in that case + /// we couldn't know which target the provided encodings are intended for) unique_isa: Option<&'a TargetIsa>, } diff --git a/lib/serde/README.md b/lib/serde/README.md index 89b54cca72..081573e413 100644 --- a/lib/serde/README.md +++ b/lib/serde/README.md @@ -1,19 +1,21 @@ This crate performs serialization of the [Cranelift](https://crates.io/crates/cranelift) IR. -This crate is structured as an optional ability to serialize and deserialize cranelift IR into JSON format. +This crate is structured as an optional ability to serialize and deserialize cranelift IR into JSON +format. Status ------ Cranelift IR can be serialized into JSON. -Deserialize is a work in progress, as it currently deserializes into the serializable data structure that can be utilized by serde instead of the actual Cranelift IR data structure. +Deserialize is a work in progress, as it currently deserializes into the serializable data structure +that can be utilized by serde instead of the actual Cranelift IR data structure. Building and Using Cranelift Serde ---------------------------------- -clif-json usage: +clif-json usage: clif-json serialize [-p] clif-json deserialize diff --git a/lib/serde/src/serde_clif_json.rs b/lib/serde/src/serde_clif_json.rs index 2cc6c006c8..c113f8622b 100644 --- a/lib/serde/src/serde_clif_json.rs +++ b/lib/serde/src/serde_clif_json.rs @@ -721,7 +721,8 @@ pub struct SerDataFlowGraph { ebbs: Vec, } -/// Serialize all parts of the Cranelift Ebb data structure, this includes name, parameters, and instructions. +/// Serialize all parts of the Cranelift Ebb data structure, this includes name, parameters, and +/// instructions. pub fn populate_ebbs(func: &Function) -> Vec { let mut ebb_vec: Vec = Vec::new(); for ebb in func.layout.ebbs() { @@ -785,7 +786,8 @@ pub struct SerFunction { } impl SerFunction { - /// Creates serializable global values, as well as the functions signature, name, and data flow graph. + /// Creates serializable global values, as well as the functions signature, name, and data flow + /// graph. fn create_new(func: &Function) -> Self { let mut global_vec: Vec = Vec::new(); for (glob_name, _) in func.global_values.iter() { @@ -804,8 +806,8 @@ impl SerFunction { } } -/// Must have SerObj for deserialization, contains all of the functions from inside the file to be serialized. -/// Files have one SerObj each, with all SerFunctions contained inside that SerObj. +/// Must have SerObj for deserialization, contains all of the functions from inside the file to be +/// serialized. Files have one SerObj each, with all SerFunctions contained inside that SerObj. #[derive(Serialize, Deserialize, Debug)] pub struct SerObj { pub functions: Vec, diff --git a/lib/wasm/src/state.rs b/lib/wasm/src/state.rs index 9b32fe3bbd..88374be17f 100644 --- a/lib/wasm/src/state.rs +++ b/lib/wasm/src/state.rs @@ -277,8 +277,8 @@ impl TranslationState { /// Methods for handling entity references. impl TranslationState { - /// Get the `GlobalVariable` reference that should be used to access the global variable `index`. - /// Create the reference if necessary. + /// Get the `GlobalVariable` reference that should be used to access the global variable + /// `index`. Create the reference if necessary. /// Also return the WebAssembly type of the global. pub fn get_global( &mut self,