From 921644ca65afbafb84fb82d58dacc4a028e2d720 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Fri, 17 May 2024 17:49:45 -0700 Subject: 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. --- src/parser/lexer.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/parser/lexer.cpp') 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 #include "lexer.h" +#include "support/bits.h" #include "support/string.h" using namespace std::string_view_literals; @@ -1005,6 +1006,9 @@ std::optional 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; -- cgit v1.2.3