2019-02-11 16:52:01 +00:00
|
|
|
#![feature(proc_macro_hygiene)]
|
2019-02-08 15:56:14 +00:00
|
|
|
|
2019-02-11 16:52:01 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate dynasmrt;
|
2019-02-08 15:56:14 +00:00
|
|
|
|
2019-02-11 16:52:01 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate dynasm;
|
2019-02-08 15:56:14 +00:00
|
|
|
|
2019-02-11 16:52:01 +00:00
|
|
|
mod codegen;
|
|
|
|
mod codegen_x64;
|
|
|
|
mod parse;
|
2019-02-12 15:15:57 +00:00
|
|
|
mod stack;
|
2019-02-13 16:53:36 +00:00
|
|
|
|
|
|
|
use std::ptr::NonNull;
|
|
|
|
use wasmer_runtime_core::{
|
|
|
|
backend::{Backend, Compiler, FuncResolver, ProtectedCaller, Token, UserTrapper},
|
|
|
|
error::{CompileError, CompileResult, RuntimeResult},
|
|
|
|
module::{ModuleInfo, ModuleInner, StringTable},
|
|
|
|
structures::{Map, TypedIndex},
|
|
|
|
types::{
|
|
|
|
FuncIndex, FuncSig, GlobalIndex, LocalFuncIndex, MemoryIndex, SigIndex, TableIndex, Type,
|
|
|
|
Value,
|
|
|
|
},
|
|
|
|
vm::{self, ImportBacking},
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Placeholder;
|
|
|
|
|
|
|
|
impl FuncResolver for Placeholder {
|
|
|
|
fn get(
|
|
|
|
&self,
|
|
|
|
_module: &ModuleInner,
|
|
|
|
_local_func_index: LocalFuncIndex,
|
|
|
|
) -> Option<NonNull<vm::Func>> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ProtectedCaller for Placeholder {
|
|
|
|
fn call(
|
|
|
|
&self,
|
|
|
|
_module: &ModuleInner,
|
|
|
|
_func_index: FuncIndex,
|
|
|
|
_params: &[Value],
|
|
|
|
_import_backing: &ImportBacking,
|
|
|
|
_vmctx: *mut vm::Ctx,
|
|
|
|
_: Token,
|
|
|
|
) -> RuntimeResult<Vec<Value>> {
|
|
|
|
Ok(vec![])
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_early_trapper(&self) -> Box<dyn UserTrapper> {
|
|
|
|
pub struct Trapper;
|
|
|
|
|
|
|
|
impl UserTrapper for Trapper {
|
|
|
|
unsafe fn do_early_trap(&self, msg: String) -> ! {
|
|
|
|
panic!("{}", msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Box::new(Trapper)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct SinglePassCompiler {}
|
|
|
|
|
|
|
|
impl Compiler for SinglePassCompiler {
|
|
|
|
fn compile(&self, wasm: &[u8], _: Token) -> CompileResult<ModuleInner> {
|
|
|
|
let mut mcg = codegen_x64::X64ModuleCodeGenerator::new();
|
|
|
|
let info = match parse::read_module(wasm, Backend::Dynasm, &mut mcg) {
|
|
|
|
Ok(x) => x,
|
|
|
|
Err(e) => {
|
|
|
|
return Err(CompileError::InternalError {
|
|
|
|
msg: format!("{:?}", e),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Ok(ModuleInner {
|
|
|
|
func_resolver: Box::new(Placeholder),
|
|
|
|
protected_caller: Box::new(Placeholder),
|
|
|
|
info: info,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|