mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
Autoformat files with cargo fmt
This commit is contained in:
parent
bb9c9f7d0a
commit
1faaad7f72
@ -207,8 +207,7 @@ fn test_module_{}() {{
|
||||
module,
|
||||
module,
|
||||
calls.join("\n ")
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
}
|
||||
self.module_calls.remove(&module);
|
||||
@ -234,8 +233,7 @@ fn test_module_{}() {{
|
||||
.replace("\n", "\n ")
|
||||
.replace("\\", "\\\\")
|
||||
.replace("\"", "\\\""),
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
|
||||
// We set the start call to the module
|
||||
@ -246,8 +244,7 @@ fn test_module_{}() {{
|
||||
result_object.instance.start();
|
||||
}}\n",
|
||||
start_module_call
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
self.module_calls
|
||||
.entry(self.last_module)
|
||||
@ -272,8 +269,7 @@ fn {}_assert_invalid() {{
|
||||
// We do this to ident four spaces back
|
||||
// String::from_utf8_lossy(&wasm_binary),
|
||||
// wast_string.replace("\n", "\n "),
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -315,8 +311,7 @@ fn {}_assert_invalid() {{
|
||||
func_return,
|
||||
args_values.join(", "),
|
||||
assertion,
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
self.module_calls
|
||||
.entry(self.last_module)
|
||||
@ -373,8 +368,7 @@ fn {}_assert_invalid() {{
|
||||
func_return,
|
||||
args_values.join(", "),
|
||||
assertion,
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
self.module_calls
|
||||
.entry(self.last_module)
|
||||
@ -404,8 +398,7 @@ fn {}_assert_malformed() {{
|
||||
// We do this to ident four spaces back
|
||||
// String::from_utf8_lossy(&wasm_binary),
|
||||
// wast_string.replace("\n", "\n "),
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -469,8 +462,7 @@ fn {}_assert_malformed() {{
|
||||
func_return,
|
||||
args_values.join(", "),
|
||||
assertion,
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
Some(func_name)
|
||||
// let mut module_calls = self.module_calls.get(&self.last_module).unwrap();
|
||||
@ -491,7 +483,7 @@ fn {}_assert_malformed() {{
|
||||
.or_insert(Vec::new())
|
||||
.push(action_fn_name.unwrap());
|
||||
}
|
||||
|
||||
|
||||
fn visit_perform_action(&mut self, action: &Action) {
|
||||
let action_fn_name = self.visit_action(action, None);
|
||||
|
||||
@ -525,8 +517,7 @@ fn {}() {{
|
||||
trap_func_name,
|
||||
self.last_module,
|
||||
action_fn_name.unwrap(),
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
|
||||
// We don't group trap calls as they may cause memory faults
|
||||
|
@ -1,9 +1,7 @@
|
||||
|
||||
use crate::webassembly::Instance;
|
||||
use std::process;
|
||||
|
||||
|
||||
pub extern "C" fn abort(_code: i32, _instance: &Instance) {
|
||||
process::abort();
|
||||
// abort!("Aborted")
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::webassembly::ImportObject;
|
||||
|
||||
mod abort;
|
||||
mod printf;
|
||||
mod putchar;
|
||||
mod abort;
|
||||
|
||||
pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
|
||||
let mut import_object = ImportObject::new();
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
pub mod emscripten;
|
||||
|
||||
pub use self::emscripten::generate_emscripten_env;
|
||||
|
18
src/main.rs
18
src/main.rs
@ -1,15 +1,15 @@
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
extern crate libc;
|
||||
extern crate cranelift_codegen;
|
||||
extern crate cranelift_entity;
|
||||
extern crate cranelift_native;
|
||||
extern crate cranelift_wasm;
|
||||
extern crate libc;
|
||||
extern crate memmap;
|
||||
extern crate region;
|
||||
extern crate structopt;
|
||||
extern crate wabt;
|
||||
extern crate wasmparser;
|
||||
extern crate memmap;
|
||||
extern crate region;
|
||||
#[macro_use]
|
||||
extern crate target_lexicon;
|
||||
extern crate nix;
|
||||
@ -68,10 +68,16 @@ fn read_file_contents(path: &PathBuf) -> Result<Vec<u8>, io::Error> {
|
||||
|
||||
/// Execute a WASM/WAT file
|
||||
fn execute_wasm(wasm_path: PathBuf) -> Result<(), String> {
|
||||
let mut wasm_binary: Vec<u8> =
|
||||
read_file_contents(&wasm_path).map_err(|err| format!("Can't read the file {}: {}", wasm_path.as_os_str().to_string_lossy(), err))?;
|
||||
let mut wasm_binary: Vec<u8> = read_file_contents(&wasm_path).map_err(|err| {
|
||||
format!(
|
||||
"Can't read the file {}: {}",
|
||||
wasm_path.as_os_str().to_string_lossy(),
|
||||
err
|
||||
)
|
||||
})?;
|
||||
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();
|
||||
|
@ -5,7 +5,7 @@
|
||||
//! 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
|
||||
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];
|
||||
|
@ -131,7 +131,7 @@ pub struct InstanceOptions {
|
||||
pub mock_missing_imports: bool,
|
||||
}
|
||||
|
||||
extern fn mock_fn() -> i32 {
|
||||
extern "C" fn mock_fn() -> i32 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -167,15 +167,16 @@ impl Instance {
|
||||
// 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 (module, field) in module.info.imported_funcs.iter() {
|
||||
let function = import_object
|
||||
.get(&module.as_str(), &field.as_str());
|
||||
let function = import_object.get(&module.as_str(), &field.as_str());
|
||||
let function = if options.mock_missing_imports {
|
||||
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
|
||||
})
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
function.ok_or_else(|| {
|
||||
ErrorKind::LinkError(format!(
|
||||
"Imported function {}.{} was not provided in the import_functions",
|
||||
|
@ -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?
|
||||
// TODO: Consider static heap for efficiency.
|
||||
for i in 0..prev_bytes {
|
||||
unsafe {
|
||||
unsafe {
|
||||
let new_mmap_index = new_mmap.get_unchecked_mut(i);
|
||||
let old_mmap_index = self.mmap.get_unchecked(i);
|
||||
*new_mmap_index = *old_mmap_index;
|
||||
|
@ -47,7 +47,13 @@ pub fn instantiate(
|
||||
) -> Result<ResultObject, ErrorKind> {
|
||||
let module = compile(buffer_source)?;
|
||||
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");
|
||||
Ok(ResultObject { module, instance })
|
||||
}
|
||||
@ -100,7 +106,12 @@ pub fn validate_or_error(bytes: &[u8]) -> Result<(), ErrorKind> {
|
||||
let state = parser.read();
|
||||
match *state {
|
||||
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
|
||||
)))
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
@ -427,9 +427,7 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
|
||||
base: heap_base,
|
||||
min_size: Imm64::new(0),
|
||||
guard_size: Imm64::new(LinearMemory::DEFAULT_GUARD_SIZE as i64),
|
||||
style: ir::HeapStyle::Dynamic {
|
||||
bound_gv,
|
||||
},
|
||||
style: ir::HeapStyle::Dynamic { bound_gv },
|
||||
index_type: I32,
|
||||
})
|
||||
|
||||
@ -535,7 +533,6 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
|
||||
.special_param(ir::ArgumentPurpose::VMContext)
|
||||
.expect("Missing vmctx parameter");
|
||||
|
||||
|
||||
// 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.
|
||||
// TODO: Generate bounds checking code.
|
||||
|
Loading…
Reference in New Issue
Block a user