Crates.io | wain-validate |
lib.rs | wain-validate |
version | 0.1.5 |
source | src |
created_at | 2020-03-29 12:25:24.930258 |
updated_at | 2023-11-18 04:58:30.855441 |
description | WebAssembly syntax tree validator for wain project |
homepage | https://github.com/rhysd/wain/tree/master/wain-validate |
repository | https://github.com/rhysd/wain |
max_upload_size | |
id | 224050 |
size | 52,936 |
wain-validate
is a crate to validate a parsed WebAssembly abstract syntax tree.
Validation logic is defined in spec
This crate is part of larger wain project.
[dependencies]
wain-validate = "0"
It takes a reference to wain_ast::Root
value and validates it. The value can be generated by
wain-syntax-binary
and wain-syntax-text
parsers:
Using wain_validate::validate()
is the easiest way.
extern crate wain_syntax_binary;
extern crate wain_validate;
use std::fs;
use wain_syntax_binary::parse;
use wain_validate::validate;
let source = fs::read("foo.wasm").unwrap();
let tree = parse(&source).unwrap();
if let Err(err) = validate(&tree) {
eprintln!("This .wasm file is invalid!: {}", err);
}
Working examples can be seen at examples/api/ directory
Please read documentation (not yet) for details.
Conforming spec, following things are validated:
select
. Since almost all instructions
are not polymorphic, almost all type checks can be done in validationConforming the spec, wain validates instructions after unreachable
instruction. For example,
(unreachable) (i64.const 0) (i32.add)
i32.add
is invalid because it should take two i32
values from stack but at least one i64
value
is in the stack.