From 924533fbcd0181f4460a13adc5762ee52f97de58 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Mon, 13 May 2024 14:18:01 -0700 Subject: [Parser] Parse wast scripts (#6581) The spec tests use an extension of the standard text format that includes various commands and assertions used to test WebAssembly implementations. Add a utility to parse this extended WebAssembly script format and use it in wasm-shell to check that it parses our spec tests without error. Fix a few errors the new parser found in our spec tests. A future PR will rewrite wasm-shell to interpret the results of the new parser, but for now to keep the diff smaller, do not do anything with the new parser except check for errors. --- src/parser/wat-parser.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/parser/wat-parser.cpp') diff --git a/src/parser/wat-parser.cpp b/src/parser/wat-parser.cpp index fd18fbbe0..2bc222d6b 100644 --- a/src/parser/wat-parser.cpp +++ b/src/parser/wat-parser.cpp @@ -238,7 +238,25 @@ Result parseExpression(Module& wasm, Lexer& lexer) { ParseDefsCtx ctx(lexer, wasm, {}, {}, {}, {}, {}); auto e = expr(ctx); CHECK_ERR(e); + lexer = ctx.in; return *e; } +Result parseConst(Lexer& lexer) { + Module wasm; + ParseDefsCtx ctx(lexer, wasm, {}, {}, {}, {}, {}); + auto inst = foldedinstr(ctx); + CHECK_ERR(inst); + auto expr = ctx.irBuilder.build(); + if (auto* err = expr.getErr()) { + return lexer.err(err->msg); + } + auto* e = *expr; + if (!e->is() && !e->is() && !e->is()) { + return lexer.err("expected constant"); + } + lexer = ctx.in; + return getLiteralFromConstExpression(e); +} + } // namespace wasm::WATParser -- cgit v1.2.3