Skip to content

Commit

Permalink
Use new wast parser in wasm2js
Browse files Browse the repository at this point in the history
When generating assertions, traverse the `WASTScript` data structure rather than
interleaving assertion parsing with emitting.
  • Loading branch information
tlively committed May 18, 2024
1 parent 921644c commit 99ac5e2
Show file tree
Hide file tree
Showing 48 changed files with 2,627 additions and 2,634 deletions.
3 changes: 1 addition & 2 deletions src/emscripten-optimizer/simple_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
#include "snprintf.h"
#include "support/safe_integer.h"

#define err(str) fprintf(stderr, str "\n");
#define errv(str, ...) fprintf(stderr, str "\n", __VA_ARGS__);
#define printErr err
#define printErr(str) fprintf(stderr, str "\n");

namespace cashew {

Expand Down
8 changes: 6 additions & 2 deletions src/parser/wast-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,15 @@ Result<WASTScript> wast(Lexer& in) {
while (!in.empty()) {
size_t line = in.position().line;
auto cmd = command(in);
if (cmd.getErr() && cmds.empty()) {
if (auto* err = cmd.getErr(); err && cmds.empty()) {
// The entire script might be a single module comprising a sequence of
// module fields with a top-level `(module ...)`.
auto wasm = std::make_shared<Module>();
CHECK_ERR(parseModule(*wasm, in.buffer));
auto parsed = parseModule(*wasm, in.buffer);
if (parsed.getErr()) {
// No, that wasn't the problem. Return the original error.
return Err{err->msg};
}
cmds.push_back({WASTModule{std::move(wasm)}, line});
return cmds;
}
Expand Down
Loading

0 comments on commit 99ac5e2

Please sign in to comment.