mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-06-27 13:31:37 +00:00
remame indeterminism
This commit is contained in:
@ -34,5 +34,5 @@ name = "wasm-build"
|
|||||||
path = "build/src/main.rs"
|
path = "build/src/main.rs"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "indeterminism-check"
|
name = "nondeterminism-check"
|
||||||
path = "indeterminism_check/src/main.rs"
|
path = "nondeterminism_check/src/main.rs"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "indeterminism_check"
|
name = "nondeterminism_check"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["NikVolf <nikvolf@gmail.com>"]
|
authors = ["NikVolf <nikvolf@gmail.com>"]
|
||||||
|
|
@ -17,10 +17,10 @@ fn main() {
|
|||||||
// Loading module
|
// Loading module
|
||||||
let module = parity_wasm::deserialize_file(&args[1]).expect("Module deserialization to succeed");
|
let module = parity_wasm::deserialize_file(&args[1]).expect("Module deserialization to succeed");
|
||||||
|
|
||||||
if wasm_utils::have_indeterminism(module) {
|
if wasm_utils::is_deterministic(module) {
|
||||||
println!("Non-determinism found");
|
println!("Module is deterministic");
|
||||||
} else {
|
} else {
|
||||||
println!("Non-determinism not found");
|
println!("Module is not deterministic");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -11,11 +11,11 @@ mod symbols;
|
|||||||
mod logger;
|
mod logger;
|
||||||
mod ext;
|
mod ext;
|
||||||
mod pack;
|
mod pack;
|
||||||
mod indeterminism_check;
|
mod nondeterminism_check;
|
||||||
|
|
||||||
pub use optimizer::{optimize, Error as OptimizerError};
|
pub use optimizer::{optimize, Error as OptimizerError};
|
||||||
pub use gas::inject_gas_counter;
|
pub use gas::inject_gas_counter;
|
||||||
pub use logger::init_log;
|
pub use logger::init_log;
|
||||||
pub use ext::externalize;
|
pub use ext::externalize;
|
||||||
pub use pack::pack_instance;
|
pub use pack::pack_instance;
|
||||||
pub use indeterminism_check::have_indeterminism;
|
pub use nondeterminism_check::is_deterministic;
|
||||||
|
@ -2,7 +2,7 @@ use parity_wasm::{elements};
|
|||||||
use parity_wasm::elements::{ Section, Opcode };
|
use parity_wasm::elements::{ Section, Opcode };
|
||||||
use parity_wasm::elements::Opcode::*;
|
use parity_wasm::elements::Opcode::*;
|
||||||
|
|
||||||
fn check_opcodes (opcodes: &[Opcode]) -> bool {
|
fn have_nondeterministic_opcodes (opcodes: &[Opcode]) -> bool {
|
||||||
for opcode in opcodes {
|
for opcode in opcodes {
|
||||||
match *opcode {
|
match *opcode {
|
||||||
F32Abs |
|
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() {
|
for section in module.sections() {
|
||||||
match *section {
|
match *section {
|
||||||
Section::Code(ref cs) => {
|
Section::Code(ref cs) => {
|
||||||
for body in cs.bodies() {
|
for body in cs.bodies() {
|
||||||
if check_opcodes(body.code().elements()) {
|
if have_nondeterministic_opcodes(body.code().elements()) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Section::Global(ref global) => {
|
Section::Global(ref global) => {
|
||||||
for entry in global.entries() {
|
for entry in global.entries() {
|
||||||
if check_opcodes(entry.init_expr().code()) {
|
if have_nondeterministic_opcodes(entry.init_expr().code()) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Section::Element(ref element) => {
|
Section::Element(ref element) => {
|
||||||
for entry in element.entries() {
|
for entry in element.entries() {
|
||||||
if check_opcodes(entry.offset().code()) {
|
if have_nondeterministic_opcodes(entry.offset().code()) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => continue
|
_ => continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -113,7 +113,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn indeterminism_found() {
|
fn nondeterminism_found() {
|
||||||
let module = builder::module()
|
let module = builder::module()
|
||||||
.function().signature().return_type().f32().build()
|
.function().signature().return_type().f32().build()
|
||||||
.body()
|
.body()
|
||||||
@ -128,11 +128,11 @@ mod tests {
|
|||||||
.build()
|
.build()
|
||||||
.build()
|
.build()
|
||||||
.build();
|
.build();
|
||||||
assert_eq!(true, have_indeterminism(module));
|
assert_eq!(false, is_deterministic(module));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn indeterminism_not() {
|
fn nondeterminism_not() {
|
||||||
let module = builder::module()
|
let module = builder::module()
|
||||||
.function().signature().return_type().f32().build()
|
.function().signature().return_type().f32().build()
|
||||||
.body()
|
.body()
|
||||||
@ -147,6 +147,6 @@ mod tests {
|
|||||||
.build()
|
.build()
|
||||||
.build()
|
.build()
|
||||||
.build();
|
.build();
|
||||||
assert_eq!(false, have_indeterminism(module));
|
assert_eq!(true, is_deterministic(module));
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user