diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-10-03 13:02:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-03 13:02:11 -0700 |
commit | eab1c956d2dbdcc83a861c94f95662bfc0af38cc (patch) | |
tree | ddf4151e595bd36cf9dc26ac9b7e3a54a8a32883 /src/wasm-validator.h | |
parent | 08136f5d7fd042539e69f9a330f2e55d28b738b9 (diff) | |
download | binaryen-eab1c956d2dbdcc83a861c94f95662bfc0af38cc.tar.gz binaryen-eab1c956d2dbdcc83a861c94f95662bfc0af38cc.tar.bz2 binaryen-eab1c956d2dbdcc83a861c94f95662bfc0af38cc.zip |
Document and clean up validation options (#730)
* document and clean up validation options
Diffstat (limited to 'src/wasm-validator.h')
-rw-r--r-- | src/wasm-validator.h | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/wasm-validator.h b/src/wasm-validator.h index d741fafdc..36dc6ad04 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -17,6 +17,22 @@ // // Simple WebAssembly module validator. // +// There are some options regarding how to validate: +// +// * validateWeb: The Web platform doesn't have i64 values, so it is illegal +// to import or export such a value. When this option is set, +// such imports/exports are validation errors. +// +// * validateGlobally: Binaryen supports building modules in parallel, which +// means you can add and optimize a function before the +// module is complete, for example, you can add function A +// with a call to function B before function B exists. +// When validateGlobally is disabled, we don't look at +// global correctness, and instead only check inside +// each function (so in the example above we wouldn't care +// about function B not existing yet, but we would care +// if e.g. inside function A an i32.add receives an i64). +// #ifndef wasm_wasm_validator_h #define wasm_wasm_validator_h @@ -28,6 +44,8 @@ namespace wasm { struct WasmValidator : public PostWalker<WasmValidator, Visitor<WasmValidator>> { bool valid = true; + + // what to validate, see comment up top bool validateWeb = false; bool validateGlobally = true; @@ -342,23 +360,27 @@ public: } void visitImport(Import* curr) { - if (!validateWeb) return; if (!validateGlobally) return; if (curr->kind == Import::Function) { - shouldBeUnequal(curr->functionType->result, i64, curr->name, "Imported function must not have i64 return type"); - for (WasmType param : curr->functionType->params) { - shouldBeUnequal(param, i64, curr->name, "Imported function must not have i64 parameters"); + if (validateWeb) { + shouldBeUnequal(curr->functionType->result, i64, curr->name, "Imported function must not have i64 return type"); + for (WasmType param : curr->functionType->params) { + shouldBeUnequal(param, i64, curr->name, "Imported function must not have i64 parameters"); + } } } } void visitExport(Export* curr) { - if (!validateWeb) return; if (!validateGlobally) return; - Function* f = getModule()->getFunction(curr->value); - shouldBeUnequal(f->result, i64, f->name, "Exported function must not have i64 return type"); - for (auto param : f->params) { - shouldBeUnequal(param, i64, f->name, "Exported function must not have i64 parameters"); + if (curr->kind == Export::Function) { + if (validateWeb) { + Function* f = getModule()->getFunction(curr->value); + shouldBeUnequal(f->result, i64, f->name, "Exported function must not have i64 return type"); + for (auto param : f->params) { + shouldBeUnequal(param, i64, f->name, "Exported function must not have i64 parameters"); + } + } } } |