Improved formatting

This commit is contained in:
Syrus Akbary
2018-10-24 02:01:46 +02:00
parent 48f7c46020
commit e9a968b4b0
4 changed files with 27 additions and 30 deletions

View File

@ -51,10 +51,9 @@ fn wabt2rust_type(v: &Value) -> String {
} }
fn is_nan(v: &Value) -> bool { fn is_nan(v: &Value) -> bool {
if let Value::F32(v) = v { if let Value::F32(v) = v {
return v.is_nan(); return v.is_nan();
} } else if let Value::F64(v) = v {
else if let Value::F64(v) = v {
return v.is_nan(); return v.is_nan();
} }
return false; return false;
@ -65,7 +64,6 @@ fn wabt2rust_value(v: &Value) -> String {
Value::I32(v) => format!("{:?} as i32", v), Value::I32(v) => format!("{:?} as i32", v),
Value::I64(v) => format!("{:?} as i64", v), Value::I64(v) => format!("{:?} as i64", v),
Value::F32(v) => { Value::F32(v) => {
match *v { match *v {
std::f32::INFINITY => "std::f32::INFINITY".to_string(), std::f32::INFINITY => "std::f32::INFINITY".to_string(),
std::f32::NEG_INFINITY => "std::f32::NEG_INFINITY".to_string(), std::f32::NEG_INFINITY => "std::f32::NEG_INFINITY".to_string(),
@ -74,17 +72,15 @@ fn wabt2rust_value(v: &Value) -> String {
if v.is_nan() { if v.is_nan() {
if v.is_sign_negative() { if v.is_sign_negative() {
"-std::f32::NAN".to_string() "-std::f32::NAN".to_string()
} } else {
else {
"std::f32::NAN".to_string() "std::f32::NAN".to_string()
} }
} } else {
else {
format!("{:?} as f32", v) format!("{:?} as f32", v)
} }
} }
} }
}, }
Value::F64(v) => { Value::F64(v) => {
match *v { match *v {
std::f64::INFINITY => "std::f64::INFINITY".to_string(), std::f64::INFINITY => "std::f64::INFINITY".to_string(),
@ -94,12 +90,10 @@ fn wabt2rust_value(v: &Value) -> String {
if v.is_nan() { if v.is_nan() {
if v.is_sign_negative() { if v.is_sign_negative() {
"-std::f64::NAN".to_string() "-std::f64::NAN".to_string()
} } else {
else {
"std::f64::NAN".to_string() "std::f64::NAN".to_string()
} }
} } else {
else {
format!("{:?} as f64", v) format!("{:?} as f64", v)
} }
} }
@ -264,10 +258,12 @@ fn l{}_assert_malformed() {{
"()".to_string() "()".to_string()
}; };
let assertion = if expected.len() > 0 && is_nan(&expected[0]) { let assertion = if expected.len() > 0 && is_nan(&expected[0]) {
format!("assert!(result.is_nan()); format!(
assert_eq!(result.is_sign_positive(), ({}).is_sign_positive());", expected_result) "assert!(result.is_nan());
} assert_eq!(result.is_sign_positive(), ({}).is_sign_positive());",
else { expected_result
)
} else {
format!("assert_eq!(result, {});", expected_result) format!("assert_eq!(result, {});", expected_result)
}; };
// We map the arguments provided into the raw Arguments provided // We map the arguments provided into the raw Arguments provided

View File

@ -37,9 +37,9 @@ use wabt::wat2wasm;
mod macros; mod macros;
pub mod common; pub mod common;
pub mod integrations; pub mod integrations;
pub mod webassembly;
#[cfg(test)] #[cfg(test)]
mod spectests; mod spectests;
pub mod webassembly;
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
#[structopt(name = "wasmer", about = "WASM execution runtime.")] #[structopt(name = "wasmer", about = "WASM execution runtime.")]

View File

@ -6,10 +6,10 @@
//! synchronously instantiate a given webassembly::Module object. However, the //! synchronously instantiate a given webassembly::Module object. However, the
//! primary way to get an Instance is through the asynchronous //! primary way to get an Instance is through the asynchronous
//! webassembly::instantiateStreaming() function. //! webassembly::instantiateStreaming() function.
use cranelift_codegen::ir::LibCall;
use cranelift_codegen::{binemit, isa, Context}; use cranelift_codegen::{binemit, isa, Context};
use cranelift_entity::EntityRef; use cranelift_entity::EntityRef;
use cranelift_wasm::{FuncIndex, GlobalInit}; use cranelift_wasm::{FuncIndex, GlobalInit};
use cranelift_codegen::ir::LibCall;
use memmap::MmapMut; use memmap::MmapMut;
use region; use region;
use spin::RwLock; use spin::RwLock;
@ -657,42 +657,43 @@ extern "C" fn current_memory(memory_index: u32, vmctx: &VmCtx) -> u32 {
// } // }
} }
// Because of this bug https://github.com/rust-lang/rust/issues/34123 // Because of this bug https://github.com/rust-lang/rust/issues/34123
// We create internal functions for it // We create internal functions for it
use std::intrinsics::{ceilf32, floorf32, truncf32, nearbyintf32, ceilf64, floorf64, truncf64, nearbyintf64}; use std::intrinsics::{
ceilf32, ceilf64, floorf32, floorf64, nearbyintf32, nearbyintf64, truncf32, truncf64,
};
// F32 // F32
unsafe extern fn _ceilf32(x: f32) -> f32 { unsafe extern "C" fn _ceilf32(x: f32) -> f32 {
ceilf32(x) ceilf32(x)
} }
unsafe extern fn _floorf32(x: f32) -> f32 { unsafe extern "C" fn _floorf32(x: f32) -> f32 {
floorf32(x) floorf32(x)
} }
unsafe extern fn _truncf32(x: f32) -> f32 { unsafe extern "C" fn _truncf32(x: f32) -> f32 {
truncf32(x) truncf32(x)
} }
unsafe extern fn _nearbyintf32(x: f32) -> f32 { unsafe extern "C" fn _nearbyintf32(x: f32) -> f32 {
nearbyintf32(x) nearbyintf32(x)
} }
// F64 // F64
unsafe extern fn _ceilf64(x: f64) -> f64 { unsafe extern "C" fn _ceilf64(x: f64) -> f64 {
ceilf64(x) ceilf64(x)
} }
unsafe extern fn _floorf64(x: f64) -> f64 { unsafe extern "C" fn _floorf64(x: f64) -> f64 {
floorf64(x) floorf64(x)
} }
unsafe extern fn _truncf64(x: f64) -> f64 { unsafe extern "C" fn _truncf64(x: f64) -> f64 {
truncf64(x) truncf64(x)
} }
unsafe extern fn _nearbyintf64(x: f64) -> f64 { unsafe extern "C" fn _nearbyintf64(x: f64) -> f64 {
nearbyintf64(x) nearbyintf64(x)
} }

View File

@ -3,7 +3,7 @@
//! any other calls that this function is doing, so we can "patch" the //! any other calls that this function is doing, so we can "patch" the
//! function addrs in runtime with the functions we need. //! function addrs in runtime with the functions we need.
use cranelift_codegen::binemit; use cranelift_codegen::binemit;
use cranelift_codegen::ir::{self, ExternalName, SourceLoc, TrapCode, LibCall}; use cranelift_codegen::ir::{self, ExternalName, LibCall, SourceLoc, TrapCode};
pub use cranelift_codegen::binemit::Reloc; pub use cranelift_codegen::binemit::Reloc;
use cranelift_wasm::FuncIndex; use cranelift_wasm::FuncIndex;