summaryrefslogtreecommitdiff
path: root/src/binaryen-shell.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-12 21:49:04 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-13 18:11:24 -0800
commit97b943c832dd3389b81c0896826977e0c447de28 (patch)
tree466affed0a003bdf5d787d17326c09c5edda7c99 /src/binaryen-shell.cpp
parent06a9c12ea045dfb9b1dd4f4ccf959ac715d4df8a (diff)
downloadbinaryen-97b943c832dd3389b81c0896826977e0c447de28.tar.gz
binaryen-97b943c832dd3389b81c0896826977e0c447de28.tar.bz2
binaryen-97b943c832dd3389b81c0896826977e0c447de28.zip
pass support
Diffstat (limited to 'src/binaryen-shell.cpp')
-rw-r--r--src/binaryen-shell.cpp48
1 files changed, 45 insertions, 3 deletions
diff --git a/src/binaryen-shell.cpp b/src/binaryen-shell.cpp
index e0f524122..4ff93cf2b 100644
--- a/src/binaryen-shell.cpp
+++ b/src/binaryen-shell.cpp
@@ -10,10 +10,15 @@
#include "wasm-s-parser.h"
#include "wasm-interpreter.h"
#include "wasm-validator.h"
+#include "pass.h"
using namespace cashew;
using namespace wasm;
+// Globals
+
+MixedArena globalAllocator;
+
IString ASSERT_RETURN("assert_return"),
ASSERT_TRAP("assert_trap"),
ASSERT_INVALID("assert_invalid"),
@@ -148,18 +153,39 @@ int main(int argc, char **argv) {
char *infile = nullptr;
bool print_before = false;
+ bool print_after = false;
+ std::vector<std::string> passes;
for (size_t i = 1; i < argc; i++) {
char* curr = argv[i];
if (curr[0] == '-') {
std::string arg = curr;
- if (arg == "--print-before") {
+ if (arg == "-print-before") {
print_before = true;
+ } else if (arg == "-print-after") {
+ print_after = true;
+ } else if (arg == "--help") {
+ std::cout << "binaryen shell\n";
+ std::cout << "--------------\n\n";
+ std::cout << "options:\n";
+ std::cout << " -print-before : print modules before processing them\n";
+ std::cout << "\n";
+ std::cout << "passes:\n";
+ auto allPasses = PassRegistry::get()->getRegisteredNames();
+ for (auto& name : allPasses) {
+ std::cout << " -" << name << "\n";
+ }
+ exit(0);
} else {
- if (infile) {
- printf("error: unrecognized argument: %s\n", curr);
+ // otherwise, assumed to be a pass
+ const char* name = curr + 1;
+ auto check = PassRegistry::get()->createPass(name);
+ if (!check) {
+ printf("error: invalid option %s\n", curr);
exit(1);
}
+ delete check;
+ passes.push_back(name);
}
} else {
if (infile) {
@@ -215,6 +241,22 @@ int main(int argc, char **argv) {
std::cout << wasm;
}
+ MixedArena moreModuleAllocations;
+
+ if (passes.size() > 0) {
+ if (debug) std::cerr << "running passes...\n";
+ PassRunner passRunner(&moreModuleAllocations);
+ for (auto& passName : passes) {
+ passRunner.add(passName);
+ }
+ passRunner.run(&wasm);
+ }
+
+ if (print_after) {
+ if (debug) std::cerr << "printing...\n";
+ std::cout << wasm;
+ }
+
// run asserts
while (i < root.size()) {
Element& curr = *root[i];