remame indeterminism

This commit is contained in:
fro
2017-09-21 12:44:08 +03:00
parent 6aa896e9fe
commit da265f3671
6 changed files with 21 additions and 21 deletions

View File

@ -34,5 +34,5 @@ name = "wasm-build"
path = "build/src/main.rs"
[[bin]]
name = "indeterminism-check"
path = "indeterminism_check/src/main.rs"
name = "nondeterminism-check"
path = "nondeterminism_check/src/main.rs"

View File

@ -1,5 +1,5 @@
[package]
name = "indeterminism_check"
name = "nondeterminism_check"
version = "0.1.0"
authors = ["NikVolf <nikvolf@gmail.com>"]

View File

@ -17,10 +17,10 @@ fn main() {
// Loading module
let module = parity_wasm::deserialize_file(&args[1]).expect("Module deserialization to succeed");
if wasm_utils::have_indeterminism(module) {
println!("Non-determinism found");
if wasm_utils::is_deterministic(module) {
println!("Module is deterministic");
} else {
println!("Non-determinism not found");
println!("Module is not deterministic");
}
}

View File

@ -11,11 +11,11 @@ mod symbols;
mod logger;
mod ext;
mod pack;
mod indeterminism_check;
mod nondeterminism_check;
pub use optimizer::{optimize, Error as OptimizerError};
pub use gas::inject_gas_counter;
pub use logger::init_log;
pub use ext::externalize;
pub use pack::pack_instance;
pub use indeterminism_check::have_indeterminism;
pub use nondeterminism_check::is_deterministic;

View File

@ -2,7 +2,7 @@ use parity_wasm::{elements};
use parity_wasm::elements::{ Section, Opcode };
use parity_wasm::elements::Opcode::*;
fn check_opcodes (opcodes: &[Opcode]) -> bool {
fn have_nondeterministic_opcodes (opcodes: &[Opcode]) -> bool {
for opcode in opcodes {
match *opcode {
F32Abs |
@ -77,34 +77,34 @@ fn check_opcodes (opcodes: &[Opcode]) -> bool {
pub fn have_indeterminism(module: elements::Module) -> bool {
pub fn is_deterministic(module: elements::Module) -> bool {
for section in module.sections() {
match *section {
Section::Code(ref cs) => {
for body in cs.bodies() {
if check_opcodes(body.code().elements()) {
return true;
if have_nondeterministic_opcodes(body.code().elements()) {
return false;
}
}
},
Section::Global(ref global) => {
for entry in global.entries() {
if check_opcodes(entry.init_expr().code()) {
return true;
if have_nondeterministic_opcodes(entry.init_expr().code()) {
return false;
}
}
},
Section::Element(ref element) => {
for entry in element.entries() {
if check_opcodes(entry.offset().code()) {
return true;
if have_nondeterministic_opcodes(entry.offset().code()) {
return false;
}
}
}
_ => continue
}
}
false
true
}
#[cfg(test)]
@ -113,7 +113,7 @@ mod tests {
use super::*;
#[test]
fn indeterminism_found() {
fn nondeterminism_found() {
let module = builder::module()
.function().signature().return_type().f32().build()
.body()
@ -128,11 +128,11 @@ mod tests {
.build()
.build()
.build();
assert_eq!(true, have_indeterminism(module));
assert_eq!(false, is_deterministic(module));
}
#[test]
fn indeterminism_not() {
fn nondeterminism_not() {
let module = builder::module()
.function().signature().return_type().f32().build()
.body()
@ -147,6 +147,6 @@ mod tests {
.build()
.build()
.build();
assert_eq!(false, have_indeterminism(module));
assert_eq!(true, is_deterministic(module));
}
}