mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-30 22:41:03 +00:00
Merge branch 'master' into feature/wasi
This commit is contained in:
commit
bbf663aceb
@ -70,6 +70,7 @@ Please select your operating system:
|
|||||||
|
|
||||||
- [macOS](#macos)
|
- [macOS](#macos)
|
||||||
- [Debian-based Linuxes](#debian-based-linuxes)
|
- [Debian-based Linuxes](#debian-based-linuxes)
|
||||||
|
- [FreeBSD](#freebsd)
|
||||||
- [Microsoft Windows](#windows-msvc)
|
- [Microsoft Windows](#windows-msvc)
|
||||||
|
|
||||||
#### macOS
|
#### macOS
|
||||||
@ -92,6 +93,12 @@ sudo port install cmake
|
|||||||
sudo apt install cmake
|
sudo apt install cmake
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### FreeBSD
|
||||||
|
|
||||||
|
```sh
|
||||||
|
pkg install cmake
|
||||||
|
```
|
||||||
|
|
||||||
#### Windows (MSVC)
|
#### Windows (MSVC)
|
||||||
|
|
||||||
Windows support is _highly experimental_. Only simple Wasm programs may be run, and no syscalls are allowed. This means
|
Windows support is _highly experimental_. Only simple Wasm programs may be run, and no syscalls are allowed. This means
|
||||||
|
@ -118,6 +118,22 @@ pub fn _pthread_cond_destroy(_ctx: &mut Ctx, _a: i32) -> i32 {
|
|||||||
debug!("emscripten::_pthread_cond_destroy");
|
debug!("emscripten::_pthread_cond_destroy");
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
pub fn _pthread_getspecific(_ctx: &mut Ctx, _a: i32) -> i32 {
|
||||||
|
debug!("emscripten::_pthread_getspecific");
|
||||||
|
0
|
||||||
|
}
|
||||||
|
pub fn _pthread_setspecific(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
|
||||||
|
debug!("emscripten::_pthread_setspecific");
|
||||||
|
0
|
||||||
|
}
|
||||||
|
pub fn _pthread_once(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
|
||||||
|
debug!("emscripten::_pthread_once");
|
||||||
|
0
|
||||||
|
}
|
||||||
|
pub fn _pthread_key_create(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
|
||||||
|
debug!("emscripten::_pthread_key_create");
|
||||||
|
0
|
||||||
|
}
|
||||||
pub fn _pthread_create(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 {
|
pub fn _pthread_create(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 {
|
||||||
debug!("emscripten::_pthread_create");
|
debug!("emscripten::_pthread_create");
|
||||||
0
|
0
|
||||||
@ -424,6 +440,30 @@ pub fn invoke_viiiiiiiii(
|
|||||||
panic!("dyn_call_viiiiiiiii is set to None");
|
panic!("dyn_call_viiiiiiiii is set to None");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn invoke_viiiiiiiiii(
|
||||||
|
ctx: &mut Ctx,
|
||||||
|
index: i32,
|
||||||
|
a1: i32,
|
||||||
|
a2: i32,
|
||||||
|
a3: i32,
|
||||||
|
a4: i32,
|
||||||
|
a5: i32,
|
||||||
|
a6: i32,
|
||||||
|
a7: i32,
|
||||||
|
a8: i32,
|
||||||
|
a9: i32,
|
||||||
|
a10: i32,
|
||||||
|
) {
|
||||||
|
debug!("emscripten::invoke_viiiiiiiiii");
|
||||||
|
if let Some(dyn_call_viiiiiiiiii) = &get_emscripten_data(ctx).dyn_call_viiiiiiiiii {
|
||||||
|
dyn_call_viiiiiiiiii
|
||||||
|
.call(index, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
panic!("dyn_call_viiiiiiiiii is set to None");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn invoke_iiji(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> i32 {
|
pub fn invoke_iiji(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> i32 {
|
||||||
debug!("emscripten::invoke_iiji");
|
debug!("emscripten::invoke_iiji");
|
||||||
if let Some(dyn_call_iiji) = &get_emscripten_data(ctx).dyn_call_iiji {
|
if let Some(dyn_call_iiji) = &get_emscripten_data(ctx).dyn_call_iiji {
|
||||||
@ -448,6 +488,15 @@ pub fn invoke_ji(ctx: &mut Ctx, index: i32, a1: i32) -> i32 {
|
|||||||
panic!("dyn_call_ji is set to None");
|
panic!("dyn_call_ji is set to None");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn invoke_jii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32) -> i32 {
|
||||||
|
debug!("emscripten::invoke_jii");
|
||||||
|
if let Some(dyn_call_jii) = &get_emscripten_data(ctx).dyn_call_jii {
|
||||||
|
dyn_call_jii.call(index, a1, a2).unwrap()
|
||||||
|
} else {
|
||||||
|
panic!("dyn_call_jii is set to None");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn invoke_jij(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) -> i32 {
|
pub fn invoke_jij(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) -> i32 {
|
||||||
debug!("emscripten::invoke_jij");
|
debug!("emscripten::invoke_jij");
|
||||||
if let Some(dyn_call_jij) = &get_emscripten_data(ctx).dyn_call_jij {
|
if let Some(dyn_call_jij) = &get_emscripten_data(ctx).dyn_call_jij {
|
||||||
|
@ -14,3 +14,12 @@ pub fn ___cxa_throw(ctx: &mut Ctx, _ptr: u32, _ty: u32, _destructor: u32) {
|
|||||||
debug!("emscripten::___cxa_throw");
|
debug!("emscripten::___cxa_throw");
|
||||||
_abort(ctx);
|
_abort(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn ___cxa_begin_catch(_ctx: &mut Ctx, _exception_object_ptr: u32) -> i32 {
|
||||||
|
debug!("emscripten::___cxa_begin_catch");
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ___cxa_end_catch(_ctx: &mut Ctx) {
|
||||||
|
debug!("emscripten::___cxa_end_catch");
|
||||||
|
}
|
||||||
|
@ -104,9 +104,12 @@ pub struct EmscriptenData<'a> {
|
|||||||
pub dyn_call_viiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32)>>,
|
pub dyn_call_viiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32)>>,
|
||||||
pub dyn_call_viiiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
|
pub dyn_call_viiiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
|
||||||
pub dyn_call_viiiiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
|
pub dyn_call_viiiiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
|
||||||
|
pub dyn_call_viiiiiiiiii:
|
||||||
|
Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
|
||||||
pub dyn_call_iiji: Option<Func<'a, (i32, i32, i32, i32, i32), i32>>,
|
pub dyn_call_iiji: Option<Func<'a, (i32, i32, i32, i32, i32), i32>>,
|
||||||
pub dyn_call_j: Option<Func<'a, i32, i32>>,
|
pub dyn_call_j: Option<Func<'a, i32, i32>>,
|
||||||
pub dyn_call_ji: Option<Func<'a, (i32, i32), i32>>,
|
pub dyn_call_ji: Option<Func<'a, (i32, i32), i32>>,
|
||||||
|
pub dyn_call_jii: Option<Func<'a, (i32, i32, i32), i32>>,
|
||||||
pub dyn_call_jij: Option<Func<'a, (i32, i32, i32, i32), i32>>,
|
pub dyn_call_jij: Option<Func<'a, (i32, i32, i32, i32), i32>>,
|
||||||
pub dyn_call_jjj: Option<Func<'a, (i32, i32, i32, i32, i32), i32>>,
|
pub dyn_call_jjj: Option<Func<'a, (i32, i32, i32, i32, i32), i32>>,
|
||||||
pub dyn_call_viiij: Option<Func<'a, (i32, i32, i32, i32, i32, i32)>>,
|
pub dyn_call_viiij: Option<Func<'a, (i32, i32, i32, i32, i32, i32)>>,
|
||||||
@ -160,9 +163,11 @@ impl<'a> EmscriptenData<'a> {
|
|||||||
let dyn_call_viiiiiii = instance.func("dynCall_viiiiiii").ok();
|
let dyn_call_viiiiiii = instance.func("dynCall_viiiiiii").ok();
|
||||||
let dyn_call_viiiiiiii = instance.func("dynCall_viiiiiiii").ok();
|
let dyn_call_viiiiiiii = instance.func("dynCall_viiiiiiii").ok();
|
||||||
let dyn_call_viiiiiiiii = instance.func("dynCall_viiiiiiiii").ok();
|
let dyn_call_viiiiiiiii = instance.func("dynCall_viiiiiiiii").ok();
|
||||||
|
let dyn_call_viiiiiiiiii = instance.func("dynCall_viiiiiiiiii").ok();
|
||||||
let dyn_call_iiji = instance.func("dynCall_iiji").ok();
|
let dyn_call_iiji = instance.func("dynCall_iiji").ok();
|
||||||
let dyn_call_j = instance.func("dynCall_j").ok();
|
let dyn_call_j = instance.func("dynCall_j").ok();
|
||||||
let dyn_call_ji = instance.func("dynCall_ji").ok();
|
let dyn_call_ji = instance.func("dynCall_ji").ok();
|
||||||
|
let dyn_call_jii = instance.func("dynCall_jii").ok();
|
||||||
let dyn_call_jij = instance.func("dynCall_jij").ok();
|
let dyn_call_jij = instance.func("dynCall_jij").ok();
|
||||||
let dyn_call_jjj = instance.func("dynCall_jjj").ok();
|
let dyn_call_jjj = instance.func("dynCall_jjj").ok();
|
||||||
let dyn_call_viiij = instance.func("dynCall_viiij").ok();
|
let dyn_call_viiij = instance.func("dynCall_viiij").ok();
|
||||||
@ -209,9 +214,11 @@ impl<'a> EmscriptenData<'a> {
|
|||||||
dyn_call_viiiiiii,
|
dyn_call_viiiiiii,
|
||||||
dyn_call_viiiiiiii,
|
dyn_call_viiiiiiii,
|
||||||
dyn_call_viiiiiiiii,
|
dyn_call_viiiiiiiii,
|
||||||
|
dyn_call_viiiiiiiiii,
|
||||||
dyn_call_iiji,
|
dyn_call_iiji,
|
||||||
dyn_call_j,
|
dyn_call_j,
|
||||||
dyn_call_ji,
|
dyn_call_ji,
|
||||||
|
dyn_call_jii,
|
||||||
dyn_call_jij,
|
dyn_call_jij,
|
||||||
dyn_call_jjj,
|
dyn_call_jjj,
|
||||||
dyn_call_viiij,
|
dyn_call_viiij,
|
||||||
@ -562,6 +569,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
|||||||
"_kill" => func!(crate::process::_kill),
|
"_kill" => func!(crate::process::_kill),
|
||||||
"_llvm_stackrestore" => func!(crate::process::_llvm_stackrestore),
|
"_llvm_stackrestore" => func!(crate::process::_llvm_stackrestore),
|
||||||
"_llvm_stacksave" => func!(crate::process::_llvm_stacksave),
|
"_llvm_stacksave" => func!(crate::process::_llvm_stacksave),
|
||||||
|
"_llvm_eh_typeid_for" => func!(crate::process::_llvm_eh_typeid_for),
|
||||||
"_raise" => func!(crate::process::_raise),
|
"_raise" => func!(crate::process::_raise),
|
||||||
"_sem_init" => func!(crate::process::_sem_init),
|
"_sem_init" => func!(crate::process::_sem_init),
|
||||||
"_sem_post" => func!(crate::process::_sem_post),
|
"_sem_post" => func!(crate::process::_sem_post),
|
||||||
@ -597,6 +605,8 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
|||||||
// Exception
|
// Exception
|
||||||
"___cxa_allocate_exception" => func!(crate::exception::___cxa_allocate_exception),
|
"___cxa_allocate_exception" => func!(crate::exception::___cxa_allocate_exception),
|
||||||
"___cxa_throw" => func!(crate::exception::___cxa_throw),
|
"___cxa_throw" => func!(crate::exception::___cxa_throw),
|
||||||
|
"___cxa_begin_catch" => func!(crate::exception::___cxa_begin_catch),
|
||||||
|
"___cxa_end_catch" => func!(crate::exception::___cxa_end_catch),
|
||||||
|
|
||||||
// Time
|
// Time
|
||||||
"_gettimeofday" => func!(crate::time::_gettimeofday),
|
"_gettimeofday" => func!(crate::time::_gettimeofday),
|
||||||
@ -675,6 +685,10 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
|||||||
"_pthread_rwlock_rdlock" => func!(crate::emscripten_target::_pthread_rwlock_rdlock),
|
"_pthread_rwlock_rdlock" => func!(crate::emscripten_target::_pthread_rwlock_rdlock),
|
||||||
"_pthread_rwlock_unlock" => func!(crate::emscripten_target::_pthread_rwlock_unlock),
|
"_pthread_rwlock_unlock" => func!(crate::emscripten_target::_pthread_rwlock_unlock),
|
||||||
"_pthread_setcancelstate" => func!(crate::emscripten_target::_pthread_setcancelstate),
|
"_pthread_setcancelstate" => func!(crate::emscripten_target::_pthread_setcancelstate),
|
||||||
|
"_pthread_getspecific" => func!(crate::emscripten_target::_pthread_getspecific),
|
||||||
|
"_pthread_setspecific" => func!(crate::emscripten_target::_pthread_setspecific),
|
||||||
|
"_pthread_once" => func!(crate::emscripten_target::_pthread_once),
|
||||||
|
"_pthread_key_create" => func!(crate::emscripten_target::_pthread_key_create),
|
||||||
"___gxx_personality_v0" => func!(crate::emscripten_target::___gxx_personality_v0),
|
"___gxx_personality_v0" => func!(crate::emscripten_target::___gxx_personality_v0),
|
||||||
"_getdtablesize" => func!(crate::emscripten_target::_getdtablesize),
|
"_getdtablesize" => func!(crate::emscripten_target::_getdtablesize),
|
||||||
"_gethostbyaddr" => func!(crate::emscripten_target::_gethostbyaddr),
|
"_gethostbyaddr" => func!(crate::emscripten_target::_gethostbyaddr),
|
||||||
@ -693,9 +707,12 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
|||||||
"invoke_viiiiiii" => func!(crate::emscripten_target::invoke_viiiiiii),
|
"invoke_viiiiiii" => func!(crate::emscripten_target::invoke_viiiiiii),
|
||||||
"invoke_viiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiii),
|
"invoke_viiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiii),
|
||||||
"invoke_viiiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiiii),
|
"invoke_viiiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiiii),
|
||||||
|
"invoke_viiiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiiii),
|
||||||
|
"invoke_viiiiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiiiii),
|
||||||
"invoke_iiji" => func!(crate::emscripten_target::invoke_iiji),
|
"invoke_iiji" => func!(crate::emscripten_target::invoke_iiji),
|
||||||
"invoke_j" => func!(crate::emscripten_target::invoke_j),
|
"invoke_j" => func!(crate::emscripten_target::invoke_j),
|
||||||
"invoke_ji" => func!(crate::emscripten_target::invoke_ji),
|
"invoke_ji" => func!(crate::emscripten_target::invoke_ji),
|
||||||
|
"invoke_jii" => func!(crate::emscripten_target::invoke_jii),
|
||||||
"invoke_jij" => func!(crate::emscripten_target::invoke_jij),
|
"invoke_jij" => func!(crate::emscripten_target::invoke_jij),
|
||||||
"invoke_jjj" => func!(crate::emscripten_target::invoke_jjj),
|
"invoke_jjj" => func!(crate::emscripten_target::invoke_jjj),
|
||||||
"invoke_viiij" => func!(crate::emscripten_target::invoke_viiij),
|
"invoke_viiij" => func!(crate::emscripten_target::invoke_viiij),
|
||||||
|
@ -150,6 +150,11 @@ pub fn _llvm_trap(ctx: &mut Ctx) {
|
|||||||
abort_with_message(ctx, "abort!");
|
abort_with_message(ctx, "abort!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn _llvm_eh_typeid_for(_ctx: &mut Ctx, _type_info_addr: u32) -> i32 {
|
||||||
|
debug!("emscripten::_llvm_eh_typeid_for");
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
|
||||||
pub fn _system(_ctx: &mut Ctx, _one: i32) -> c_int {
|
pub fn _system(_ctx: &mut Ctx, _one: i32) -> c_int {
|
||||||
debug!("emscripten::_system");
|
debug!("emscripten::_system");
|
||||||
// TODO: May need to change this Em impl to a working version
|
// TODO: May need to change this Em impl to a working version
|
||||||
|
@ -23,10 +23,7 @@ use wasmer_runtime_core::{
|
|||||||
export::Context,
|
export::Context,
|
||||||
module::{ModuleInfo, ModuleInner},
|
module::{ModuleInfo, ModuleInner},
|
||||||
structures::TypedIndex,
|
structures::TypedIndex,
|
||||||
types::{
|
types::{FuncIndex, FuncSig, LocalFuncIndex, LocalOrImport, SigIndex, Type, Value},
|
||||||
FuncIndex, FuncSig, LocalFuncIndex, LocalOrImport, MemoryIndex, SigIndex, TableIndex, Type,
|
|
||||||
Value,
|
|
||||||
},
|
|
||||||
vm::{self, ImportBacking},
|
vm::{self, ImportBacking},
|
||||||
vmcalls,
|
vmcalls,
|
||||||
};
|
};
|
||||||
@ -57,6 +54,7 @@ enum LLVMResult {
|
|||||||
OBJECT_LOAD_FAILURE,
|
OBJECT_LOAD_FAILURE,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
enum WasmTrapType {
|
enum WasmTrapType {
|
||||||
Unreachable = 0,
|
Unreachable = 0,
|
||||||
@ -220,7 +218,7 @@ pub struct LLVMBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl LLVMBackend {
|
impl LLVMBackend {
|
||||||
pub fn new(module: Module, intrinsics: Intrinsics) -> (Self, LLVMProtectedCaller) {
|
pub fn new(module: Module, _intrinsics: Intrinsics) -> (Self, LLVMProtectedCaller) {
|
||||||
Target::initialize_x86(&InitializationConfig {
|
Target::initialize_x86(&InitializationConfig {
|
||||||
asm_parser: true,
|
asm_parser: true,
|
||||||
asm_printer: true,
|
asm_printer: true,
|
||||||
|
@ -3,14 +3,14 @@ use inkwell::{
|
|||||||
context::Context,
|
context::Context,
|
||||||
module::{Linkage, Module},
|
module::{Linkage, Module},
|
||||||
passes::PassManager,
|
passes::PassManager,
|
||||||
types::{BasicType, BasicTypeEnum, FunctionType, IntType, PointerType},
|
types::{BasicType, BasicTypeEnum, FunctionType, PointerType},
|
||||||
values::{BasicValue, FloatValue, FunctionValue, IntValue, PhiValue, PointerValue},
|
values::{BasicValue, FloatValue, FunctionValue, IntValue, PhiValue, PointerValue},
|
||||||
AddressSpace, FloatPredicate, IntPredicate,
|
AddressSpace, FloatPredicate, IntPredicate,
|
||||||
};
|
};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use wasmer_runtime_core::{
|
use wasmer_runtime_core::{
|
||||||
memory::MemoryType,
|
memory::MemoryType,
|
||||||
module::{ExportIndex, ModuleInfo},
|
module::ModuleInfo,
|
||||||
structures::{Map, SliceMap, TypedIndex},
|
structures::{Map, SliceMap, TypedIndex},
|
||||||
types::{
|
types::{
|
||||||
FuncIndex, FuncSig, GlobalIndex, LocalFuncIndex, LocalOrImport, MemoryIndex, SigIndex,
|
FuncIndex, FuncSig, GlobalIndex, LocalFuncIndex, LocalOrImport, MemoryIndex, SigIndex,
|
||||||
@ -102,7 +102,6 @@ pub fn parse_function_bodies(
|
|||||||
|
|
||||||
parse_function(
|
parse_function(
|
||||||
&context,
|
&context,
|
||||||
&module,
|
|
||||||
&builder,
|
&builder,
|
||||||
&intrinsics,
|
&intrinsics,
|
||||||
info,
|
info,
|
||||||
@ -143,7 +142,6 @@ pub fn parse_function_bodies(
|
|||||||
|
|
||||||
fn parse_function(
|
fn parse_function(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
module: &Module,
|
|
||||||
builder: &Builder,
|
builder: &Builder,
|
||||||
intrinsics: &Intrinsics,
|
intrinsics: &Intrinsics,
|
||||||
info: &ModuleInfo,
|
info: &ModuleInfo,
|
||||||
@ -155,7 +153,6 @@ fn parse_function(
|
|||||||
) -> Result<(), BinaryReaderError> {
|
) -> Result<(), BinaryReaderError> {
|
||||||
let sig_index = info.func_assoc[func_index.convert_up(info)];
|
let sig_index = info.func_assoc[func_index.convert_up(info)];
|
||||||
let func_sig = &info.signatures[sig_index];
|
let func_sig = &info.signatures[sig_index];
|
||||||
let llvm_sig = &signatures[sig_index];
|
|
||||||
|
|
||||||
let function = functions[func_index];
|
let function = functions[func_index];
|
||||||
let mut state = State::new();
|
let mut state = State::new();
|
||||||
@ -193,7 +190,7 @@ fn parse_function(
|
|||||||
let param_len = locals.len();
|
let param_len = locals.len();
|
||||||
|
|
||||||
let mut local_idx = 0;
|
let mut local_idx = 0;
|
||||||
for (index, local) in locals_reader.into_iter().enumerate() {
|
for local in locals_reader.into_iter() {
|
||||||
let (count, ty) = local?;
|
let (count, ty) = local?;
|
||||||
let wasmer_ty = type_to_type(ty)?;
|
let wasmer_ty = type_to_type(ty)?;
|
||||||
let ty = type_to_llvm(intrinsics, wasmer_ty);
|
let ty = type_to_llvm(intrinsics, wasmer_ty);
|
||||||
@ -490,7 +487,6 @@ fn parse_function(
|
|||||||
if let ControlFrame::IfElse {
|
if let ControlFrame::IfElse {
|
||||||
if_else,
|
if_else,
|
||||||
next,
|
next,
|
||||||
phis,
|
|
||||||
if_else_state,
|
if_else_state,
|
||||||
..
|
..
|
||||||
} = &frame
|
} = &frame
|
||||||
@ -866,7 +862,7 @@ fn parse_function(
|
|||||||
let value = call_site.try_as_basic_value().left().unwrap();
|
let value = call_site.try_as_basic_value().left().unwrap();
|
||||||
state.push1(value);
|
state.push1(value);
|
||||||
}
|
}
|
||||||
returns @ _ => unimplemented!("multi-value returns"),
|
_ => unimplemented!("multi-value returns"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2158,7 +2154,7 @@ fn parse_function(
|
|||||||
[one_value] => {
|
[one_value] => {
|
||||||
builder.build_return(Some(one_value));
|
builder.build_return(Some(one_value));
|
||||||
}
|
}
|
||||||
returns @ _ => {
|
_ => {
|
||||||
// let struct_ty = llvm_sig.get_return_type().as_struct_type();
|
// let struct_ty = llvm_sig.get_return_type().as_struct_type();
|
||||||
// let ret_struct = struct_ty.const_zero();
|
// let ret_struct = struct_ty.const_zero();
|
||||||
unimplemented!("multi-value returns not yet implemented")
|
unimplemented!("multi-value returns not yet implemented")
|
||||||
@ -2211,7 +2207,7 @@ fn trap_if_not_representatable_as_int(
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
let masked = builder.build_and(
|
builder.build_and(
|
||||||
float_bits,
|
float_bits,
|
||||||
int_ty.const_int(exponent_mask, false),
|
int_ty.const_int(exponent_mask, false),
|
||||||
"masked_bits",
|
"masked_bits",
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
use inkwell::OptimizationLevel;
|
|
||||||
use inkwell::builder::Builder;
|
|
||||||
use inkwell::context::Context;
|
|
||||||
use inkwell::execution_engine::{ExecutionEngine, JitFunction};
|
|
||||||
use inkwell::module::Module;
|
|
||||||
use inkwell::targets::{InitializationConfig, Target};
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
/// Convenience type alias for the `sum` function.
|
|
||||||
///
|
|
||||||
/// Calling this is innately `unsafe` because there's no guarantee it doesn't
|
|
||||||
/// do `unsafe` operations internally.
|
|
||||||
type SumFunc = unsafe extern "C" fn(u64, u64, u64) -> u64;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_sum() -> Result<(), Box<Error>> {
|
|
||||||
let context = Context::create();
|
|
||||||
let module = context.create_module("sum");
|
|
||||||
let builder = context.create_builder();
|
|
||||||
let execution_engine = module.create_jit_execution_engine(OptimizationLevel::Aggressive)?;
|
|
||||||
|
|
||||||
let sum = jit_compile_sum(&context, &module, &builder, &execution_engine)
|
|
||||||
.ok_or("Unable to JIT compile `sum`")?;
|
|
||||||
|
|
||||||
let x = 1u64;
|
|
||||||
let y = 2u64;
|
|
||||||
let z = 3u64;
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
println!("{} + {} + {} = {}", x, y, z, sum.call(x, y, z));
|
|
||||||
assert_eq!(sum.call(x, y, z), x + y + z);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn jit_compile_sum(
|
|
||||||
context: &Context,
|
|
||||||
module: &Module,
|
|
||||||
builder: &Builder,
|
|
||||||
execution_engine: &ExecutionEngine,
|
|
||||||
) -> Option<JitFunction<SumFunc>> {
|
|
||||||
let i64_type = context.i64_type();
|
|
||||||
let fn_type = i64_type.fn_type(&[i64_type.into(), i64_type.into(), i64_type.into()], false);
|
|
||||||
|
|
||||||
let function = module.add_function("sum", fn_type, None);
|
|
||||||
let basic_block = context.append_basic_block(&function, "entry");
|
|
||||||
|
|
||||||
builder.position_at_end(&basic_block);
|
|
||||||
|
|
||||||
let x = function.get_nth_param(0)?.into_int_value();
|
|
||||||
let y = function.get_nth_param(1)?.into_int_value();
|
|
||||||
let z = function.get_nth_param(2)?.into_int_value();
|
|
||||||
|
|
||||||
let sum = builder.build_int_add(x, y, "sum");
|
|
||||||
let sum = builder.build_int_add(sum, z, "sum");
|
|
||||||
|
|
||||||
builder.build_return(Some(&sum));
|
|
||||||
|
|
||||||
unsafe { execution_engine.get_function("sum").ok() }
|
|
||||||
}
|
|
@ -4,10 +4,7 @@ use inkwell::{
|
|||||||
context::Context,
|
context::Context,
|
||||||
module::Module,
|
module::Module,
|
||||||
types::{BasicType, FloatType, FunctionType, IntType, PointerType, StructType, VoidType},
|
types::{BasicType, FloatType, FunctionType, IntType, PointerType, StructType, VoidType},
|
||||||
values::{
|
values::{BasicValue, BasicValueEnum, FloatValue, FunctionValue, IntValue, PointerValue},
|
||||||
BasicValue, BasicValueEnum, FloatValue, FunctionValue, InstructionValue, IntValue,
|
|
||||||
PointerValue,
|
|
||||||
},
|
|
||||||
AddressSpace,
|
AddressSpace,
|
||||||
};
|
};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
@ -117,7 +114,6 @@ pub struct Intrinsics {
|
|||||||
|
|
||||||
pub throw_trap: FunctionValue,
|
pub throw_trap: FunctionValue,
|
||||||
|
|
||||||
ctx_ty: StructType,
|
|
||||||
pub ctx_ptr_ty: PointerType,
|
pub ctx_ptr_ty: PointerType,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,7 +366,6 @@ impl Intrinsics {
|
|||||||
void_ty.fn_type(&[i32_ty_basic], false),
|
void_ty.fn_type(&[i32_ty_basic], false),
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
ctx_ty,
|
|
||||||
ctx_ptr_ty,
|
ctx_ptr_ty,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -383,9 +378,6 @@ impl Intrinsics {
|
|||||||
cache_builder: Builder,
|
cache_builder: Builder,
|
||||||
) -> CtxType<'a> {
|
) -> CtxType<'a> {
|
||||||
CtxType {
|
CtxType {
|
||||||
ctx_ty: self.ctx_ty,
|
|
||||||
ctx_ptr_ty: self.ctx_ptr_ty,
|
|
||||||
|
|
||||||
ctx_ptr_value: func_value.get_nth_param(0).unwrap().into_pointer_value(),
|
ctx_ptr_value: func_value.get_nth_param(0).unwrap().into_pointer_value(),
|
||||||
|
|
||||||
builder,
|
builder,
|
||||||
@ -435,9 +427,6 @@ struct ImportedFuncCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct CtxType<'a> {
|
pub struct CtxType<'a> {
|
||||||
ctx_ty: StructType,
|
|
||||||
ctx_ptr_ty: PointerType,
|
|
||||||
|
|
||||||
ctx_ptr_value: PointerValue,
|
ctx_ptr_value: PointerValue,
|
||||||
|
|
||||||
builder: &'a Builder,
|
builder: &'a Builder,
|
||||||
@ -460,9 +449,8 @@ impl<'a> CtxType<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn memory(&mut self, index: MemoryIndex) -> MemoryCache {
|
pub fn memory(&mut self, index: MemoryIndex) -> MemoryCache {
|
||||||
let (cached_memories, builder, info, ctx_ptr_value, intrinsics, cache_builder) = (
|
let (cached_memories, info, ctx_ptr_value, intrinsics, cache_builder) = (
|
||||||
&mut self.cached_memories,
|
&mut self.cached_memories,
|
||||||
self.builder,
|
|
||||||
self.info,
|
self.info,
|
||||||
self.ctx_ptr_value,
|
self.ctx_ptr_value,
|
||||||
self.intrinsics,
|
self.intrinsics,
|
||||||
@ -618,10 +606,8 @@ impl<'a> CtxType<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn dynamic_sigindex(&mut self, index: SigIndex) -> IntValue {
|
pub fn dynamic_sigindex(&mut self, index: SigIndex) -> IntValue {
|
||||||
let (cached_sigindices, builder, info, ctx_ptr_value, intrinsics, cache_builder) = (
|
let (cached_sigindices, ctx_ptr_value, intrinsics, cache_builder) = (
|
||||||
&mut self.cached_sigindices,
|
&mut self.cached_sigindices,
|
||||||
self.builder,
|
|
||||||
self.info,
|
|
||||||
self.ctx_ptr_value,
|
self.ctx_ptr_value,
|
||||||
self.intrinsics,
|
self.intrinsics,
|
||||||
&self.cache_builder,
|
&self.cache_builder,
|
||||||
@ -651,9 +637,8 @@ impl<'a> CtxType<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn global_cache(&mut self, index: GlobalIndex) -> GlobalCache {
|
pub fn global_cache(&mut self, index: GlobalIndex) -> GlobalCache {
|
||||||
let (cached_globals, builder, ctx_ptr_value, info, intrinsics, cache_builder) = (
|
let (cached_globals, ctx_ptr_value, info, intrinsics, cache_builder) = (
|
||||||
&mut self.cached_globals,
|
&mut self.cached_globals,
|
||||||
self.builder,
|
|
||||||
self.ctx_ptr_value,
|
self.ctx_ptr_value,
|
||||||
self.info,
|
self.info,
|
||||||
self.intrinsics,
|
self.intrinsics,
|
||||||
@ -728,9 +713,8 @@ impl<'a> CtxType<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn imported_func(&mut self, index: ImportedFuncIndex) -> (PointerValue, PointerValue) {
|
pub fn imported_func(&mut self, index: ImportedFuncIndex) -> (PointerValue, PointerValue) {
|
||||||
let (cached_imported_functions, builder, ctx_ptr_value, intrinsics, cache_builder) = (
|
let (cached_imported_functions, ctx_ptr_value, intrinsics, cache_builder) = (
|
||||||
&mut self.cached_imported_functions,
|
&mut self.cached_imported_functions,
|
||||||
self.builder,
|
|
||||||
self.ctx_ptr_value,
|
self.ctx_ptr_value,
|
||||||
self.intrinsics,
|
self.intrinsics,
|
||||||
&self.cache_builder,
|
&self.cache_builder,
|
||||||
@ -770,38 +754,4 @@ impl<'a> CtxType<'a> {
|
|||||||
|
|
||||||
(imported_func_cache.func_ptr, imported_func_cache.ctx_ptr)
|
(imported_func_cache.func_ptr, imported_func_cache.ctx_ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_trap(&self) {
|
|
||||||
self.builder.build_call(self.intrinsics.trap, &[], "trap");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub struct Ctx {
|
|
||||||
// /// A pointer to an array of locally-defined memories, indexed by `MemoryIndex`.
|
|
||||||
// pub(crate) memories: *mut *mut LocalMemory,
|
|
||||||
|
|
||||||
// /// A pointer to an array of locally-defined tables, indexed by `TableIndex`.
|
|
||||||
// pub(crate) tables: *mut *mut LocalTable,
|
|
||||||
|
|
||||||
// /// A pointer to an array of locally-defined globals, indexed by `GlobalIndex`.
|
|
||||||
// pub(crate) globals: *mut *mut LocalGlobal,
|
|
||||||
|
|
||||||
// /// A pointer to an array of imported memories, indexed by `MemoryIndex,
|
|
||||||
// pub(crate) imported_memories: *mut *mut LocalMemory,
|
|
||||||
|
|
||||||
// /// A pointer to an array of imported tables, indexed by `TableIndex`.
|
|
||||||
// pub(crate) imported_tables: *mut *mut LocalTable,
|
|
||||||
|
|
||||||
// /// A pointer to an array of imported globals, indexed by `GlobalIndex`.
|
|
||||||
// pub(crate) imported_globals: *mut *mut LocalGlobal,
|
|
||||||
|
|
||||||
// /// A pointer to an array of imported functions, indexed by `FuncIndex`.
|
|
||||||
// pub(crate) imported_funcs: *mut ImportedFunc,
|
|
||||||
|
|
||||||
// local_backing: *mut LocalBacking,
|
|
||||||
// import_backing: *mut ImportBacking,
|
|
||||||
// module: *const ModuleInner,
|
|
||||||
|
|
||||||
// pub data: *mut c_void,
|
|
||||||
// pub data_finalizer: Option<extern "C" fn(data: *mut c_void)>,
|
|
||||||
// }
|
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
#![cfg_attr(nightly, feature(unwind_attributes))]
|
#![cfg_attr(nightly, feature(unwind_attributes))]
|
||||||
|
|
||||||
use inkwell::{
|
|
||||||
execution_engine::JitFunction,
|
|
||||||
targets::{CodeModel, FileType, InitializationConfig, RelocMode, Target, TargetMachine},
|
|
||||||
OptimizationLevel,
|
|
||||||
};
|
|
||||||
use wasmer_runtime_core::{
|
use wasmer_runtime_core::{
|
||||||
backend::{Compiler, CompilerConfig, Token},
|
backend::{Compiler, CompilerConfig, Token},
|
||||||
cache::{Artifact, Error as CacheError},
|
cache::{Artifact, Error as CacheError},
|
||||||
@ -47,19 +42,16 @@ impl Compiler for LLVMCompiler {
|
|||||||
|
|
||||||
// Create placeholder values here.
|
// Create placeholder values here.
|
||||||
let cache_gen = {
|
let cache_gen = {
|
||||||
use wasmer_runtime_core::backend::{
|
use wasmer_runtime_core::backend::{sys::Memory, CacheGen};
|
||||||
sys::Memory, CacheGen, ProtectedCaller, UserTrapper,
|
|
||||||
};
|
|
||||||
use wasmer_runtime_core::cache::Error as CacheError;
|
use wasmer_runtime_core::cache::Error as CacheError;
|
||||||
use wasmer_runtime_core::error::RuntimeResult;
|
|
||||||
use wasmer_runtime_core::module::ModuleInfo;
|
use wasmer_runtime_core::module::ModuleInfo;
|
||||||
use wasmer_runtime_core::types::{FuncIndex, Value};
|
|
||||||
use wasmer_runtime_core::vm;
|
|
||||||
struct Placeholder;
|
struct Placeholder;
|
||||||
|
|
||||||
impl CacheGen for Placeholder {
|
impl CacheGen for Placeholder {
|
||||||
fn generate_cache(
|
fn generate_cache(
|
||||||
&self,
|
&self,
|
||||||
module: &ModuleInner,
|
_module: &ModuleInner,
|
||||||
) -> Result<(Box<ModuleInfo>, Box<[u8]>, Memory), CacheError> {
|
) -> Result<(Box<ModuleInfo>, Box<[u8]>, Memory), CacheError> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use libc::{c_void, siginfo_t};
|
use libc::{c_void, siginfo_t};
|
||||||
use nix::sys::signal::{
|
use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, SIGBUS, SIGSEGV};
|
||||||
sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal, SIGBUS, SIGFPE, SIGILL, SIGSEGV,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// `__register_frame` and `__deregister_frame` on macos take a single fde as an
|
/// `__register_frame` and `__deregister_frame` on macos take a single fde as an
|
||||||
/// argument, so we need to parse the fde table here.
|
/// argument, so we need to parse the fde table here.
|
||||||
@ -51,24 +49,22 @@ pub unsafe fn install_signal_handler() {
|
|||||||
SaFlags::SA_ONSTACK | SaFlags::SA_SIGINFO,
|
SaFlags::SA_ONSTACK | SaFlags::SA_SIGINFO,
|
||||||
SigSet::empty(),
|
SigSet::empty(),
|
||||||
);
|
);
|
||||||
// sigaction(SIGFPE, &sa).unwrap();
|
|
||||||
// sigaction(SIGILL, &sa).unwrap();
|
|
||||||
sigaction(SIGSEGV, &sa).unwrap();
|
sigaction(SIGSEGV, &sa).unwrap();
|
||||||
sigaction(SIGBUS, &sa).unwrap();
|
sigaction(SIGBUS, &sa).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(nightly, unwind(allowed))]
|
#[cfg_attr(nightly, unwind(allowed))]
|
||||||
extern "C" fn signal_trap_handler(
|
extern "C" fn signal_trap_handler(
|
||||||
signum: ::nix::libc::c_int,
|
_signum: ::nix::libc::c_int,
|
||||||
siginfo: *mut siginfo_t,
|
_siginfo: *mut siginfo_t,
|
||||||
ucontext: *mut c_void,
|
_ucontext: *mut c_void,
|
||||||
) {
|
) {
|
||||||
unsafe {
|
unsafe {
|
||||||
/// Apparently, we can unwind from arbitary instructions, as long
|
// Apparently, we can unwind from arbitary instructions, as long
|
||||||
/// as we don't need to catch the exception inside the function that
|
// as we don't need to catch the exception inside the function that
|
||||||
/// was interrupted.
|
// was interrupted.
|
||||||
///
|
//
|
||||||
/// This works on macos, not sure about linux.
|
// This works on macos, not sure about linux.
|
||||||
throw_trap(2);
|
throw_trap(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,9 @@ use inkwell::{
|
|||||||
builder::Builder,
|
builder::Builder,
|
||||||
context::Context,
|
context::Context,
|
||||||
module::{Linkage, Module},
|
module::{Linkage, Module},
|
||||||
passes::PassManager,
|
types::{BasicType, FunctionType},
|
||||||
types::{BasicType, BasicTypeEnum, FunctionType, PointerType},
|
values::FunctionValue,
|
||||||
values::{BasicValue, FunctionValue, PhiValue, PointerValue},
|
AddressSpace,
|
||||||
AddressSpace, FloatPredicate, IntPredicate,
|
|
||||||
};
|
};
|
||||||
use wasmer_runtime_core::{
|
use wasmer_runtime_core::{
|
||||||
module::ModuleInfo,
|
module::ModuleInfo,
|
||||||
@ -43,20 +42,12 @@ pub fn generate_trampolines(
|
|||||||
Some(Linkage::External),
|
Some(Linkage::External),
|
||||||
);
|
);
|
||||||
|
|
||||||
generate_trampoline(
|
generate_trampoline(trampoline_func, sig, context, builder, intrinsics);
|
||||||
trampoline_func,
|
|
||||||
func_type,
|
|
||||||
sig,
|
|
||||||
context,
|
|
||||||
builder,
|
|
||||||
intrinsics,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_trampoline(
|
fn generate_trampoline(
|
||||||
trampoline_func: FunctionValue,
|
trampoline_func: FunctionValue,
|
||||||
sig_type: FunctionType,
|
|
||||||
func_sig: &FuncSig,
|
func_sig: &FuncSig,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
builder: &Builder,
|
builder: &Builder,
|
||||||
|
@ -183,6 +183,7 @@ pub enum Initializer {
|
|||||||
GetGlobal(ImportedGlobalIndex),
|
GetGlobal(ImportedGlobalIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Describes the mutability and type of a Global
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct GlobalDescriptor {
|
pub struct GlobalDescriptor {
|
||||||
pub mutable: bool,
|
pub mutable: bool,
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
//! [`wasmer-clif-backend`]: https://crates.io/crates/wasmer-clif-backend
|
//! [`wasmer-clif-backend`]: https://crates.io/crates/wasmer-clif-backend
|
||||||
//! [`compile_with`]: fn.compile_with.html
|
//! [`compile_with`]: fn.compile_with.html
|
||||||
|
|
||||||
|
pub use wasmer_runtime_core::export::Export;
|
||||||
pub use wasmer_runtime_core::global::Global;
|
pub use wasmer_runtime_core::global::Global;
|
||||||
pub use wasmer_runtime_core::import::ImportObject;
|
pub use wasmer_runtime_core::import::ImportObject;
|
||||||
pub use wasmer_runtime_core::instance::{DynFunc, Instance};
|
pub use wasmer_runtime_core::instance::{DynFunc, Instance};
|
||||||
@ -95,7 +96,9 @@ pub mod wasm {
|
|||||||
//! Various types exposed by the Wasmer Runtime.
|
//! Various types exposed by the Wasmer Runtime.
|
||||||
pub use wasmer_runtime_core::global::Global;
|
pub use wasmer_runtime_core::global::Global;
|
||||||
pub use wasmer_runtime_core::table::Table;
|
pub use wasmer_runtime_core::table::Table;
|
||||||
pub use wasmer_runtime_core::types::{FuncSig, MemoryDescriptor, TableDescriptor, Type, Value};
|
pub use wasmer_runtime_core::types::{
|
||||||
|
FuncSig, GlobalDescriptor, MemoryDescriptor, TableDescriptor, Type, Value,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod error {
|
pub mod error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user