2019-02-11 16:52:01 +00:00
|
|
|
#![feature(proc_macro_hygiene)]
|
2019-02-08 15:56:14 +00:00
|
|
|
|
2019-03-17 02:27:14 +00:00
|
|
|
#[cfg(not(any(
|
|
|
|
all(target_os = "macos", target_arch = "x86_64"),
|
|
|
|
all(target_os = "linux", target_arch = "x86_64"),
|
|
|
|
)))]
|
|
|
|
compile_error!("This crate doesn't yet support compiling on operating systems other than linux and macos and architectures other than x86_64");
|
|
|
|
|
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-23 16:52:32 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
|
|
|
|
extern crate byteorder;
|
|
|
|
|
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-03-17 02:27:14 +00:00
|
|
|
mod protect_unix;
|
2019-02-13 16:53:36 +00:00
|
|
|
|
2019-02-14 18:21:52 +00:00
|
|
|
use crate::codegen::{CodegenError, ModuleCodeGenerator};
|
|
|
|
use crate::parse::LoadError;
|
2019-02-13 16:53:36 +00:00
|
|
|
use std::ptr::NonNull;
|
|
|
|
use wasmer_runtime_core::{
|
2019-03-13 01:59:10 +00:00
|
|
|
backend::{sys::Memory, Backend, CacheGen, Compiler, FuncResolver, ProtectedCaller, Token, UserTrapper},
|
|
|
|
cache::{Artifact, Error as CacheError},
|
2019-02-13 16:53:36 +00:00
|
|
|
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;
|
2019-03-13 01:59:10 +00:00
|
|
|
impl CacheGen for Placeholder {
|
|
|
|
fn generate_cache(
|
|
|
|
&self,
|
|
|
|
module: &ModuleInner,
|
|
|
|
) -> Result<(Box<ModuleInfo>, Box<[u8]>, Memory), CacheError> {
|
2019-03-16 18:52:11 +00:00
|
|
|
// unimplemented!()
|
|
|
|
Err(CacheError::Unknown("the dynasm backend doesn't support caching yet".to_string()))
|
2019-03-13 01:59:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-13 16:53:36 +00:00
|
|
|
|
|
|
|
impl FuncResolver for Placeholder {
|
|
|
|
fn get(
|
|
|
|
&self,
|
|
|
|
_module: &ModuleInner,
|
|
|
|
_local_func_index: LocalFuncIndex,
|
|
|
|
) -> Option<NonNull<vm::Func>> {
|
2019-03-08 18:57:23 +00:00
|
|
|
NonNull::new(0x3f3f3f3f3f3f3f3fusize as *mut vm::Func)
|
2019-02-13 16:53:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct SinglePassCompiler {}
|
2019-03-13 01:59:10 +00:00
|
|
|
impl SinglePassCompiler {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {}
|
|
|
|
}
|
|
|
|
}
|
2019-02-13 16:53:36 +00:00
|
|
|
|
|
|
|
impl Compiler for SinglePassCompiler {
|
|
|
|
fn compile(&self, wasm: &[u8], _: Token) -> CompileResult<ModuleInner> {
|
|
|
|
let mut mcg = codegen_x64::X64ModuleCodeGenerator::new();
|
2019-02-14 18:21:52 +00:00
|
|
|
let info = parse::read_module(wasm, Backend::Dynasm, &mut mcg)?;
|
2019-03-16 19:07:27 +00:00
|
|
|
let (ec, resolver) = mcg.finalize(&info)?;
|
2019-02-13 16:53:36 +00:00
|
|
|
Ok(ModuleInner {
|
2019-03-13 01:59:10 +00:00
|
|
|
cache_gen: Box::new(Placeholder),
|
2019-03-16 19:07:27 +00:00
|
|
|
func_resolver: Box::new(resolver),
|
2019-02-14 18:21:52 +00:00
|
|
|
protected_caller: Box::new(ec),
|
2019-02-13 16:53:36 +00:00
|
|
|
info: info,
|
|
|
|
})
|
|
|
|
}
|
2019-03-13 00:39:10 +00:00
|
|
|
|
2019-03-13 01:59:10 +00:00
|
|
|
unsafe fn from_cache(&self, _artifact: Artifact, _: Token) -> Result<ModuleInner, CacheError> {
|
2019-03-16 18:52:11 +00:00
|
|
|
Err(CacheError::Unknown("the dynasm backend doesn't support caching yet".to_string()))
|
|
|
|
// unimplemented!("the dynasm backend doesn't support caching yet")
|
2019-03-13 00:39:10 +00:00
|
|
|
}
|
2019-02-13 16:53:36 +00:00
|
|
|
}
|
2019-02-14 18:21:52 +00:00
|
|
|
|
|
|
|
impl From<CodegenError> for CompileError {
|
|
|
|
fn from(other: CodegenError) -> CompileError {
|
|
|
|
CompileError::InternalError {
|
|
|
|
msg: other.message.into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<LoadError> for CompileError {
|
|
|
|
fn from(other: LoadError) -> CompileError {
|
|
|
|
CompileError::InternalError {
|
|
|
|
msg: format!("{:?}", other),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|