Cargo fmt

This commit is contained in:
Brandon Fish 2019-06-02 09:49:21 -05:00
parent f029ea6231
commit 995ecefa92
4 changed files with 58 additions and 44 deletions

View File

@ -212,16 +212,18 @@ fn get_callbacks() -> Callbacks {
}
}
unsafe extern "C" fn vm_breakpoint(_ctx: &mut vm::Ctx, breakpoints: *const Vec<Box<Fn(BkptInfo) + Send + Sync + 'static>>, index: u32) -> i32 {
unsafe extern "C" fn vm_breakpoint(
_ctx: &mut vm::Ctx,
breakpoints: *const Vec<Box<Fn(BkptInfo) + Send + Sync + 'static>>,
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<Vec<Box<Fn(BkptInfo) + Send + Sync + 'static>>>) -> (Self, LLVMCache) {
pub fn new(
module: Module,
_intrinsics: Intrinsics,
breakpoints: Box<Vec<Box<Fn(BkptInfo) + Send + Sync + 'static>>>,
) -> (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<Vec<Box<Fn(BkptInfo) + Send + Sync + 'static>>>) -> Result<(Self, LLVMCache), String> {
pub unsafe fn from_buffer(
memory: Memory,
breakpoints: Box<Vec<Box<Fn(BkptInfo) + Send + Sync + 'static>>>,
) -> Result<(Self, LLVMCache), String> {
let callbacks = get_callbacks();
let mut module: *mut LLVMModule = ptr::null_mut();

View File

@ -472,7 +472,8 @@ impl FunctionCodeGenerator<CodegenError> 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<CodegenError> 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<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
// 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<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
}
unsafe fn from_cache(_artifact: Artifact, _: Token) -> Result<ModuleInner, CacheError> {
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) =

View File

@ -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") }
})
}

View File

@ -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<LLVMModuleCodeGenerator, _, _, _, _> = StreamingCompiler::new(|| {
let mut chain = MiddlewareChain::new();
if let Some(limit) = options.instruction_limit {
chain.push(Metering::new(limit));
}
chain
});
let c: StreamingCompiler<LLVMModuleCodeGenerator, _, _, _, _> =
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))?
);
}
}