2019-02-24 00:52:32 +08:00
|
|
|
use std::sync::Arc;
|
|
|
|
use wasmer_runtime_core::{
|
|
|
|
backend::ProtectedCaller,
|
|
|
|
structures::Map,
|
|
|
|
types::{FuncIndex, FuncSig, SigIndex},
|
|
|
|
units::Pages,
|
2019-03-09 00:32:18 +08:00
|
|
|
module::ModuleInfo,
|
2019-02-24 00:52:32 +08:00
|
|
|
};
|
2019-02-12 00:51:49 +08:00
|
|
|
use wasmparser::{Operator, Type as WpType};
|
|
|
|
|
2019-02-15 02:21:52 +08:00
|
|
|
pub trait ModuleCodeGenerator<FCG: FunctionCodeGenerator, PC: ProtectedCaller> {
|
2019-02-12 00:51:49 +08:00
|
|
|
fn next_function(&mut self) -> Result<&mut FCG, CodegenError>;
|
2019-02-15 02:21:52 +08:00
|
|
|
fn finalize(self) -> Result<PC, CodegenError>;
|
2019-02-24 00:52:32 +08:00
|
|
|
fn feed_signatures(
|
|
|
|
&mut self,
|
|
|
|
signatures: Map<SigIndex, Arc<FuncSig>>,
|
|
|
|
) -> Result<(), CodegenError>;
|
|
|
|
fn feed_function_signatures(
|
|
|
|
&mut self,
|
|
|
|
assoc: Map<FuncIndex, SigIndex>,
|
|
|
|
) -> Result<(), CodegenError>;
|
2019-03-08 01:31:37 +08:00
|
|
|
fn feed_import_function(&mut self) -> Result<(), CodegenError>;
|
2019-02-12 00:51:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait FunctionCodeGenerator {
|
2019-02-14 00:53:06 +08:00
|
|
|
fn feed_return(&mut self, ty: WpType) -> Result<(), CodegenError>;
|
2019-02-12 00:51:49 +08:00
|
|
|
fn feed_param(&mut self, ty: WpType) -> Result<(), CodegenError>;
|
|
|
|
fn feed_local(&mut self, ty: WpType, n: usize) -> Result<(), CodegenError>;
|
2019-02-12 23:15:57 +08:00
|
|
|
fn begin_body(&mut self) -> Result<(), CodegenError>;
|
2019-03-09 00:32:18 +08:00
|
|
|
fn feed_opcode(&mut self, op: Operator, module_info: &ModuleInfo) -> Result<(), CodegenError>;
|
2019-02-12 00:51:49 +08:00
|
|
|
fn finalize(&mut self) -> Result<(), CodegenError>;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct CodegenError {
|
|
|
|
pub message: &'static str,
|
|
|
|
}
|