diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-validator.h | 14 | ||||
-rw-r--r-- | src/wasm.h | 2 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 29 |
3 files changed, 29 insertions, 16 deletions
diff --git a/src/wasm-validator.h b/src/wasm-validator.h index 29787a510..b657b67a6 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -390,15 +390,7 @@ public: } void visitUnary(Unary *curr) { shouldBeUnequal(curr->value->type, none, curr, "unaries must not receive a none as their input"); - switch (curr->op) { - case EqZInt32: - case EqZInt64: { - shouldBeEqual(curr->type, i32, curr, "eqz must return i32"); - break; - } - default: {} - } - if (curr->value->type == unreachable) return; + if (curr->value->type == unreachable) return; // nothing to check switch (curr->op) { case ClzInt32: case CtzInt32: @@ -420,9 +412,7 @@ public: case TruncFloat64: case NearestFloat64: case SqrtFloat64: { - if (curr->value->type != unreachable) { - shouldBeEqual(curr->value->type, curr->type, curr, "non-conversion unaries must return the same type"); - } + shouldBeEqual(curr->value->type, curr->type, curr, "non-conversion unaries must return the same type"); break; } case EqZInt32: { diff --git a/src/wasm.h b/src/wasm.h index 4804322b6..b23dab918 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -299,6 +299,8 @@ public: Name default_; Expression* condition; Expression* value; + + void finalize(); }; class Call : public SpecificExpression<Expression::CallId> { diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 36eff681f..96ca8fbc8 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -248,7 +248,9 @@ void Loop::finalize() { void Break::finalize() { if (condition) { - if (value) { + if (condition->type == unreachable) { + type = unreachable; + } else if (value) { type = value->type; } else { type = none; @@ -258,6 +260,10 @@ void Break::finalize() { } } +void Switch::finalize() { + type = unreachable; +} + bool FunctionType::structuralComparison(FunctionType& b) { if (result != b.result) return false; if (params.size() != b.params.size()) return false; @@ -286,6 +292,11 @@ void SetLocal::setTee(bool is) { void Store::finalize() { assert(valueType != none); // must be set + if (ptr->type == unreachable || value->type == unreachable) { + type = unreachable; + } else { + type = none; + } } Const* Const::set(Literal value_) { @@ -299,6 +310,10 @@ bool Unary::isRelational() { } void Unary::finalize() { + if (value->type == unreachable) { + type = unreachable; + return; + } switch (op) { case ClzInt32: case CtzInt32: @@ -390,16 +405,22 @@ bool Binary::isRelational() { void Binary::finalize() { assert(left && right); - if (isRelational()) { + if (left->type == unreachable || right->type == unreachable) { + type = unreachable; + } else if (isRelational()) { type = i32; } else { - type = getReachableWasmType(left->type, right->type); + type = left->type; } } void Select::finalize() { assert(ifTrue && ifFalse); - type = getReachableWasmType(ifTrue->type, ifFalse->type); + if (ifTrue->type == unreachable || ifFalse->type == unreachable || condition->type == unreachable) { + type = unreachable; + } else { + type = ifTrue->type; + } } void Host::finalize() { |