Fix rustfmt errors.

This commit is contained in:
Dan Gohman
2018-08-14 22:03:07 -07:00
parent e2badb0ad6
commit 3d89a8645b
14 changed files with 66 additions and 46 deletions

View File

@@ -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);
});

View File

@@ -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));

View File

@@ -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.

View File

@@ -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;
//!

View File

@@ -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;

View File

@@ -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),
};

View File

@@ -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()

View File

@@ -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<Ebb, (u8, usize)>,
}

View File

@@ -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
//!

View File

@@ -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);

View File

@@ -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>,
}

View File

@@ -1,13 +1,15 @@
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

View File

@@ -721,7 +721,8 @@ pub struct SerDataFlowGraph {
ebbs: Vec<SerEbb>,
}
/// 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<SerEbb> {
let mut ebb_vec: Vec<SerEbb> = 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<String> = 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<SerFunction>,

View File

@@ -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<FE: FuncEnvironment + ?Sized>(
&mut self,