mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
Cargo fmt
This commit is contained in:
parent
f029ea6231
commit
995ecefa92
@ -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() -> ! {
|
unsafe extern "C" fn do_throw() -> ! {
|
||||||
let ptr: *mut i32 = ::std::ptr::null_mut();
|
let ptr: *mut i32 = ::std::ptr::null_mut();
|
||||||
*ptr = 42;
|
*ptr = 42;
|
||||||
::std::process::abort();
|
::std::process::abort();
|
||||||
}
|
}
|
||||||
let breakpoints: &Vec<_> = &*breakpoints;
|
let breakpoints: &Vec<_> = &*breakpoints;
|
||||||
breakpoints[index as usize](BkptInfo {
|
breakpoints[index as usize](BkptInfo { throw: do_throw });
|
||||||
throw: do_throw,
|
|
||||||
});
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +253,11 @@ pub struct LLVMBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
Target::initialize_x86(&InitializationConfig {
|
||||||
asm_parser: true,
|
asm_parser: true,
|
||||||
asm_printer: 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 callbacks = get_callbacks();
|
||||||
let mut module: *mut LLVMModule = ptr::null_mut();
|
let mut module: *mut LLVMModule = ptr::null_mut();
|
||||||
|
|
||||||
|
@ -472,7 +472,8 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
|
|
||||||
fn feed_event(&mut self, event: Event, module_info: &ModuleInfo) -> Result<(), CodegenError> {
|
fn feed_event(&mut self, event: Event, module_info: &ModuleInfo) -> Result<(), CodegenError> {
|
||||||
match event {
|
match event {
|
||||||
Event::Internal(InternalEvent::FunctionBegin(_)) | Event::Internal(InternalEvent::FunctionEnd) => {
|
Event::Internal(InternalEvent::FunctionBegin(_))
|
||||||
|
| Event::Internal(InternalEvent::FunctionEnd) => {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -533,13 +534,17 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
.as_basic_value_enum();
|
.as_basic_value_enum();
|
||||||
builder.build_call(
|
builder.build_call(
|
||||||
intrinsics.breakpoint,
|
intrinsics.breakpoint,
|
||||||
&[ctx.basic(), ptr_const, intrinsics
|
&[
|
||||||
|
ctx.basic(),
|
||||||
|
ptr_const,
|
||||||
|
intrinsics
|
||||||
.i32_ty
|
.i32_ty
|
||||||
.const_int((breakpoints.len() - 1) as u64, false)
|
.const_int((breakpoints.len() - 1) as u64, false)
|
||||||
.as_basic_value_enum()],
|
.as_basic_value_enum(),
|
||||||
|
],
|
||||||
&state.var_name(),
|
&state.var_name(),
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
InternalEvent::GetInternal(index) => {
|
InternalEvent::GetInternal(index) => {
|
||||||
let ptr = ctx.internal_pointer(index as usize, intrinsics);
|
let ptr = ctx.internal_pointer(index as usize, intrinsics);
|
||||||
let value = builder.build_load(ptr, "internal_value");
|
let value = builder.build_load(ptr, "internal_value");
|
||||||
@ -2678,7 +2683,8 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
|
|||||||
|
|
||||||
// self.module.print_to_stderr();
|
// 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)))
|
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> {
|
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 (info, _, memory) = artifact.consume();
|
||||||
let (backend, cache_gen) =
|
let (backend, cache_gen) =
|
||||||
|
@ -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_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 {
|
Self {
|
||||||
ctlz_i32: module.add_function("llvm.ctlz.i32", ret_i32_take_i32_i1, None),
|
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,
|
ret_i32_take_ctx_i32,
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
breakpoint: module.add_function(
|
breakpoint: module.add_function("vm.breakpoint", ret_i32_take_ctx_i64_i32, None),
|
||||||
"vm.breakpoint",
|
|
||||||
ret_i32_take_ctx_i64_i32,
|
|
||||||
None,
|
|
||||||
),
|
|
||||||
throw_trap: module.add_function(
|
throw_trap: module.add_function(
|
||||||
"vm.exception.trap",
|
"vm.exception.trap",
|
||||||
void_ty.fn_type(&[i32_ty_basic], false),
|
void_ty.fn_type(&[i32_ty_basic], false),
|
||||||
@ -706,15 +705,11 @@ impl<'a> CtxType<'a> {
|
|||||||
"internals_array_ptr_ptr",
|
"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);
|
let const_index = intrinsics.i32_ty.const_int(index as u64, false);
|
||||||
unsafe {
|
unsafe { cache_builder.build_in_bounds_gep(array_ptr, &[const_index], "element_ptr") }
|
||||||
cache_builder.build_in_bounds_gep(
|
|
||||||
array_ptr,
|
|
||||||
&[const_index],
|
|
||||||
"element_ptr",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,9 +16,7 @@ use structopt::StructOpt;
|
|||||||
use wasmer::*;
|
use wasmer::*;
|
||||||
use wasmer_clif_backend::CraneliftCompiler;
|
use wasmer_clif_backend::CraneliftCompiler;
|
||||||
#[cfg(feature = "backend:llvm")]
|
#[cfg(feature = "backend:llvm")]
|
||||||
use wasmer_llvm_backend::{
|
use wasmer_llvm_backend::code::LLVMModuleCodeGenerator;
|
||||||
code::LLVMModuleCodeGenerator,
|
|
||||||
};
|
|
||||||
use wasmer_runtime::{
|
use wasmer_runtime::{
|
||||||
cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH},
|
cache::{Cache as BaseCache, FileSystemCache, WasmHash, WASMER_VERSION_HASH},
|
||||||
error::RuntimeError,
|
error::RuntimeError,
|
||||||
@ -361,7 +359,8 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
|||||||
Backend::Cranelift => Box::new(CraneliftCompiler::new()),
|
Backend::Cranelift => Box::new(CraneliftCompiler::new()),
|
||||||
#[cfg(feature = "backend:llvm")]
|
#[cfg(feature = "backend:llvm")]
|
||||||
Backend::LLVM => {
|
Backend::LLVM => {
|
||||||
let c: StreamingCompiler<LLVMModuleCodeGenerator, _, _, _, _> = StreamingCompiler::new(|| {
|
let c: StreamingCompiler<LLVMModuleCodeGenerator, _, _, _, _> =
|
||||||
|
StreamingCompiler::new(|| {
|
||||||
let mut chain = MiddlewareChain::new();
|
let mut chain = MiddlewareChain::new();
|
||||||
if let Some(limit) = options.instruction_limit {
|
if let Some(limit) = options.instruction_limit {
|
||||||
chain.push(Metering::new(limit));
|
chain.push(Metering::new(limit));
|
||||||
@ -369,7 +368,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
|||||||
chain
|
chain
|
||||||
});
|
});
|
||||||
Box::new(c)
|
Box::new(c)
|
||||||
},
|
}
|
||||||
#[cfg(not(feature = "backend:llvm"))]
|
#[cfg(not(feature = "backend:llvm"))]
|
||||||
Backend::LLVM => return Err("the llvm backend is not enabled".to_string()),
|
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(|arg| arg.as_str())
|
||||||
.map(|x| Value::I32(x.parse().unwrap()))
|
.map(|x| Value::I32(x.parse().unwrap()))
|
||||||
.collect();
|
.collect();
|
||||||
println!("{:?}", instance
|
println!(
|
||||||
|
"{:?}",
|
||||||
|
instance
|
||||||
.dyn_func("main")
|
.dyn_func("main")
|
||||||
.map_err(|e| format!("{:?}", e))?
|
.map_err(|e| format!("{:?}", e))?
|
||||||
.call(&args)
|
.call(&args)
|
||||||
.map_err(|e| format!("{:?}", e))?);
|
.map_err(|e| format!("{:?}", e))?
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user