This commit is contained in:
Sergey Pepyakin 2019-04-16 14:39:34 +02:00
parent fc36931c06
commit e4dcf553a2
2 changed files with 7 additions and 7 deletions

View File

@ -3,7 +3,7 @@ use alloc::prelude::v1::*;
use crate::{ use crate::{
isa, isa,
validation::{validate_module, Error, Validation}, validation::{validate_module, Error, Validator},
}; };
use parity_wasm::elements::Module; use parity_wasm::elements::Module;
@ -24,7 +24,7 @@ pub struct WasmiValidation {
// This implementation of `Validation` is compiling wasm code at the // This implementation of `Validation` is compiling wasm code at the
// validation time. // validation time.
impl Validation for WasmiValidation { impl Validator for WasmiValidation {
type Output = Vec<isa::Instructions>; type Output = Vec<isa::Instructions>;
type FuncValidator = compile::Compiler; type FuncValidator = compile::Compiler;
fn new(_module: &Module) -> Self { fn new(_module: &Module) -> Self {

View File

@ -69,14 +69,14 @@ impl From<stack::Error> for Error {
} }
} }
pub trait Validation { pub trait Validator {
type Output; type Output;
type FuncValidator: FuncValidator; type FuncValidator: FuncValidator;
fn new(module: &Module) -> Self; fn new(module: &Module) -> Self;
fn on_function_validated( fn on_function_validated(
&mut self, &mut self,
index: u32, index: u32,
output: <<Self as Validation>::FuncValidator as FuncValidator>::Output, output: <<Self as Validator>::FuncValidator as FuncValidator>::Output,
); );
fn finish(self) -> Self::Output; fn finish(self) -> Self::Output;
} }
@ -95,7 +95,7 @@ pub trait FuncValidator {
/// A module validator that just validates modules and produces no result. /// A module validator that just validates modules and produces no result.
pub struct PlainValidator; pub struct PlainValidator;
impl Validation for PlainValidator { impl Validator for PlainValidator {
type Output = (); type Output = ();
type FuncValidator = PlainFuncValidator; type FuncValidator = PlainFuncValidator;
fn new(_module: &Module) -> PlainValidator { fn new(_module: &Module) -> PlainValidator {
@ -104,7 +104,7 @@ impl Validation for PlainValidator {
fn on_function_validated( fn on_function_validated(
&mut self, &mut self,
_index: u32, _index: u32,
_output: <<Self as Validation>::FuncValidator as FuncValidator>::Output, _output: <<Self as Validator>::FuncValidator as FuncValidator>::Output,
) -> () { ) -> () {
() ()
} }
@ -136,7 +136,7 @@ impl FuncValidator for PlainFuncValidator {
} }
} }
pub fn validate_module<V: Validation>(module: &Module) -> Result<V::Output, Error> { pub fn validate_module<V: Validator>(module: &Module) -> Result<V::Output, Error> {
let mut context_builder = ModuleContextBuilder::new(); let mut context_builder = ModuleContextBuilder::new();
let mut imported_globals = Vec::new(); let mut imported_globals = Vec::new();
let mut validation = V::new(&module); let mut validation = V::new(&module);