Skip to content

Commit bbf663a

Browse files
authored
Merge branch 'master' into feature/wasi
2 parents 2686322 + 0d8a190 commit bbf663a

File tree

14 files changed

+123
-170
lines changed

14 files changed

+123
-170
lines changed

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Please select your operating system:
7070

7171
- [macOS](#macos)
7272
- [Debian-based Linuxes](#debian-based-linuxes)
73+
- [FreeBSD](#freebsd)
7374
- [Microsoft Windows](#windows-msvc)
7475

7576
#### macOS
@@ -92,6 +93,12 @@ sudo port install cmake
9293
sudo apt install cmake
9394
```
9495

96+
#### FreeBSD
97+
98+
```sh
99+
pkg install cmake
100+
```
101+
95102
#### Windows (MSVC)
96103

97104
Windows support is _highly experimental_. Only simple Wasm programs may be run, and no syscalls are allowed. This means

Diff for: lib/emscripten/src/emscripten_target.rs

+49
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ pub fn _pthread_cond_destroy(_ctx: &mut Ctx, _a: i32) -> i32 {
118118
debug!("emscripten::_pthread_cond_destroy");
119119
0
120120
}
121+
pub fn _pthread_getspecific(_ctx: &mut Ctx, _a: i32) -> i32 {
122+
debug!("emscripten::_pthread_getspecific");
123+
0
124+
}
125+
pub fn _pthread_setspecific(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
126+
debug!("emscripten::_pthread_setspecific");
127+
0
128+
}
129+
pub fn _pthread_once(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
130+
debug!("emscripten::_pthread_once");
131+
0
132+
}
133+
pub fn _pthread_key_create(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
134+
debug!("emscripten::_pthread_key_create");
135+
0
136+
}
121137
pub fn _pthread_create(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 {
122138
debug!("emscripten::_pthread_create");
123139
0
@@ -424,6 +440,30 @@ pub fn invoke_viiiiiiiii(
424440
panic!("dyn_call_viiiiiiiii is set to None");
425441
}
426442
}
443+
pub fn invoke_viiiiiiiiii(
444+
ctx: &mut Ctx,
445+
index: i32,
446+
a1: i32,
447+
a2: i32,
448+
a3: i32,
449+
a4: i32,
450+
a5: i32,
451+
a6: i32,
452+
a7: i32,
453+
a8: i32,
454+
a9: i32,
455+
a10: i32,
456+
) {
457+
debug!("emscripten::invoke_viiiiiiiiii");
458+
if let Some(dyn_call_viiiiiiiiii) = &get_emscripten_data(ctx).dyn_call_viiiiiiiiii {
459+
dyn_call_viiiiiiiiii
460+
.call(index, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
461+
.unwrap();
462+
} else {
463+
panic!("dyn_call_viiiiiiiiii is set to None");
464+
}
465+
}
466+
427467
pub fn invoke_iiji(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) -> i32 {
428468
debug!("emscripten::invoke_iiji");
429469
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 {
448488
panic!("dyn_call_ji is set to None");
449489
}
450490
}
491+
pub fn invoke_jii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32) -> i32 {
492+
debug!("emscripten::invoke_jii");
493+
if let Some(dyn_call_jii) = &get_emscripten_data(ctx).dyn_call_jii {
494+
dyn_call_jii.call(index, a1, a2).unwrap()
495+
} else {
496+
panic!("dyn_call_jii is set to None");
497+
}
498+
}
499+
451500
pub fn invoke_jij(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32) -> i32 {
452501
debug!("emscripten::invoke_jij");
453502
if let Some(dyn_call_jij) = &get_emscripten_data(ctx).dyn_call_jij {

Diff for: lib/emscripten/src/exception.rs

+9
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ pub fn ___cxa_throw(ctx: &mut Ctx, _ptr: u32, _ty: u32, _destructor: u32) {
1414
debug!("emscripten::___cxa_throw");
1515
_abort(ctx);
1616
}
17+
18+
pub fn ___cxa_begin_catch(_ctx: &mut Ctx, _exception_object_ptr: u32) -> i32 {
19+
debug!("emscripten::___cxa_begin_catch");
20+
-1
21+
}
22+
23+
pub fn ___cxa_end_catch(_ctx: &mut Ctx) {
24+
debug!("emscripten::___cxa_end_catch");
25+
}

Diff for: lib/emscripten/src/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,12 @@ pub struct EmscriptenData<'a> {
104104
pub dyn_call_viiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32)>>,
105105
pub dyn_call_viiiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
106106
pub dyn_call_viiiiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
107+
pub dyn_call_viiiiiiiiii:
108+
Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32)>>,
107109
pub dyn_call_iiji: Option<Func<'a, (i32, i32, i32, i32, i32), i32>>,
108110
pub dyn_call_j: Option<Func<'a, i32, i32>>,
109111
pub dyn_call_ji: Option<Func<'a, (i32, i32), i32>>,
112+
pub dyn_call_jii: Option<Func<'a, (i32, i32, i32), i32>>,
110113
pub dyn_call_jij: Option<Func<'a, (i32, i32, i32, i32), i32>>,
111114
pub dyn_call_jjj: Option<Func<'a, (i32, i32, i32, i32, i32), i32>>,
112115
pub dyn_call_viiij: Option<Func<'a, (i32, i32, i32, i32, i32, i32)>>,
@@ -160,9 +163,11 @@ impl<'a> EmscriptenData<'a> {
160163
let dyn_call_viiiiiii = instance.func("dynCall_viiiiiii").ok();
161164
let dyn_call_viiiiiiii = instance.func("dynCall_viiiiiiii").ok();
162165
let dyn_call_viiiiiiiii = instance.func("dynCall_viiiiiiiii").ok();
166+
let dyn_call_viiiiiiiiii = instance.func("dynCall_viiiiiiiiii").ok();
163167
let dyn_call_iiji = instance.func("dynCall_iiji").ok();
164168
let dyn_call_j = instance.func("dynCall_j").ok();
165169
let dyn_call_ji = instance.func("dynCall_ji").ok();
170+
let dyn_call_jii = instance.func("dynCall_jii").ok();
166171
let dyn_call_jij = instance.func("dynCall_jij").ok();
167172
let dyn_call_jjj = instance.func("dynCall_jjj").ok();
168173
let dyn_call_viiij = instance.func("dynCall_viiij").ok();
@@ -209,9 +214,11 @@ impl<'a> EmscriptenData<'a> {
209214
dyn_call_viiiiiii,
210215
dyn_call_viiiiiiii,
211216
dyn_call_viiiiiiiii,
217+
dyn_call_viiiiiiiiii,
212218
dyn_call_iiji,
213219
dyn_call_j,
214220
dyn_call_ji,
221+
dyn_call_jii,
215222
dyn_call_jij,
216223
dyn_call_jjj,
217224
dyn_call_viiij,
@@ -562,6 +569,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
562569
"_kill" => func!(crate::process::_kill),
563570
"_llvm_stackrestore" => func!(crate::process::_llvm_stackrestore),
564571
"_llvm_stacksave" => func!(crate::process::_llvm_stacksave),
572+
"_llvm_eh_typeid_for" => func!(crate::process::_llvm_eh_typeid_for),
565573
"_raise" => func!(crate::process::_raise),
566574
"_sem_init" => func!(crate::process::_sem_init),
567575
"_sem_post" => func!(crate::process::_sem_post),
@@ -597,6 +605,8 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
597605
// Exception
598606
"___cxa_allocate_exception" => func!(crate::exception::___cxa_allocate_exception),
599607
"___cxa_throw" => func!(crate::exception::___cxa_throw),
608+
"___cxa_begin_catch" => func!(crate::exception::___cxa_begin_catch),
609+
"___cxa_end_catch" => func!(crate::exception::___cxa_end_catch),
600610

601611
// Time
602612
"_gettimeofday" => func!(crate::time::_gettimeofday),
@@ -675,6 +685,10 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
675685
"_pthread_rwlock_rdlock" => func!(crate::emscripten_target::_pthread_rwlock_rdlock),
676686
"_pthread_rwlock_unlock" => func!(crate::emscripten_target::_pthread_rwlock_unlock),
677687
"_pthread_setcancelstate" => func!(crate::emscripten_target::_pthread_setcancelstate),
688+
"_pthread_getspecific" => func!(crate::emscripten_target::_pthread_getspecific),
689+
"_pthread_setspecific" => func!(crate::emscripten_target::_pthread_setspecific),
690+
"_pthread_once" => func!(crate::emscripten_target::_pthread_once),
691+
"_pthread_key_create" => func!(crate::emscripten_target::_pthread_key_create),
678692
"___gxx_personality_v0" => func!(crate::emscripten_target::___gxx_personality_v0),
679693
"_getdtablesize" => func!(crate::emscripten_target::_getdtablesize),
680694
"_gethostbyaddr" => func!(crate::emscripten_target::_gethostbyaddr),
@@ -693,9 +707,12 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
693707
"invoke_viiiiiii" => func!(crate::emscripten_target::invoke_viiiiiii),
694708
"invoke_viiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiii),
695709
"invoke_viiiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiiii),
710+
"invoke_viiiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiiii),
711+
"invoke_viiiiiiiiii" => func!(crate::emscripten_target::invoke_viiiiiiiiii),
696712
"invoke_iiji" => func!(crate::emscripten_target::invoke_iiji),
697713
"invoke_j" => func!(crate::emscripten_target::invoke_j),
698714
"invoke_ji" => func!(crate::emscripten_target::invoke_ji),
715+
"invoke_jii" => func!(crate::emscripten_target::invoke_jii),
699716
"invoke_jij" => func!(crate::emscripten_target::invoke_jij),
700717
"invoke_jjj" => func!(crate::emscripten_target::invoke_jjj),
701718
"invoke_viiij" => func!(crate::emscripten_target::invoke_viiij),

Diff for: lib/emscripten/src/process.rs

+5
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ pub fn _llvm_trap(ctx: &mut Ctx) {
150150
abort_with_message(ctx, "abort!");
151151
}
152152

153+
pub fn _llvm_eh_typeid_for(_ctx: &mut Ctx, _type_info_addr: u32) -> i32 {
154+
debug!("emscripten::_llvm_eh_typeid_for");
155+
-1
156+
}
157+
153158
pub fn _system(_ctx: &mut Ctx, _one: i32) -> c_int {
154159
debug!("emscripten::_system");
155160
// TODO: May need to change this Em impl to a working version

Diff for: lib/llvm-backend/src/backend.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ use wasmer_runtime_core::{
2323
export::Context,
2424
module::{ModuleInfo, ModuleInner},
2525
structures::TypedIndex,
26-
types::{
27-
FuncIndex, FuncSig, LocalFuncIndex, LocalOrImport, MemoryIndex, SigIndex, TableIndex, Type,
28-
Value,
29-
},
26+
types::{FuncIndex, FuncSig, LocalFuncIndex, LocalOrImport, SigIndex, Type, Value},
3027
vm::{self, ImportBacking},
3128
vmcalls,
3229
};
@@ -57,6 +54,7 @@ enum LLVMResult {
5754
OBJECT_LOAD_FAILURE,
5855
}
5956

57+
#[allow(dead_code)]
6058
#[repr(C)]
6159
enum WasmTrapType {
6260
Unreachable = 0,
@@ -220,7 +218,7 @@ pub struct LLVMBackend {
220218
}
221219

222220
impl LLVMBackend {
223-
pub fn new(module: Module, intrinsics: Intrinsics) -> (Self, LLVMProtectedCaller) {
221+
pub fn new(module: Module, _intrinsics: Intrinsics) -> (Self, LLVMProtectedCaller) {
224222
Target::initialize_x86(&InitializationConfig {
225223
asm_parser: true,
226224
asm_printer: true,

Diff for: lib/llvm-backend/src/code.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ use inkwell::{
33
context::Context,
44
module::{Linkage, Module},
55
passes::PassManager,
6-
types::{BasicType, BasicTypeEnum, FunctionType, IntType, PointerType},
6+
types::{BasicType, BasicTypeEnum, FunctionType, PointerType},
77
values::{BasicValue, FloatValue, FunctionValue, IntValue, PhiValue, PointerValue},
88
AddressSpace, FloatPredicate, IntPredicate,
99
};
1010
use smallvec::SmallVec;
1111
use wasmer_runtime_core::{
1212
memory::MemoryType,
13-
module::{ExportIndex, ModuleInfo},
13+
module::ModuleInfo,
1414
structures::{Map, SliceMap, TypedIndex},
1515
types::{
1616
FuncIndex, FuncSig, GlobalIndex, LocalFuncIndex, LocalOrImport, MemoryIndex, SigIndex,
@@ -102,7 +102,6 @@ pub fn parse_function_bodies(
102102

103103
parse_function(
104104
&context,
105-
&module,
106105
&builder,
107106
&intrinsics,
108107
info,
@@ -143,7 +142,6 @@ pub fn parse_function_bodies(
143142

144143
fn parse_function(
145144
context: &Context,
146-
module: &Module,
147145
builder: &Builder,
148146
intrinsics: &Intrinsics,
149147
info: &ModuleInfo,
@@ -155,7 +153,6 @@ fn parse_function(
155153
) -> Result<(), BinaryReaderError> {
156154
let sig_index = info.func_assoc[func_index.convert_up(info)];
157155
let func_sig = &info.signatures[sig_index];
158-
let llvm_sig = &signatures[sig_index];
159156

160157
let function = functions[func_index];
161158
let mut state = State::new();
@@ -193,7 +190,7 @@ fn parse_function(
193190
let param_len = locals.len();
194191

195192
let mut local_idx = 0;
196-
for (index, local) in locals_reader.into_iter().enumerate() {
193+
for local in locals_reader.into_iter() {
197194
let (count, ty) = local?;
198195
let wasmer_ty = type_to_type(ty)?;
199196
let ty = type_to_llvm(intrinsics, wasmer_ty);
@@ -490,7 +487,6 @@ fn parse_function(
490487
if let ControlFrame::IfElse {
491488
if_else,
492489
next,
493-
phis,
494490
if_else_state,
495491
..
496492
} = &frame
@@ -866,7 +862,7 @@ fn parse_function(
866862
let value = call_site.try_as_basic_value().left().unwrap();
867863
state.push1(value);
868864
}
869-
returns @ _ => unimplemented!("multi-value returns"),
865+
_ => unimplemented!("multi-value returns"),
870866
}
871867
}
872868

@@ -2158,7 +2154,7 @@ fn parse_function(
21582154
[one_value] => {
21592155
builder.build_return(Some(one_value));
21602156
}
2161-
returns @ _ => {
2157+
_ => {
21622158
// let struct_ty = llvm_sig.get_return_type().as_struct_type();
21632159
// let ret_struct = struct_ty.const_zero();
21642160
unimplemented!("multi-value returns not yet implemented")
@@ -2211,7 +2207,7 @@ fn trap_if_not_representatable_as_int(
22112207
),
22122208
};
22132209

2214-
let masked = builder.build_and(
2210+
builder.build_and(
22152211
float_bits,
22162212
int_ty.const_int(exponent_mask, false),
22172213
"masked_bits",

Diff for: lib/llvm-backend/src/example.rs

-61
This file was deleted.

0 commit comments

Comments
 (0)