Fix rustfmt errors.
This commit is contained in:
@@ -4,8 +4,6 @@ extern crate libfuzzer_sys;
|
|||||||
extern crate cranelift_reader;
|
extern crate cranelift_reader;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
fuzz_target!(|data: &[u8]| if let Ok(s) = str::from_utf8(data) {
|
||||||
if let Ok(s) = str::from_utf8(data) {
|
|
||||||
let _ = cranelift_reader::parse_test(s);
|
let _ = cranelift_reader::parse_test(s);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
//! Reads Wasm binary files, translates the functions' code to Cranelift IR.
|
//! Reads Wasm binary files, translates the functions' code to Cranelift IR.
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments, cyclomatic_complexity))]
|
#![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::print_errors::{pretty_error, pretty_verifier_error};
|
||||||
use cranelift_codegen::settings::FlagsOrIsa;
|
use cranelift_codegen::settings::FlagsOrIsa;
|
||||||
|
use cranelift_codegen::Context;
|
||||||
use cranelift_entity::EntityRef;
|
use cranelift_entity::EntityRef;
|
||||||
use cranelift_wasm::{translate_module, DummyEnvironment, FuncIndex, ModuleEnvironment};
|
use cranelift_wasm::{translate_module, DummyEnvironment, FuncIndex, ModuleEnvironment};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
@@ -80,7 +80,8 @@ fn handle_module(
|
|||||||
vprint!(flag_verbose, "Translating... ");
|
vprint!(flag_verbose, "Translating... ");
|
||||||
terminal.reset().unwrap();
|
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']) {
|
if !module_binary.starts_with(&[b'\0', b'a', b's', b'm']) {
|
||||||
module_binary = match wat2wasm(&module_binary) {
|
module_binary = match wat2wasm(&module_binary) {
|
||||||
@@ -91,7 +92,11 @@ fn handle_module(
|
|||||||
|
|
||||||
let isa = match fisa.isa {
|
let isa = match fisa.isa {
|
||||||
Some(isa) => 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 =
|
let mut dummy_environ =
|
||||||
@@ -118,7 +123,9 @@ fn handle_module(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
vprintln!(flag_verbose, "");
|
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!("; Exported as \"{}\"", export_name);
|
||||||
}
|
}
|
||||||
println!("{}", context.func.display(None));
|
println!("{}", context.func.display(None));
|
||||||
@@ -163,7 +170,8 @@ fn handle_module(
|
|||||||
total_module_code_size += compiled_size;
|
total_module_code_size += compiled_size;
|
||||||
println!(
|
println!(
|
||||||
"Function #{} bytecode size: {} bytes",
|
"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");
|
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!("; Exported as \"{}\"", export_name);
|
||||||
}
|
}
|
||||||
println!("{}", context.func.display(fisa.isa));
|
println!("{}", context.func.display(fisa.isa));
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//! Runtime support for precomputed constant hash tables.
|
//! Runtime support for precomputed constant hash tables.
|
||||||
//!
|
//!
|
||||||
//! The `lib/codegen/meta-python/constant_hash.py` Python module can generate constant hash tables using
|
//! The `lib/codegen/meta-python/constant_hash.py` Python module can generate constant hash tables
|
||||||
//! open addressing and quadratic probing. The hash tables are arrays that are guaranteed to:
|
//! using open addressing and quadratic probing. The hash tables are arrays that are guaranteed to:
|
||||||
//!
|
//!
|
||||||
//! - Have a power-of-two size.
|
//! - Have a power-of-two size.
|
||||||
//! - Contain at least one empty slot.
|
//! - Contain at least one empty slot.
|
||||||
|
|||||||
@@ -23,8 +23,8 @@
|
|||||||
//! # extern crate cranelift_codegen;
|
//! # extern crate cranelift_codegen;
|
||||||
//! # #[macro_use] extern crate target_lexicon;
|
//! # #[macro_use] extern crate target_lexicon;
|
||||||
//! # fn main() {
|
//! # fn main() {
|
||||||
//! use cranelift_codegen::settings::{self, Configurable};
|
|
||||||
//! use cranelift_codegen::isa;
|
//! use cranelift_codegen::isa;
|
||||||
|
//! use cranelift_codegen::settings::{self, Configurable};
|
||||||
//! use std::str::FromStr;
|
//! use std::str::FromStr;
|
||||||
//! use target_lexicon::Triple;
|
//! use target_lexicon::Triple;
|
||||||
//!
|
//!
|
||||||
|
|||||||
@@ -433,8 +433,8 @@ fn insert_common_prologue(
|
|||||||
if let Some(stack_limit_arg) = pos.func.special_param(ArgumentPurpose::StackLimit) {
|
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
|
// Total stack size is the size of all stack area used by the function, including
|
||||||
// pushed CSRs, frame pointer.
|
// pushed CSRs, frame pointer.
|
||||||
// Also, the size of a return address, implicitly pushed by a x86 `call` instruction, also
|
// Also, the size of a return address, implicitly pushed by a x86 `call` instruction,
|
||||||
// should be accounted for.
|
// also should be accounted for.
|
||||||
// TODO: Check if the function body actually contains a `call` instruction.
|
// TODO: Check if the function body actually contains a `call` instruction.
|
||||||
let word_size = isa.pointer_bytes();
|
let word_size = isa.pointer_bytes();
|
||||||
let total_stack_size = (csrs.iter(GPR).len() + 1 + 1) as i64 * word_size as i64;
|
let total_stack_size = (csrs.iter(GPR).len() + 1 + 1) as i64 * word_size as i64;
|
||||||
|
|||||||
@@ -369,21 +369,25 @@ fn expand_fcvt_to_sint(
|
|||||||
ir::types::F32 =>
|
ir::types::F32 =>
|
||||||
// An f32 can represent `i16::min_value() - 1` exactly with precision to spare, so
|
// 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.
|
// there are values less than -2^(N-1) that convert correctly to INT_MIN.
|
||||||
|
{
|
||||||
pos.ins().f32const(if output_bits < 32 {
|
pos.ins().f32const(if output_bits < 32 {
|
||||||
overflow_cc = FloatCC::LessThanOrEqual;
|
overflow_cc = FloatCC::LessThanOrEqual;
|
||||||
Ieee32::fcvt_to_sint_negative_overflow(output_bits)
|
Ieee32::fcvt_to_sint_negative_overflow(output_bits)
|
||||||
} else {
|
} else {
|
||||||
Ieee32::pow2(output_bits - 1).neg()
|
Ieee32::pow2(output_bits - 1).neg()
|
||||||
}),
|
})
|
||||||
|
}
|
||||||
ir::types::F64 =>
|
ir::types::F64 =>
|
||||||
// An f64 can represent `i32::min_value() - 1` exactly with precision to spare, so
|
// 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.
|
// there are values less than -2^(N-1) that convert correctly to INT_MIN.
|
||||||
|
{
|
||||||
pos.ins().f64const(if output_bits < 64 {
|
pos.ins().f64const(if output_bits < 64 {
|
||||||
overflow_cc = FloatCC::LessThanOrEqual;
|
overflow_cc = FloatCC::LessThanOrEqual;
|
||||||
Ieee64::fcvt_to_sint_negative_overflow(output_bits)
|
Ieee64::fcvt_to_sint_negative_overflow(output_bits)
|
||||||
} else {
|
} else {
|
||||||
Ieee64::pow2(output_bits - 1).neg()
|
Ieee64::pow2(output_bits - 1).neg()
|
||||||
}),
|
})
|
||||||
|
}
|
||||||
_ => panic!("Can't convert {}", xty),
|
_ => panic!("Can't convert {}", xty),
|
||||||
};
|
};
|
||||||
let overflow = pos.ins().fcmp(overflow_cc, x, flimit);
|
let overflow = pos.ins().fcmp(overflow_cc, x, flimit);
|
||||||
@@ -466,21 +470,25 @@ fn expand_fcvt_to_sint_sat(
|
|||||||
ir::types::F32 =>
|
ir::types::F32 =>
|
||||||
// An f32 can represent `i16::min_value() - 1` exactly with precision to spare, so
|
// 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.
|
// there are values less than -2^(N-1) that convert correctly to INT_MIN.
|
||||||
|
{
|
||||||
pos.ins().f32const(if output_bits < 32 {
|
pos.ins().f32const(if output_bits < 32 {
|
||||||
overflow_cc = FloatCC::LessThanOrEqual;
|
overflow_cc = FloatCC::LessThanOrEqual;
|
||||||
Ieee32::fcvt_to_sint_negative_overflow(output_bits)
|
Ieee32::fcvt_to_sint_negative_overflow(output_bits)
|
||||||
} else {
|
} else {
|
||||||
Ieee32::pow2(output_bits - 1).neg()
|
Ieee32::pow2(output_bits - 1).neg()
|
||||||
}),
|
})
|
||||||
|
}
|
||||||
ir::types::F64 =>
|
ir::types::F64 =>
|
||||||
// An f64 can represent `i32::min_value() - 1` exactly with precision to spare, so
|
// 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.
|
// there are values less than -2^(N-1) that convert correctly to INT_MIN.
|
||||||
|
{
|
||||||
pos.ins().f64const(if output_bits < 64 {
|
pos.ins().f64const(if output_bits < 64 {
|
||||||
overflow_cc = FloatCC::LessThanOrEqual;
|
overflow_cc = FloatCC::LessThanOrEqual;
|
||||||
Ieee64::fcvt_to_sint_negative_overflow(output_bits)
|
Ieee64::fcvt_to_sint_negative_overflow(output_bits)
|
||||||
} else {
|
} else {
|
||||||
Ieee64::pow2(output_bits - 1).neg()
|
Ieee64::pow2(output_bits - 1).neg()
|
||||||
}),
|
})
|
||||||
|
}
|
||||||
_ => panic!("Can't convert {}", xty),
|
_ => panic!("Can't convert {}", xty),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ fn dynamic_addr(
|
|||||||
.ins()
|
.ins()
|
||||||
.icmp(IntCC::UnsignedGreaterThanOrEqual, offset, bound);
|
.icmp(IntCC::UnsignedGreaterThanOrEqual, offset, bound);
|
||||||
} else if access_size <= min_size {
|
} else if access_size <= min_size {
|
||||||
// We know that bound >= min_size, so here we can compare `offset > bound - access_size` without
|
// We know that bound >= min_size, so here we can compare `offset > bound - access_size`
|
||||||
// wrapping.
|
// without wrapping.
|
||||||
let adj_bound = pos.ins().iadd_imm(bound, -access_size);
|
let adj_bound = pos.ins().iadd_imm(bound, -access_size);
|
||||||
oob = pos
|
oob = pos
|
||||||
.ins()
|
.ins()
|
||||||
|
|||||||
@@ -876,8 +876,8 @@ struct VirtualCopies {
|
|||||||
|
|
||||||
// Filter for the currently active node iterator.
|
// 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
|
// An ebb => (set_id, num) entry means that branches to `ebb` are active in `set_id` with
|
||||||
// argument number `num`.
|
// branch argument number `num`.
|
||||||
filter: FxHashMap<Ebb, (u8, usize)>,
|
filter: FxHashMap<Ebb, (u8, usize)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,8 +97,8 @@
|
|||||||
//!
|
//!
|
||||||
//! Cranelift uses a very similar data structures and algorithms to LLVM, with the important
|
//! 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
|
//! 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
|
//! uses in Cranelift IR refers to SSA values instead of virtual registers. This means that
|
||||||
//! can skip the last step of reconstructing SSA form for the virtual register uses.
|
//! Cranelift can skip the last step of reconstructing SSA form for the virtual register uses.
|
||||||
//!
|
//!
|
||||||
//! ## Fast Liveness Checking for SSA-Form Programs
|
//! ## Fast Liveness Checking for SSA-Form Programs
|
||||||
//!
|
//!
|
||||||
|
|||||||
@@ -66,11 +66,11 @@
|
|||||||
//! extern crate cranelift_frontend;
|
//! extern crate cranelift_frontend;
|
||||||
//!
|
//!
|
||||||
//! use cranelift_codegen::entity::EntityRef;
|
//! use cranelift_codegen::entity::EntityRef;
|
||||||
//! use cranelift_codegen::ir::{ExternalName, Function, Signature, AbiParam, InstBuilder};
|
|
||||||
//! use cranelift_codegen::ir::types::*;
|
//! use cranelift_codegen::ir::types::*;
|
||||||
|
//! use cranelift_codegen::ir::{AbiParam, ExternalName, Function, InstBuilder, Signature};
|
||||||
//! use cranelift_codegen::settings::{self, CallConv};
|
//! use cranelift_codegen::settings::{self, CallConv};
|
||||||
//! use cranelift_frontend::{FunctionBuilderContext, FunctionBuilder, Variable};
|
|
||||||
//! use cranelift_codegen::verifier::verify_function;
|
//! use cranelift_codegen::verifier::verify_function;
|
||||||
|
//! use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
|
||||||
//!
|
//!
|
||||||
//! fn main() {
|
//! fn main() {
|
||||||
//! let mut sig = Signature::new(CallConv::SystemV);
|
//! let mut sig = Signature::new(CallConv::SystemV);
|
||||||
|
|||||||
@@ -92,8 +92,8 @@ struct Context<'a> {
|
|||||||
|
|
||||||
/// Reference to the unique_isa for things like parsing target-specific instruction encoding
|
/// 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
|
/// 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
|
/// prologue (it is valid to have directives for multiple different targets, but in that case
|
||||||
/// couldn't know which target the provided encodings are intended for)
|
/// we couldn't know which target the provided encodings are intended for)
|
||||||
unique_isa: Option<&'a TargetIsa>,
|
unique_isa: Option<&'a TargetIsa>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
This crate performs serialization of the [Cranelift](https://crates.io/crates/cranelift) IR.
|
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
|
Status
|
||||||
------
|
------
|
||||||
|
|
||||||
Cranelift IR can be serialized into JSON.
|
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
|
Building and Using Cranelift Serde
|
||||||
|
|||||||
@@ -721,7 +721,8 @@ pub struct SerDataFlowGraph {
|
|||||||
ebbs: Vec<SerEbb>,
|
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> {
|
pub fn populate_ebbs(func: &Function) -> Vec<SerEbb> {
|
||||||
let mut ebb_vec: Vec<SerEbb> = Vec::new();
|
let mut ebb_vec: Vec<SerEbb> = Vec::new();
|
||||||
for ebb in func.layout.ebbs() {
|
for ebb in func.layout.ebbs() {
|
||||||
@@ -785,7 +786,8 @@ pub struct SerFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
fn create_new(func: &Function) -> Self {
|
||||||
let mut global_vec: Vec<String> = Vec::new();
|
let mut global_vec: Vec<String> = Vec::new();
|
||||||
for (glob_name, _) in func.global_values.iter() {
|
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.
|
/// Must have SerObj for deserialization, contains all of the functions from inside the file to be
|
||||||
/// Files have one SerObj each, with all SerFunctions contained inside that SerObj.
|
/// serialized. Files have one SerObj each, with all SerFunctions contained inside that SerObj.
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct SerObj {
|
pub struct SerObj {
|
||||||
pub functions: Vec<SerFunction>,
|
pub functions: Vec<SerFunction>,
|
||||||
|
|||||||
@@ -277,8 +277,8 @@ impl TranslationState {
|
|||||||
|
|
||||||
/// Methods for handling entity references.
|
/// Methods for handling entity references.
|
||||||
impl TranslationState {
|
impl TranslationState {
|
||||||
/// Get the `GlobalVariable` reference that should be used to access the global variable `index`.
|
/// Get the `GlobalVariable` reference that should be used to access the global variable
|
||||||
/// Create the reference if necessary.
|
/// `index`. Create the reference if necessary.
|
||||||
/// Also return the WebAssembly type of the global.
|
/// Also return the WebAssembly type of the global.
|
||||||
pub fn get_global<FE: FuncEnvironment + ?Sized>(
|
pub fn get_global<FE: FuncEnvironment + ?Sized>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|||||||
Reference in New Issue
Block a user