diff options
author | Thomas Lively <tlively@google.com> | 2024-05-17 17:49:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-17 17:49:45 -0700 |
commit | 921644ca65afbafb84fb82d58dacc4a028e2d720 (patch) | |
tree | 9253fbcf3f1dd9930dd1b9bc9f545234399b918e /src/wasm | |
parent | 369cddfb44ddbada2ef7742a9ebef54727d12dd5 (diff) | |
download | binaryen-921644ca65afbafb84fb82d58dacc4a028e2d720.tar.gz binaryen-921644ca65afbafb84fb82d58dacc4a028e2d720.tar.bz2 binaryen-921644ca65afbafb84fb82d58dacc4a028e2d720.zip |
Rewrite wasm-shell to use new wast parser (#6601)
Use the new wast parser to parse a full script up front, then traverse the
parsed script data structure and execute the commands. wasm-shell had previously
used the new wat parser for top-level modules, but it now uses the new parser
for module assertions as well. Fix various bugs this uncovered.
After this change, wasm-shell supports all the assertions used in the upstream
spec tests (although not new kinds of assertions introduced in any proposals).
Uncomment various `assert_exhaustion` tests that we can now execute.
Other kinds of assertions remain commented out in our tests: wasm-shell now
supports `assert_unlinkable`, but the interpreter does not eagerly check for the
existence of imports, so those tests do not pass. Tests that check for NaNs also
remain commented out because they do not yet use the standard syntax that
wasm-shell now supports for canonical and arithmetic NaN results, and our
interpreter would not pass all of those tests even if they did use the standard
syntax.
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/literal.cpp | 16 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 10 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 2c61be12a..d4e1bfc45 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -467,6 +467,22 @@ bool Literal::isNaN() { return false; } +bool Literal::isCanonicalNaN() { + if (!isNaN()) { + return false; + } + return (type == Type::f32 && NaNPayload(getf32()) == (1u << 23) - 1) || + (type == Type::f64 && NaNPayload(getf64()) == (1ull << 52) - 1); +} + +bool Literal::isArithmeticNaN() { + if (!isNaN()) { + return false; + } + return (type == Type::f32 && NaNPayload(getf32()) > (1u << 23) - 1) || + (type == Type::f64 && NaNPayload(getf64()) > (1ull << 52) - 1); +} + uint32_t Literal::NaNPayload(float f) { assert(std::isnan(f) && "expected a NaN"); // SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index 2eb5369d0..3e215b23a 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -1666,6 +1666,8 @@ std::ostream& operator<<(std::ostream& os, TypeBuilder::ErrorReason reason) { return os << "Heap type has an undeclared supertype"; case TypeBuilder::ErrorReason::ForwardChildReference: return os << "Heap type has an undeclared child"; + case TypeBuilder::ErrorReason::InvalidFuncType: + return os << "Continuation has invalid function type"; } WASM_UNREACHABLE("Unexpected error reason"); } @@ -2616,7 +2618,7 @@ buildRecGroup(std::unique_ptr<RecGroupInfo>&& groupInfo, updateReferencedHeapTypes(info, canonicalized); } - // Collect the types and check supertype validity. + // Collect the types and check validity. std::unordered_set<HeapType> seenTypes; for (size_t i = 0; i < typeInfos.size(); ++i) { auto& info = typeInfos[i]; @@ -2633,6 +2635,12 @@ buildRecGroup(std::unique_ptr<RecGroupInfo>&& groupInfo, TypeBuilder::Error{i, TypeBuilder::ErrorReason::InvalidSupertype}}; } } + if (info->isContinuation()) { + if (!info->continuation.type.isSignature()) { + return { + TypeBuilder::Error{i, TypeBuilder::ErrorReason::InvalidFuncType}}; + } + } seenTypes.insert(asHeapType(info)); } |