2019-05-12 11:05:26 -05:00
|
|
|
use crate::signal::Caller;
|
2019-05-12 19:16:01 -05:00
|
|
|
use std::sync::Arc;
|
2019-05-12 11:05:26 -05:00
|
|
|
use wasmer_runtime_core::{
|
|
|
|
backend::{Backend, CacheGen, Token},
|
|
|
|
cache::{Artifact, Error as CacheError},
|
|
|
|
codegen::*,
|
|
|
|
module::{ModuleInfo, ModuleInner},
|
|
|
|
structures::Map,
|
|
|
|
types::{FuncIndex, FuncSig, SigIndex},
|
|
|
|
};
|
|
|
|
use wasmparser::Type as WpType;
|
|
|
|
|
2019-05-12 19:16:01 -05:00
|
|
|
pub struct CraneliftModuleCodeGenerator {
|
|
|
|
signatures: Option<Arc<Map<SigIndex, FuncSig>>>,
|
|
|
|
function_signatures: Option<Arc<Map<FuncIndex, SigIndex>>>,
|
|
|
|
functions: Vec<CraneliftFunctionCodeGenerator>,
|
|
|
|
}
|
2019-05-12 11:05:26 -05:00
|
|
|
|
|
|
|
impl ModuleCodeGenerator<CraneliftFunctionCodeGenerator, Caller, CodegenError>
|
|
|
|
for CraneliftModuleCodeGenerator
|
|
|
|
{
|
|
|
|
fn new() -> Self {
|
2019-05-12 19:16:01 -05:00
|
|
|
CraneliftModuleCodeGenerator {
|
|
|
|
functions: vec![],
|
|
|
|
function_signatures: None,
|
|
|
|
signatures: None,
|
|
|
|
}
|
2019-05-12 11:05:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn backend_id() -> Backend {
|
2019-05-12 19:16:01 -05:00
|
|
|
Backend::Cranelift
|
2019-05-12 11:05:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn check_precondition(&mut self, _module_info: &ModuleInfo) -> Result<(), CodegenError> {
|
2019-05-12 19:16:01 -05:00
|
|
|
Ok(())
|
2019-05-12 11:05:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn next_function(&mut self) -> Result<&mut CraneliftFunctionCodeGenerator, CodegenError> {
|
2019-05-12 19:16:01 -05:00
|
|
|
let code = CraneliftFunctionCodeGenerator {};
|
|
|
|
self.functions.push(code);
|
|
|
|
Ok(self.functions.last_mut().unwrap())
|
2019-05-12 11:05:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn finalize(
|
|
|
|
self,
|
|
|
|
_module_info: &ModuleInfo,
|
|
|
|
) -> Result<(Caller, Box<dyn CacheGen>), CodegenError> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2019-05-12 19:16:01 -05:00
|
|
|
fn feed_signatures(&mut self, signatures: Map<SigIndex, FuncSig>) -> Result<(), CodegenError> {
|
|
|
|
self.signatures = Some(Arc::new(signatures));
|
|
|
|
Ok(())
|
2019-05-12 11:05:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn feed_function_signatures(
|
|
|
|
&mut self,
|
2019-05-12 19:16:01 -05:00
|
|
|
assoc: Map<FuncIndex, SigIndex>,
|
2019-05-12 11:05:26 -05:00
|
|
|
) -> Result<(), CodegenError> {
|
2019-05-12 19:16:01 -05:00
|
|
|
self.function_signatures = Some(Arc::new(assoc));
|
|
|
|
Ok(())
|
2019-05-12 11:05:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn feed_import_function(&mut self) -> Result<(), CodegenError> {
|
2019-05-12 19:16:01 -05:00
|
|
|
Ok(())
|
2019-05-12 11:05:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn from_cache(_cache: Artifact, _: Token) -> Result<ModuleInner, CacheError> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CraneliftFunctionCodeGenerator {}
|
|
|
|
|
|
|
|
impl FunctionCodeGenerator<CodegenError> for CraneliftFunctionCodeGenerator {
|
|
|
|
fn feed_return(&mut self, _ty: WpType) -> Result<(), CodegenError> {
|
2019-05-12 19:16:01 -05:00
|
|
|
Ok(())
|
2019-05-12 11:05:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn feed_param(&mut self, _ty: WpType) -> Result<(), CodegenError> {
|
2019-05-12 19:16:01 -05:00
|
|
|
Ok(())
|
2019-05-12 11:05:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn feed_local(&mut self, _ty: WpType, _n: usize) -> Result<(), CodegenError> {
|
2019-05-12 19:16:01 -05:00
|
|
|
Ok(())
|
2019-05-12 11:05:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn begin_body(&mut self, _module_info: &ModuleInfo) -> Result<(), CodegenError> {
|
2019-05-12 19:16:01 -05:00
|
|
|
Ok(())
|
2019-05-12 11:05:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn feed_event(&mut self, _op: Event, _module_info: &ModuleInfo) -> Result<(), CodegenError> {
|
2019-05-12 19:16:01 -05:00
|
|
|
Ok(())
|
2019-05-12 11:05:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn finalize(&mut self) -> Result<(), CodegenError> {
|
2019-05-12 19:16:01 -05:00
|
|
|
Ok(())
|
2019-05-12 11:05:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct CodegenError {
|
|
|
|
pub message: String,
|
|
|
|
}
|