summaryrefslogtreecommitdiff
path: root/src/wasm-validator.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-10-02 15:19:46 -0700
committerGitHub <noreply@github.com>2016-10-02 15:19:46 -0700
commit926e4ab3c19c0adc965a3b75d9bd2624a4a2b58f (patch)
tree30bb7d06b3b352000443c77069deabe22b92cf37 /src/wasm-validator.h
parent58832ad0b8a197ece6165bfe163f634a21f8bd6d (diff)
downloadbinaryen-926e4ab3c19c0adc965a3b75d9bd2624a4a2b58f.tar.gz
binaryen-926e4ab3c19c0adc965a3b75d9bd2624a4a2b58f.tar.bz2
binaryen-926e4ab3c19c0adc965a3b75d9bd2624a4a2b58f.zip
passRunner debug and validation improvements (#726)
Diffstat (limited to 'src/wasm-validator.h')
-rw-r--r--src/wasm-validator.h20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/wasm-validator.h b/src/wasm-validator.h
index bdc075946..d741fafdc 100644
--- a/src/wasm-validator.h
+++ b/src/wasm-validator.h
@@ -28,7 +28,8 @@ namespace wasm {
struct WasmValidator : public PostWalker<WasmValidator, Visitor<WasmValidator>> {
bool valid = true;
- bool validateWebConstraints = false;
+ bool validateWeb = false;
+ bool validateGlobally = true;
struct BreakInfo {
WasmType type;
@@ -43,8 +44,9 @@ struct WasmValidator : public PostWalker<WasmValidator, Visitor<WasmValidator>>
WasmType returnType = unreachable; // type used in returns
public:
- bool validate(Module& module, bool validateWeb=false) {
- validateWebConstraints = validateWeb;
+ bool validate(Module& module, bool validateWeb_ = false, bool validateGlobally_ = true) {
+ validateWeb = validateWeb_;
+ validateGlobally = validateGlobally_;
walkModule(&module);
if (!valid) {
WasmPrinter::printModule(&module, std::cerr);
@@ -175,6 +177,7 @@ public:
shouldBeTrue(curr->condition->type == unreachable || curr->condition->type == i32, curr, "br_table condition must be i32");
}
void visitCall(Call *curr) {
+ if (!validateGlobally) return;
auto* target = getModule()->checkFunction(curr->target);
if (!shouldBeTrue(!!target, curr, "call target must exist")) return;
if (!shouldBeTrue(curr->operands.size() == target->params.size(), curr, "call param number must match")) return;
@@ -185,8 +188,10 @@ public:
}
}
void visitCallImport(CallImport *curr) {
+ if (!validateGlobally) return;
auto* import = getModule()->checkImport(curr->target);
if (!shouldBeTrue(!!import, curr, "call_import target must exist")) return;
+ if (!shouldBeTrue(import->functionType, curr, "called import must be function")) return;
auto* type = import->functionType;
if (!shouldBeTrue(curr->operands.size() == type->params.size(), curr, "call param number must match")) return;
for (size_t i = 0; i < curr->operands.size(); i++) {
@@ -196,6 +201,7 @@ public:
}
}
void visitCallIndirect(CallIndirect *curr) {
+ if (!validateGlobally) return;
auto* type = getModule()->checkFunctionType(curr->fullType);
if (!shouldBeTrue(!!type, curr, "call_indirect type must exist")) return;
shouldBeEqualOrFirstIsUnreachable(curr->target->type, i32, curr, "indirect call target must be an i32");
@@ -336,7 +342,8 @@ public:
}
void visitImport(Import* curr) {
- if (!validateWebConstraints) return;
+ 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) {
@@ -346,7 +353,8 @@ public:
}
void visitExport(Export* curr) {
- if (!validateWebConstraints) return;
+ 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) {
@@ -355,6 +363,7 @@ public:
}
void visitGlobal(Global* curr) {
+ if (!validateGlobally) return;
shouldBeTrue(curr->init->is<Const>() || curr->init->is<GetGlobal>(), curr->name, "global init must be valid");
shouldBeEqual(curr->type, curr->init->type, nullptr, "global init must have correct type");
}
@@ -402,6 +411,7 @@ public:
}
}
void visitModule(Module *curr) {
+ if (!validateGlobally) return;
// exports
std::set<Name> exportNames;
for (auto& exp : curr->exports) {