Updates to compile dynasm after merge from master

This commit is contained in:
Brandon Fish
2019-03-12 20:59:10 -05:00
parent 557be77338
commit a5bab8cdf6
4 changed files with 31 additions and 25 deletions

View File

@ -13,7 +13,7 @@ pub trait ModuleCodeGenerator<FCG: FunctionCodeGenerator, PC: ProtectedCaller> {
fn finalize(self) -> Result<PC, CodegenError>; fn finalize(self) -> Result<PC, CodegenError>;
fn feed_signatures( fn feed_signatures(
&mut self, &mut self,
signatures: Map<SigIndex, Arc<FuncSig>>, signatures: Map<SigIndex, FuncSig>,
) -> Result<(), CodegenError>; ) -> Result<(), CodegenError>;
fn feed_function_signatures( fn feed_function_signatures(
&mut self, &mut self,

View File

@ -9,7 +9,7 @@ use dynasmrt::{
use std::cell::RefCell; use std::cell::RefCell;
use std::ptr::NonNull; use std::ptr::NonNull;
use std::sync::Mutex; use std::sync::Mutex;
use std::{collections::HashMap, sync::Arc}; use std::{any::Any, collections::HashMap, sync::Arc};
use wasmer_runtime_core::{ use wasmer_runtime_core::{
backend::{Backend, Compiler, FuncResolver, ProtectedCaller, Token, UserTrapper}, backend::{Backend, Compiler, FuncResolver, ProtectedCaller, Token, UserTrapper},
error::{CompileError, CompileResult, RuntimeError, RuntimeResult}, error::{CompileError, CompileResult, RuntimeError, RuntimeResult},
@ -211,7 +211,7 @@ pub struct NativeTrampolines {
pub struct X64ModuleCodeGenerator { pub struct X64ModuleCodeGenerator {
functions: Vec<X64FunctionCode>, functions: Vec<X64FunctionCode>,
signatures: Option<Arc<Map<SigIndex, Arc<FuncSig>>>>, signatures: Option<Arc<Map<SigIndex, FuncSig>>>,
function_signatures: Option<Arc<Map<FuncIndex, SigIndex>>>, function_signatures: Option<Arc<Map<FuncIndex, SigIndex>>>,
function_labels: Option<HashMap<usize, (DynamicLabel, Option<AssemblyOffset>)>>, function_labels: Option<HashMap<usize, (DynamicLabel, Option<AssemblyOffset>)>>,
assembler: Option<Assembler>, assembler: Option<Assembler>,
@ -220,7 +220,7 @@ pub struct X64ModuleCodeGenerator {
} }
pub struct X64FunctionCode { pub struct X64FunctionCode {
signatures: Arc<Map<SigIndex, Arc<FuncSig>>>, signatures: Arc<Map<SigIndex, FuncSig>>,
function_signatures: Arc<Map<FuncIndex, SigIndex>>, function_signatures: Arc<Map<FuncIndex, SigIndex>>,
native_trampolines: Arc<NativeTrampolines>, native_trampolines: Arc<NativeTrampolines>,
@ -248,7 +248,7 @@ unsafe impl Sync for FuncPtr {}
pub struct X64ExecutionContext { pub struct X64ExecutionContext {
code: ExecutableBuffer, code: ExecutableBuffer,
functions: Vec<X64FunctionCode>, functions: Vec<X64FunctionCode>,
signatures: Arc<Map<SigIndex, Arc<FuncSig>>>, signatures: Arc<Map<SigIndex, FuncSig>>,
function_signatures: Arc<Map<FuncIndex, SigIndex>>, function_signatures: Arc<Map<FuncIndex, SigIndex>>,
function_pointers: Vec<FuncPtr>, function_pointers: Vec<FuncPtr>,
br_table_data: Vec<Vec<usize>>, br_table_data: Vec<Vec<usize>>,
@ -283,7 +283,7 @@ impl ProtectedCaller for X64ExecutionContext {
let return_ty = self.functions[index].returns.last().cloned(); let return_ty = self.functions[index].returns.last().cloned();
if self.functions[index].num_params != _params.len() { if self.functions[index].num_params != _params.len() {
return Err(RuntimeError::User { return Err(RuntimeError::Trap {
msg: "param count mismatch".into(), msg: "param count mismatch".into(),
}); });
} }
@ -306,7 +306,7 @@ impl ProtectedCaller for X64ExecutionContext {
Value::I32(x) => LittleEndian::write_u32(buf, x as u32), Value::I32(x) => LittleEndian::write_u32(buf, x as u32),
Value::F32(x) => LittleEndian::write_u32(buf, f32::to_bits(x)), Value::F32(x) => LittleEndian::write_u32(buf, f32::to_bits(x)),
_ => { _ => {
return Err(RuntimeError::User { return Err(RuntimeError::Trap {
msg: "signature mismatch".into(), msg: "signature mismatch".into(),
}) })
} }
@ -316,7 +316,7 @@ impl ProtectedCaller for X64ExecutionContext {
Value::I64(x) => LittleEndian::write_u64(buf, x as u64), Value::I64(x) => LittleEndian::write_u64(buf, x as u64),
Value::F64(x) => LittleEndian::write_u64(buf, f64::to_bits(x)), Value::F64(x) => LittleEndian::write_u64(buf, f64::to_bits(x)),
_ => { _ => {
return Err(RuntimeError::User { return Err(RuntimeError::Trap {
msg: "signature mismatch".into(), msg: "signature mismatch".into(),
}) })
} }
@ -326,7 +326,7 @@ impl ProtectedCaller for X64ExecutionContext {
let memory_base: *mut u8 = if _module.info.memories.len() > 0 { let memory_base: *mut u8 = if _module.info.memories.len() > 0 {
if _module.info.memories.len() != 1 { if _module.info.memories.len() != 1 {
return Err(RuntimeError::User { return Err(RuntimeError::Trap {
msg: "only one linear memory is supported".into(), msg: "only one linear memory is supported".into(),
}); });
} }
@ -361,8 +361,8 @@ impl ProtectedCaller for X64ExecutionContext {
pub struct Trapper; pub struct Trapper;
impl UserTrapper for Trapper { impl UserTrapper for Trapper {
unsafe fn do_early_trap(&self, msg: String) -> ! { unsafe fn do_early_trap(&self, data: Box<Any>) -> ! {
panic!("{}", msg); panic!("do_early_trap");
} }
} }
@ -521,7 +521,7 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext> for X64ModuleCode
fn feed_signatures( fn feed_signatures(
&mut self, &mut self,
signatures: Map<SigIndex, Arc<FuncSig>>, signatures: Map<SigIndex, FuncSig>,
) -> Result<(), CodegenError> { ) -> Result<(), CodegenError> {
self.signatures = Some(Arc::new(signatures)); self.signatures = Some(Arc::new(signatures));
Ok(()) Ok(())

View File

@ -20,8 +20,8 @@ use crate::codegen::{CodegenError, ModuleCodeGenerator};
use crate::parse::LoadError; use crate::parse::LoadError;
use std::ptr::NonNull; use std::ptr::NonNull;
use wasmer_runtime_core::{ use wasmer_runtime_core::{
backend::{sys::Memory, Backend, Compiler, FuncResolver, ProtectedCaller, Token, UserTrapper}, backend::{sys::Memory, Backend, CacheGen, Compiler, FuncResolver, ProtectedCaller, Token, UserTrapper},
cache::{Cache, Error as CacheError}, cache::{Artifact, Error as CacheError},
error::{CompileError, CompileResult, RuntimeResult}, error::{CompileError, CompileResult, RuntimeResult},
module::{ModuleInfo, ModuleInner, StringTable}, module::{ModuleInfo, ModuleInner, StringTable},
structures::{Map, TypedIndex}, structures::{Map, TypedIndex},
@ -33,6 +33,14 @@ use wasmer_runtime_core::{
}; };
struct Placeholder; struct Placeholder;
impl CacheGen for Placeholder {
fn generate_cache(
&self,
module: &ModuleInner,
) -> Result<(Box<ModuleInfo>, Box<[u8]>, Memory), CacheError> {
unimplemented!()
}
}
impl FuncResolver for Placeholder { impl FuncResolver for Placeholder {
fn get( fn get(
@ -45,6 +53,11 @@ impl FuncResolver for Placeholder {
} }
pub struct SinglePassCompiler {} pub struct SinglePassCompiler {}
impl SinglePassCompiler {
pub fn new() -> Self {
Self {}
}
}
impl Compiler for SinglePassCompiler { impl Compiler for SinglePassCompiler {
fn compile(&self, wasm: &[u8], _: Token) -> CompileResult<ModuleInner> { fn compile(&self, wasm: &[u8], _: Token) -> CompileResult<ModuleInner> {
@ -52,22 +65,15 @@ impl Compiler for SinglePassCompiler {
let info = parse::read_module(wasm, Backend::Dynasm, &mut mcg)?; let info = parse::read_module(wasm, Backend::Dynasm, &mut mcg)?;
let ec = mcg.finalize()?; let ec = mcg.finalize()?;
Ok(ModuleInner { Ok(ModuleInner {
cache_gen: Box::new(Placeholder),
func_resolver: Box::new(Placeholder), func_resolver: Box::new(Placeholder),
protected_caller: Box::new(ec), protected_caller: Box::new(ec),
info: info, info: info,
}) })
} }
unsafe fn from_cache(&self, cache: Cache, _: Token) -> Result<ModuleInner, CacheError> { unsafe fn from_cache(&self, _artifact: Artifact, _: Token) -> Result<ModuleInner, CacheError> {
unimplemented!() unimplemented!("the dynasm backend doesn't support caching yet")
}
fn compile_to_backend_cache_data(
&self,
wasm: &[u8],
_: Token,
) -> CompileResult<(Box<ModuleInfo>, Vec<u8>, Memory)> {
unimplemented!()
} }
} }

View File

@ -87,7 +87,7 @@ pub fn read_module<
for ty in type_reader { for ty in type_reader {
let ty = ty?; let ty = ty?;
info.signatures.push(Arc::new(func_type_to_func_sig(ty)?)); info.signatures.push(func_type_to_func_sig(ty)?);
} }
mcg.feed_signatures(info.signatures.clone())?; mcg.feed_signatures(info.signatures.clone())?;