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