Autoformat files with cargo fmt

This commit is contained in:
Syrus Akbary
2018-11-15 13:31:37 -08:00
parent bb9c9f7d0a
commit 1faaad7f72
10 changed files with 47 additions and 44 deletions

View File

@ -207,8 +207,7 @@ fn test_module_{}() {{
module, module,
module, module,
calls.join("\n ") calls.join("\n ")
) ).as_str(),
.as_str(),
); );
} }
self.module_calls.remove(&module); self.module_calls.remove(&module);
@ -234,8 +233,7 @@ fn test_module_{}() {{
.replace("\n", "\n ") .replace("\n", "\n ")
.replace("\\", "\\\\") .replace("\\", "\\\\")
.replace("\"", "\\\""), .replace("\"", "\\\""),
) ).as_str(),
.as_str(),
); );
// We set the start call to the module // We set the start call to the module
@ -246,8 +244,7 @@ fn test_module_{}() {{
result_object.instance.start(); result_object.instance.start();
}}\n", }}\n",
start_module_call start_module_call
) ).as_str(),
.as_str(),
); );
self.module_calls self.module_calls
.entry(self.last_module) .entry(self.last_module)
@ -272,8 +269,7 @@ fn {}_assert_invalid() {{
// We do this to ident four spaces back // We do this to ident four spaces back
// String::from_utf8_lossy(&wasm_binary), // String::from_utf8_lossy(&wasm_binary),
// wast_string.replace("\n", "\n "), // wast_string.replace("\n", "\n "),
) ).as_str(),
.as_str(),
); );
} }
@ -315,8 +311,7 @@ fn {}_assert_invalid() {{
func_return, func_return,
args_values.join(", "), args_values.join(", "),
assertion, assertion,
) ).as_str(),
.as_str(),
); );
self.module_calls self.module_calls
.entry(self.last_module) .entry(self.last_module)
@ -373,8 +368,7 @@ fn {}_assert_invalid() {{
func_return, func_return,
args_values.join(", "), args_values.join(", "),
assertion, assertion,
) ).as_str(),
.as_str(),
); );
self.module_calls self.module_calls
.entry(self.last_module) .entry(self.last_module)
@ -404,8 +398,7 @@ fn {}_assert_malformed() {{
// We do this to ident four spaces back // We do this to ident four spaces back
// String::from_utf8_lossy(&wasm_binary), // String::from_utf8_lossy(&wasm_binary),
// wast_string.replace("\n", "\n "), // wast_string.replace("\n", "\n "),
) ).as_str(),
.as_str(),
); );
} }
@ -469,8 +462,7 @@ fn {}_assert_malformed() {{
func_return, func_return,
args_values.join(", "), args_values.join(", "),
assertion, assertion,
) ).as_str(),
.as_str(),
); );
Some(func_name) Some(func_name)
// let mut module_calls = self.module_calls.get(&self.last_module).unwrap(); // let mut module_calls = self.module_calls.get(&self.last_module).unwrap();
@ -491,7 +483,7 @@ fn {}_assert_malformed() {{
.or_insert(Vec::new()) .or_insert(Vec::new())
.push(action_fn_name.unwrap()); .push(action_fn_name.unwrap());
} }
fn visit_perform_action(&mut self, action: &Action) { fn visit_perform_action(&mut self, action: &Action) {
let action_fn_name = self.visit_action(action, None); let action_fn_name = self.visit_action(action, None);
@ -525,8 +517,7 @@ fn {}() {{
trap_func_name, trap_func_name,
self.last_module, self.last_module,
action_fn_name.unwrap(), action_fn_name.unwrap(),
) ).as_str(),
.as_str(),
); );
// We don't group trap calls as they may cause memory faults // We don't group trap calls as they may cause memory faults

View File

@ -1,9 +1,7 @@
use crate::webassembly::Instance; use crate::webassembly::Instance;
use std::process; use std::process;
pub extern "C" fn abort(_code: i32, _instance: &Instance) { pub extern "C" fn abort(_code: i32, _instance: &Instance) {
process::abort(); process::abort();
// abort!("Aborted") // abort!("Aborted")
} }

View File

@ -1,8 +1,8 @@
use crate::webassembly::ImportObject; use crate::webassembly::ImportObject;
mod abort;
mod printf; mod printf;
mod putchar; mod putchar;
mod abort;
pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> { pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
let mut import_object = ImportObject::new(); let mut import_object = ImportObject::new();

View File

@ -1,4 +1,3 @@
pub mod emscripten; pub mod emscripten;
pub use self::emscripten::generate_emscripten_env; pub use self::emscripten::generate_emscripten_env;

View File

@ -1,15 +1,15 @@
#[macro_use] #[macro_use]
extern crate error_chain; extern crate error_chain;
extern crate libc;
extern crate cranelift_codegen; extern crate cranelift_codegen;
extern crate cranelift_entity; extern crate cranelift_entity;
extern crate cranelift_native; extern crate cranelift_native;
extern crate cranelift_wasm; extern crate cranelift_wasm;
extern crate libc;
extern crate memmap;
extern crate region;
extern crate structopt; extern crate structopt;
extern crate wabt; extern crate wabt;
extern crate wasmparser; extern crate wasmparser;
extern crate memmap;
extern crate region;
#[macro_use] #[macro_use]
extern crate target_lexicon; extern crate target_lexicon;
extern crate nix; extern crate nix;
@ -68,10 +68,16 @@ fn read_file_contents(path: &PathBuf) -> Result<Vec<u8>, io::Error> {
/// Execute a WASM/WAT file /// Execute a WASM/WAT file
fn execute_wasm(wasm_path: PathBuf) -> Result<(), String> { fn execute_wasm(wasm_path: PathBuf) -> Result<(), String> {
let mut wasm_binary: Vec<u8> = let mut wasm_binary: Vec<u8> = read_file_contents(&wasm_path).map_err(|err| {
read_file_contents(&wasm_path).map_err(|err| format!("Can't read the file {}: {}", wasm_path.as_os_str().to_string_lossy(), err))?; format!(
"Can't read the file {}: {}",
wasm_path.as_os_str().to_string_lossy(),
err
)
})?;
if !webassembly::utils::is_wasm_binary(&wasm_binary) { if !webassembly::utils::is_wasm_binary(&wasm_binary) {
wasm_binary = wabt::wat2wasm(wasm_binary).map_err(|err| format!("Can't convert from wast to wasm: {:?}", err))?; wasm_binary = wabt::wat2wasm(wasm_binary)
.map_err(|err| format!("Can't convert from wast to wasm: {:?}", err))?;
} }
let import_object = linkers::generate_emscripten_env(); let import_object = linkers::generate_emscripten_env();

View File

@ -5,7 +5,7 @@
//! Please read more about this here: https://github.com/CraneStation/wasmtime/issues/15 //! Please read more about this here: https://github.com/CraneStation/wasmtime/issues/15
//! This code is inspired by: https://github.com/pepyakin/wasmtime/commit/625a2b6c0815b21996e111da51b9664feb174622 //! This code is inspired by: https://github.com/pepyakin/wasmtime/commit/625a2b6c0815b21996e111da51b9664feb174622
use nix::sys::signal::{ use nix::sys::signal::{
sigaction, Signal, SaFlags, SigAction, SigHandler, SigSet, SIGBUS, SIGFPE, SIGILL, SIGSEGV, sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal, SIGBUS, SIGFPE, SIGILL, SIGSEGV,
}; };
static mut SETJMP_BUFFER: [::nix::libc::c_int; 27] = [0; 27]; static mut SETJMP_BUFFER: [::nix::libc::c_int; 27] = [0; 27];

View File

@ -131,7 +131,7 @@ pub struct InstanceOptions {
pub mock_missing_imports: bool, pub mock_missing_imports: bool,
} }
extern fn mock_fn() -> i32 { extern "C" fn mock_fn() -> i32 {
return 0; return 0;
} }
@ -167,15 +167,16 @@ impl Instance {
// We walk through the imported functions and set the relocations // We walk through the imported functions and set the relocations
// for each of this functions to be an empty vector (as is defined outside of wasm) // for each of this functions to be an empty vector (as is defined outside of wasm)
for (module, field) in module.info.imported_funcs.iter() { for (module, field) in module.info.imported_funcs.iter() {
let function = import_object let function = import_object.get(&module.as_str(), &field.as_str());
.get(&module.as_str(), &field.as_str());
let function = if options.mock_missing_imports { let function = if options.mock_missing_imports {
function.unwrap_or_else(|| { function.unwrap_or_else(|| {
debug!("The import {}.{} is not provided, therefore will be mocked.", module, field); debug!(
"The import {}.{} is not provided, therefore will be mocked.",
module, field
);
mock_fn as *const u8 mock_fn as *const u8
}) })
} } else {
else {
function.ok_or_else(|| { function.ok_or_else(|| {
ErrorKind::LinkError(format!( ErrorKind::LinkError(format!(
"Imported function {}.{} was not provided in the import_functions", "Imported function {}.{} was not provided in the import_functions",

View File

@ -108,7 +108,7 @@ impl LinearMemory {
// Copy old mem to new mem. Will a while loop be faster or is this going to be optimized? // Copy old mem to new mem. Will a while loop be faster or is this going to be optimized?
// TODO: Consider static heap for efficiency. // TODO: Consider static heap for efficiency.
for i in 0..prev_bytes { for i in 0..prev_bytes {
unsafe { unsafe {
let new_mmap_index = new_mmap.get_unchecked_mut(i); let new_mmap_index = new_mmap.get_unchecked_mut(i);
let old_mmap_index = self.mmap.get_unchecked(i); let old_mmap_index = self.mmap.get_unchecked(i);
*new_mmap_index = *old_mmap_index; *new_mmap_index = *old_mmap_index;

View File

@ -47,7 +47,13 @@ pub fn instantiate(
) -> Result<ResultObject, ErrorKind> { ) -> Result<ResultObject, ErrorKind> {
let module = compile(buffer_source)?; let module = compile(buffer_source)?;
debug!("webassembly - creating instance"); debug!("webassembly - creating instance");
let instance = Instance::new(&module, &import_object, InstanceOptions { mock_missing_imports: true })?; let instance = Instance::new(
&module,
&import_object,
InstanceOptions {
mock_missing_imports: true,
},
)?;
debug!("webassembly - instance created"); debug!("webassembly - instance created");
Ok(ResultObject { module, instance }) Ok(ResultObject { module, instance })
} }
@ -100,7 +106,12 @@ pub fn validate_or_error(bytes: &[u8]) -> Result<(), ErrorKind> {
let state = parser.read(); let state = parser.read();
match *state { match *state {
wasmparser::ParserState::EndWasm => return Ok(()), wasmparser::ParserState::EndWasm => return Ok(()),
wasmparser::ParserState::Error(err) => return Err(ErrorKind::CompileError(format!("Validation error: {}", err.message))), wasmparser::ParserState::Error(err) => {
return Err(ErrorKind::CompileError(format!(
"Validation error: {}",
err.message
)))
}
_ => (), _ => (),
} }
} }

View File

@ -427,9 +427,7 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
base: heap_base, base: heap_base,
min_size: Imm64::new(0), min_size: Imm64::new(0),
guard_size: Imm64::new(LinearMemory::DEFAULT_GUARD_SIZE as i64), guard_size: Imm64::new(LinearMemory::DEFAULT_GUARD_SIZE as i64),
style: ir::HeapStyle::Dynamic { style: ir::HeapStyle::Dynamic { bound_gv },
bound_gv,
},
index_type: I32, index_type: I32,
}) })
@ -535,7 +533,6 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
.special_param(ir::ArgumentPurpose::VMContext) .special_param(ir::ArgumentPurpose::VMContext)
.expect("Missing vmctx parameter"); .expect("Missing vmctx parameter");
// The `callee` value is an index into a table of function pointers. // The `callee` value is an index into a table of function pointers.
// Apparently, that table is stored at absolute address 0 in this dummy environment. // Apparently, that table is stored at absolute address 0 in this dummy environment.
// TODO: Generate bounds checking code. // TODO: Generate bounds checking code.