summaryrefslogtreecommitdiff
path: root/src/parser/lexer.cpp
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-05-17 17:49:45 -0700
committerGitHub <noreply@github.com>2024-05-17 17:49:45 -0700
commit921644ca65afbafb84fb82d58dacc4a028e2d720 (patch)
tree9253fbcf3f1dd9930dd1b9bc9f545234399b918e /src/parser/lexer.cpp
parent369cddfb44ddbada2ef7742a9ebef54727d12dd5 (diff)
downloadbinaryen-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/parser/lexer.cpp')
-rw-r--r--src/parser/lexer.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/parser/lexer.cpp b/src/parser/lexer.cpp
index fd0a262b8..bb6428e87 100644
--- a/src/parser/lexer.cpp
+++ b/src/parser/lexer.cpp
@@ -23,6 +23,7 @@
#include <variant>
#include "lexer.h"
+#include "support/bits.h"
#include "support/string.h"
using namespace std::string_view_literals;
@@ -1005,6 +1006,9 @@ std::optional<uint32_t> Lexer::takeAlign() {
}
Lexer subLexer(result->span.substr(6));
if (auto o = subLexer.takeU32()) {
+ if (Bits::popCount(*o) != 1) {
+ return std::nullopt;
+ }
pos += result->span.size();
advance();
return o;