Skip to content

Commit

Permalink
Merge #360
Browse files Browse the repository at this point in the history
360: Single-pass fixes and optimizations. r=syrusakbary a=losfair



Co-authored-by: losfair <zhy20000919@hotmail.com>
Co-authored-by: Lachlan Sneff <lachlan.sneff@gmail.com>
  • Loading branch information
3 people committed Apr 18, 2019
2 parents 6c158a9 + 016535c commit ccad887
Show file tree
Hide file tree
Showing 4 changed files with 373 additions and 323 deletions.
20 changes: 19 additions & 1 deletion lib/singlepass-backend/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,40 @@ use wasmparser::{Operator, Type as WpType};

pub trait ModuleCodeGenerator<FCG: FunctionCodeGenerator, RM: RunnableModule> {
fn check_precondition(&mut self, module_info: &ModuleInfo) -> Result<(), CodegenError>;

/// Creates a new function and returns the function-scope code generator for it.
fn next_function(&mut self) -> Result<&mut FCG, CodegenError>;
fn finalize(self, module_info: &ModuleInfo) -> Result<RM, CodegenError>;
fn feed_signatures(&mut self, signatures: Map<SigIndex, FuncSig>) -> Result<(), CodegenError>;

/// Sets function signatures.
fn feed_function_signatures(
&mut self,
assoc: Map<FuncIndex, SigIndex>,
) -> Result<(), CodegenError>;

/// Adds an import function.
fn feed_import_function(&mut self) -> Result<(), CodegenError>;
}

/// The function-scope code generator trait.
pub trait FunctionCodeGenerator {
/// Sets the return type.
fn feed_return(&mut self, ty: WpType) -> Result<(), CodegenError>;

/// Adds a parameter to the function.
fn feed_param(&mut self, ty: WpType) -> Result<(), CodegenError>;

/// Adds `n` locals to the function.
fn feed_local(&mut self, ty: WpType, n: usize) -> Result<(), CodegenError>;

/// Called before the first call to `feed_opcode`.
fn begin_body(&mut self) -> Result<(), CodegenError>;
fn feed_opcode(&mut self, op: Operator, module_info: &ModuleInfo) -> Result<(), CodegenError>;

/// Called for each operator.
fn feed_opcode(&mut self, op: &Operator, module_info: &ModuleInfo) -> Result<(), CodegenError>;

/// Finalizes the function.
fn finalize(&mut self) -> Result<(), CodegenError>;
}

Expand Down
Loading

0 comments on commit ccad887

Please sign in to comment.