mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-07-01 23:41:38 +00:00
non-determinism checker initial impl
wip
This commit is contained in:
2
non_determinism_checker/.gitignore
vendored
Normal file
2
non_determinism_checker/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
target
|
||||||
|
Cargo.lock
|
9
non_determinism_checker/Cargo.toml
Normal file
9
non_determinism_checker/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "wasm-pack"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["NikVolf <nikvolf@gmail.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
parity-wasm = "0.14"
|
||||||
|
wasm-utils = { path = "../" }
|
||||||
|
clap = "2.24"
|
26
non_determinism_checker/src/main.rs
Normal file
26
non_determinism_checker/src/main.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
extern crate parity_wasm;
|
||||||
|
extern crate wasm_utils;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
|
||||||
|
wasm_utils::init_log();
|
||||||
|
|
||||||
|
let args = env::args().collect::<Vec<_>>();
|
||||||
|
if args.len() != 2 {
|
||||||
|
println!("Usage: {} input_file.wasm", args[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loading module
|
||||||
|
let module = parity_wasm::deserialize_file(&args[1]).expect("Module deserialization to succeed");
|
||||||
|
|
||||||
|
if wasm_utils::have_non_determinism(module) {
|
||||||
|
println!("Yes");
|
||||||
|
} else {
|
||||||
|
println!("No");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -11,9 +11,11 @@ mod symbols;
|
|||||||
mod logger;
|
mod logger;
|
||||||
mod ext;
|
mod ext;
|
||||||
mod pack;
|
mod pack;
|
||||||
|
mod non_determinism_checker;
|
||||||
|
|
||||||
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 non_determinism_checker::have_non_determinism;
|
||||||
|
101
src/non_determinism_checker.rs
Normal file
101
src/non_determinism_checker.rs
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
use parity_wasm::{elements};
|
||||||
|
use parity_wasm::elements::Section;
|
||||||
|
use parity_wasm::elements::Opcode::*;
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// fn check_code (FuncBodybody) -> bool {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
pub fn have_non_determinism(module: elements::Module) -> bool {
|
||||||
|
|
||||||
|
for section in module.sections() {
|
||||||
|
match *section {
|
||||||
|
Section::Code(ref cs) => {
|
||||||
|
for body in cs.bodies() {
|
||||||
|
for opcode in body.code().elements() {
|
||||||
|
match *opcode {
|
||||||
|
F32Abs |
|
||||||
|
F32Neg |
|
||||||
|
F32Ceil |
|
||||||
|
F32Floor |
|
||||||
|
F32Trunc |
|
||||||
|
F32Nearest |
|
||||||
|
F32Sqrt |
|
||||||
|
F32Add |
|
||||||
|
F32Sub |
|
||||||
|
F32Mul |
|
||||||
|
F32Div |
|
||||||
|
F32Min |
|
||||||
|
F32Max |
|
||||||
|
F32Copysign |
|
||||||
|
F64Abs |
|
||||||
|
F64Neg |
|
||||||
|
F64Ceil |
|
||||||
|
F64Floor |
|
||||||
|
F64Trunc |
|
||||||
|
F64Nearest |
|
||||||
|
F64Sqrt |
|
||||||
|
F64Add |
|
||||||
|
F64Sub |
|
||||||
|
F64Mul |
|
||||||
|
F64Div |
|
||||||
|
F64Min |
|
||||||
|
F64Max |
|
||||||
|
F64Copysign |
|
||||||
|
I32TruncSF32 |
|
||||||
|
I32TruncUF32 |
|
||||||
|
I32TruncSF64 |
|
||||||
|
I32TruncUF64 |
|
||||||
|
I64TruncSF32 |
|
||||||
|
I64TruncUF32 |
|
||||||
|
I64TruncSF64 |
|
||||||
|
I64TruncUF64 |
|
||||||
|
F32ConvertSI32 |
|
||||||
|
F32ConvertUI32 |
|
||||||
|
F32ConvertSI64 |
|
||||||
|
F32ConvertUI64 |
|
||||||
|
F32DemoteF64 |
|
||||||
|
F64ConvertSI32 |
|
||||||
|
F64ConvertUI32 |
|
||||||
|
F64ConvertSI64 |
|
||||||
|
F64ConvertUI64 |
|
||||||
|
F64PromoteF32 |
|
||||||
|
I32ReinterpretF32 |
|
||||||
|
I64ReinterpretF64 |
|
||||||
|
F32ReinterpretI32 |
|
||||||
|
F64ReinterpretI64 |
|
||||||
|
F32Eq |
|
||||||
|
F32Ne |
|
||||||
|
F32Lt |
|
||||||
|
F32Gt |
|
||||||
|
F32Le |
|
||||||
|
F32Ge |
|
||||||
|
F64Eq |
|
||||||
|
F64Ne |
|
||||||
|
F64Lt |
|
||||||
|
F64Gt |
|
||||||
|
F64Le |
|
||||||
|
F64Ge
|
||||||
|
=> {
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
_ => continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
_ => continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use parity_wasm::{builder, elements};
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user