wasmer/lib/dynasm-backend/src/lib.rs

72 lines
1.7 KiB
Rust
Raw Normal View History

2019-02-11 16:52:01 +00:00
#![feature(proc_macro_hygiene)]
2019-02-11 16:52:01 +00:00
#[macro_use]
extern crate dynasmrt;
2019-02-11 16:52:01 +00:00
#[macro_use]
extern crate dynasm;
2019-02-11 16:52:01 +00:00
mod codegen;
mod codegen_x64;
mod parse;
mod stack;
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::{
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>> {
2019-02-14 18:21:52 +00:00
panic!();
2019-02-13 16:53:36 +00:00
None
}
}
pub struct SinglePassCompiler {}
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)?;
let ec = mcg.finalize()?;
2019-02-13 16:53:36 +00:00
Ok(ModuleInner {
func_resolver: Box::new(Placeholder),
2019-02-14 18:21:52 +00:00
protected_caller: Box::new(ec),
2019-02-13 16:53:36 +00:00
info: info,
})
}
}
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),
}
}
}