From 995ecefa928e4087764ed77bd1e839217b8ae1c1 Mon Sep 17 00:00:00 2001 From: Brandon Fish Date: Sun, 2 Jun 2019 09:49:21 -0500 Subject: [PATCH] Cargo fmt --- lib/llvm-backend/src/backend.rs | 21 ++++++++++++------ lib/llvm-backend/src/code.rs | 24 ++++++++++++++------- lib/llvm-backend/src/intrinsics.rs | 23 ++++++++------------ src/bin/wasmer.rs | 34 ++++++++++++++++-------------- 4 files changed, 58 insertions(+), 44 deletions(-) diff --git a/lib/llvm-backend/src/backend.rs b/lib/llvm-backend/src/backend.rs index 4824141a6..fa41e908e 100644 --- a/lib/llvm-backend/src/backend.rs +++ b/lib/llvm-backend/src/backend.rs @@ -212,16 +212,18 @@ fn get_callbacks() -> Callbacks { } } -unsafe extern "C" fn vm_breakpoint(_ctx: &mut vm::Ctx, breakpoints: *const Vec>, index: u32) -> i32 { +unsafe extern "C" fn vm_breakpoint( + _ctx: &mut vm::Ctx, + breakpoints: *const Vec>, + index: u32, +) -> i32 { unsafe extern "C" fn do_throw() -> ! { let ptr: *mut i32 = ::std::ptr::null_mut(); *ptr = 42; ::std::process::abort(); } let breakpoints: &Vec<_> = &*breakpoints; - breakpoints[index as usize](BkptInfo { - throw: do_throw, - }); + breakpoints[index as usize](BkptInfo { throw: do_throw }); 0 } @@ -251,7 +253,11 @@ pub struct LLVMBackend { } impl LLVMBackend { - pub fn new(module: Module, _intrinsics: Intrinsics, breakpoints: Box>>) -> (Self, LLVMCache) { + pub fn new( + module: Module, + _intrinsics: Intrinsics, + breakpoints: Box>>, + ) -> (Self, LLVMCache) { Target::initialize_x86(&InitializationConfig { asm_parser: true, asm_printer: true, @@ -312,7 +318,10 @@ impl LLVMBackend { ) } - pub unsafe fn from_buffer(memory: Memory, breakpoints: Box>>) -> Result<(Self, LLVMCache), String> { + pub unsafe fn from_buffer( + memory: Memory, + breakpoints: Box>>, + ) -> Result<(Self, LLVMCache), String> { let callbacks = get_callbacks(); let mut module: *mut LLVMModule = ptr::null_mut(); diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 8ad7cdfce..0069d0aee 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -472,7 +472,8 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { fn feed_event(&mut self, event: Event, module_info: &ModuleInfo) -> Result<(), CodegenError> { match event { - Event::Internal(InternalEvent::FunctionBegin(_)) | Event::Internal(InternalEvent::FunctionEnd) => { + Event::Internal(InternalEvent::FunctionBegin(_)) + | Event::Internal(InternalEvent::FunctionEnd) => { return Ok(()); } _ => {} @@ -533,13 +534,17 @@ impl FunctionCodeGenerator for LLVMFunctionCodeGenerator { .as_basic_value_enum(); builder.build_call( intrinsics.breakpoint, - &[ctx.basic(), ptr_const, intrinsics - .i32_ty - .const_int((breakpoints.len() - 1) as u64, false) - .as_basic_value_enum()], + &[ + ctx.basic(), + ptr_const, + intrinsics + .i32_ty + .const_int((breakpoints.len() - 1) as u64, false) + .as_basic_value_enum(), + ], &state.var_name(), ); - }, + } InternalEvent::GetInternal(index) => { let ptr = ctx.internal_pointer(index as usize, intrinsics); let value = builder.build_load(ptr, "internal_value"); @@ -2678,7 +2683,8 @@ impl ModuleCodeGenerator // self.module.print_to_stderr(); - let (backend, cache_gen) = LLVMBackend::new(self.module, self.intrinsics.take().unwrap(), breakpoints); + let (backend, cache_gen) = + LLVMBackend::new(self.module, self.intrinsics.take().unwrap(), breakpoints); Ok((backend, Box::new(cache_gen))) } @@ -2711,7 +2717,9 @@ impl ModuleCodeGenerator } unsafe fn from_cache(_artifact: Artifact, _: Token) -> Result { - Err(CacheError::Unknown("caching is broken for LLVM backend".into())) + Err(CacheError::Unknown( + "caching is broken for LLVM backend".into(), + )) /* let (info, _, memory) = artifact.consume(); let (backend, cache_gen) = diff --git a/lib/llvm-backend/src/intrinsics.rs b/lib/llvm-backend/src/intrinsics.rs index c3982857c..34f985c14 100644 --- a/lib/llvm-backend/src/intrinsics.rs +++ b/lib/llvm-backend/src/intrinsics.rs @@ -252,7 +252,10 @@ impl Intrinsics { let ret_i1_take_i1_i1 = i1_ty.fn_type(&[i1_ty_basic, i1_ty_basic], false); - let ret_i32_take_ctx_i64_i32 = i32_ty.fn_type(&[ctx_ptr_ty.as_basic_type_enum(), i64_ty_basic, i32_ty_basic], false); + let ret_i32_take_ctx_i64_i32 = i32_ty.fn_type( + &[ctx_ptr_ty.as_basic_type_enum(), i64_ty_basic, i32_ty_basic], + false, + ); Self { ctlz_i32: module.add_function("llvm.ctlz.i32", ret_i32_take_i32_i1, None), @@ -386,11 +389,7 @@ impl Intrinsics { ret_i32_take_ctx_i32, None, ), - breakpoint: module.add_function( - "vm.breakpoint", - ret_i32_take_ctx_i64_i32, - None, - ), + breakpoint: module.add_function("vm.breakpoint", ret_i32_take_ctx_i64_i32, None), throw_trap: module.add_function( "vm.exception.trap", void_ty.fn_type(&[i32_ty_basic], false), @@ -706,15 +705,11 @@ impl<'a> CtxType<'a> { "internals_array_ptr_ptr", ) }; - let array_ptr = cache_builder.build_load(array_ptr_ptr, "internals_array_ptr").into_pointer_value(); + let array_ptr = cache_builder + .build_load(array_ptr_ptr, "internals_array_ptr") + .into_pointer_value(); let const_index = intrinsics.i32_ty.const_int(index as u64, false); - unsafe { - cache_builder.build_in_bounds_gep( - array_ptr, - &[const_index], - "element_ptr", - ) - } + unsafe { cache_builder.build_in_bounds_gep(array_ptr, &[const_index], "element_ptr") } }) } diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 387582aa1..c97aa7c3c 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -16,9 +16,7 @@ use structopt::StructOpt; use wasmer::*; use wasmer_clif_backend::CraneliftCompiler; #[cfg(feature = "backend:llvm")] -use wasmer_llvm_backend::{ - code::LLVMModuleCodeGenerator, -}; +use wasmer_llvm_backend::code::LLVMModuleCodeGenerator; use wasmer_runtime::{ cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH}, error::RuntimeError, @@ -361,15 +359,16 @@ fn execute_wasm(options: &Run) -> Result<(), String> { Backend::Cranelift => Box::new(CraneliftCompiler::new()), #[cfg(feature = "backend:llvm")] Backend::LLVM => { - let c: StreamingCompiler = StreamingCompiler::new(|| { - let mut chain = MiddlewareChain::new(); - if let Some(limit) = options.instruction_limit { - chain.push(Metering::new(limit)); - } - chain - }); + let c: StreamingCompiler = + StreamingCompiler::new(|| { + let mut chain = MiddlewareChain::new(); + if let Some(limit) = options.instruction_limit { + chain.push(Metering::new(limit)); + } + chain + }); Box::new(c) - }, + } #[cfg(not(feature = "backend:llvm"))] Backend::LLVM => return Err("the llvm backend is not enabled".to_string()), }; @@ -558,11 +557,14 @@ fn execute_wasm(options: &Run) -> Result<(), String> { .map(|arg| arg.as_str()) .map(|x| Value::I32(x.parse().unwrap())) .collect(); - println!("{:?}", instance - .dyn_func("main") - .map_err(|e| format!("{:?}", e))? - .call(&args) - .map_err(|e| format!("{:?}", e))?); + println!( + "{:?}", + instance + .dyn_func("main") + .map_err(|e| format!("{:?}", e))? + .call(&args) + .map_err(|e| format!("{:?}", e))? + ); } }