diff --git a/src/lib.rs b/src/lib.rs index caa89d1..f8184ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,7 +112,6 @@ extern crate core; #[cfg(test)] extern crate wabt; #[cfg(test)] -#[macro_use] extern crate assert_matches; #[cfg(not(feature = "std"))] diff --git a/src/prepare/compile.rs b/src/prepare/compile.rs index c72d095..441b49d 100644 --- a/src/prepare/compile.rs +++ b/src/prepare/compile.rs @@ -8,7 +8,7 @@ use validation::func::{ }; use validation::stack::StackWithLimit; use validation::util::Locals; -use validation::{Error, FunctionValidator}; +use validation::{Error, FuncValidator}; use isa; @@ -67,7 +67,7 @@ pub struct Compiler { label_stack: Vec, } -impl FunctionValidator for Compiler { +impl FuncValidator for Compiler { type Output = isa::Instructions; fn new(_module: &FunctionValidationContext) -> Self { let mut compiler = Compiler { diff --git a/src/prepare/mod.rs b/src/prepare/mod.rs index e2c2889..1873a79 100644 --- a/src/prepare/mod.rs +++ b/src/prepare/mod.rs @@ -26,7 +26,7 @@ pub struct WasmiValidation { // validation time. impl Validation for WasmiValidation { type Output = Vec; - type FunctionValidator = compile::Compiler; + type FuncValidator = compile::Compiler; fn new(_module: &Module) -> Self { WasmiValidation { // TODO: with capacity? diff --git a/validation/src/func.rs b/validation/src/func.rs index d51a4e8..0976675 100644 --- a/validation/src/func.rs +++ b/validation/src/func.rs @@ -2,7 +2,7 @@ use alloc::prelude::v1::*; use crate::{ - context::ModuleContext, stack::StackWithLimit, util::Locals, Error, FunctionValidator, + context::ModuleContext, stack::StackWithLimit, util::Locals, Error, FuncValidator, DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX, }; @@ -99,7 +99,7 @@ impl PartialEq for ValueType { } } -pub fn drive( +pub fn drive( module: &ModuleContext, func: &Func, body: &FuncBody, diff --git a/validation/src/lib.rs b/validation/src/lib.rs index f9b03dc..1c49bd5 100644 --- a/validation/src/lib.rs +++ b/validation/src/lib.rs @@ -79,17 +79,17 @@ impl From for Error { pub trait Validation { type Output; - type FunctionValidator: FunctionValidator; + type FuncValidator: FuncValidator; fn new(module: &Module) -> Self; fn on_function_validated( &mut self, index: u32, - output: <::FunctionValidator as FunctionValidator>::Output, + output: <::FuncValidator as FuncValidator>::Output, ); fn finish(self) -> Self::Output; } -pub trait FunctionValidator { +pub trait FuncValidator { type Output; fn new(ctx: &func::FunctionValidationContext) -> Self; fn next_instruction( @@ -100,19 +100,19 @@ pub trait FunctionValidator { fn finish(self) -> Self::Output; } -pub struct SimpleValidation; -pub struct SimpleFunctionValidator; +/// A module validator that just validates modules and produces no result. +pub struct PlainValidator; -impl Validation for SimpleValidation { +impl Validation for PlainValidator { type Output = (); - type FunctionValidator = SimpleFunctionValidator; - fn new(_module: &Module) -> SimpleValidation { - SimpleValidation + type FuncValidator = PlainFuncValidator; + fn new(_module: &Module) -> PlainValidator { + PlainValidator } fn on_function_validated( &mut self, _index: u32, - _output: <::FunctionValidator as FunctionValidator>::Output, + _output: <::FuncValidator as FuncValidator>::Output, ) -> () { () } @@ -121,11 +121,14 @@ impl Validation for SimpleValidation { } } -impl FunctionValidator for SimpleFunctionValidator { +/// A function validator that just validates modules and produces no result. +pub struct PlainFuncValidator; + +impl FuncValidator for PlainFuncValidator { type Output = (); - fn new(_ctx: &func::FunctionValidationContext) -> SimpleFunctionValidator { - SimpleFunctionValidator + fn new(_ctx: &func::FunctionValidationContext) -> PlainFuncValidator { + PlainFuncValidator } fn next_instruction( @@ -232,7 +235,7 @@ pub fn validate_module(module: &Module) -> Result(&context, function, function_body) + let output = func::drive::(&context, function, function_body) .map_err(|Error(ref msg)| { Error(format!( "Function #{} reading/validation error: {}", diff --git a/validation/src/tests.rs b/validation/src/tests.rs index adda4c0..2da4598 100644 --- a/validation/src/tests.rs +++ b/validation/src/tests.rs @@ -1,4 +1,4 @@ -use crate::{Error, SimpleValidation}; +use crate::{Error, PlainValidator}; use parity_wasm::builder::module; use parity_wasm::elements::{ BlockType, External, GlobalEntry, GlobalType, ImportEntry, InitExpr, Instruction, Instructions, @@ -6,7 +6,7 @@ use parity_wasm::elements::{ }; fn validate_module(module: &Module) -> Result<(), Error> { - super::validate_module::(module) + super::validate_module::(module) } #[test]