Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 10 additions & 53 deletions src/tools/wasm-shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,6 @@ Name INVOKE("invoke");
Name REGISTER("register");
Name GET("get");

struct ShellOptions : public Options {
Name entry;
std::set<size_t> skipped;

const std::string WasmShellOption = "wasm-shell options";

ShellOptions(const std::string& command, const std::string& description)
: Options(command, description) {
(*this)
.add("--entry",
"-e",
"Call the entry point after parsing the module",
WasmShellOption,
Options::Arguments::One,
[this](Options*, const std::string& argument) { entry = argument; })
.add("--skip",
"-s",
"Skip input on certain lines (comma-separated-list)",
WasmShellOption,
Options::Arguments::One,
[this](Options*, const std::string& argument) {
size_t i = 0;
while (i < argument.size()) {
auto ending = argument.find(',', i);
if (ending == std::string::npos) {
ending = argument.size();
}
auto sub = argument.substr(i, ending - i);
skipped.insert(atoi(sub.c_str()));
i = ending + 1;
}
})
.add_positional("INFILE",
Options::Arguments::One,
[](Options* o, const std::string& argument) {
o->extra["infile"] = argument;
});
}
};

class Shell {
protected:
std::map<Name, std::shared_ptr<Module>> modules;
Expand Down Expand Up @@ -320,7 +280,7 @@ class Shell {
}

protected:
ShellOptions& options;
Options& options;

// spectest module is a default host-provided module defined by the spec's
// reference interpreter. It's been replaced by the `(register ...)`
Expand Down Expand Up @@ -376,21 +336,13 @@ class Shell {
}

public:
Shell(ShellOptions& options) : options(options) { buildSpectestModule(); }
Shell(Options& options) : options(options) { buildSpectestModule(); }

bool parseAndRun(Element& root) {
size_t i = 0;
while (i < root.size()) {
Element& curr = *root[i];

if (options.skipped.count(curr.line) > 0) {
Colors::green(std::cerr);
std::cerr << "SKIPPING [line: " << curr.line << "]\n";
Colors::normal(std::cerr);
i++;
continue;
}

if (curr[0]->str() != MODULE) {
Colors::red(std::cerr);
std::cerr << i << '/' << (root.size() - 1);
Expand All @@ -416,11 +368,16 @@ int main(int argc, const char* argv[]) {
Name entry;
std::set<size_t> skipped;

ShellOptions options("wasm-shell", "Execute .wast files");
// Read stdin by default.
std::string infile = "-";
Options options("wasm-shell", "Execute .wast files");
options.add_positional(
"INFILE",
Options::Arguments::One,
[&](Options* o, const std::string& argument) { infile = argument; });
options.parse(argc, argv);

auto input(
read_file<std::vector<char>>(options.extra["infile"], Flags::Text));
auto input = read_file<std::string>(infile, Flags::Text);

bool checked = false;
try {
Expand Down
8 changes: 0 additions & 8 deletions test/lit/help/wasm-shell.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
;; CHECK-NEXT: ================================================================================
;; CHECK-NEXT:
;; CHECK-NEXT:
;; CHECK-NEXT: wasm-shell options:
;; CHECK-NEXT: -------------------
;; CHECK-NEXT:
;; CHECK-NEXT: --entry,-e Call the entry point after parsing the module
;; CHECK-NEXT:
;; CHECK-NEXT: --skip,-s Skip input on certain lines (comma-separated-list)
;; CHECK-NEXT:
;; CHECK-NEXT:
;; CHECK-NEXT: General options:
;; CHECK-NEXT: ----------------
;; CHECK-NEXT:
Expand Down