diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/asm2wasm.h | 2 | ||||
-rw-r--r-- | src/binaryen-shell.cpp (renamed from src/wasm-shell.cpp) | 45 | ||||
-rw-r--r-- | src/pretty_printing.h | 2 | ||||
-rw-r--r-- | src/wasm.h | 23 |
4 files changed, 57 insertions, 15 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 61c67c5d8..ce5b669d1 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -5,7 +5,7 @@ // #include "wasm.h" -#include "optimizer.h" +#include "emscripten-optimizer/optimizer.h" #include "mixed_arena.h" namespace wasm { diff --git a/src/wasm-shell.cpp b/src/binaryen-shell.cpp index 701b6b6c2..e0f524122 100644 --- a/src/wasm-shell.cpp +++ b/src/binaryen-shell.cpp @@ -144,14 +144,43 @@ struct Invocation { // int main(int argc, char **argv) { - debug = getenv("WASM_SHELL_DEBUG") ? getenv("WASM_SHELL_DEBUG")[0] - '0' : 0; + debug = getenv("BINARYEN_DEBUG") ? getenv("BINARYEN_DEBUG")[0] - '0' : 0; - char *infile = argv[1]; - bool print_wasm = argc >= 3; // second arg means print it out + char *infile = nullptr; + bool print_before = false; + + for (size_t i = 1; i < argc; i++) { + char* curr = argv[i]; + if (curr[0] == '-') { + std::string arg = curr; + if (arg == "--print-before") { + print_before = true; + } else { + if (infile) { + printf("error: unrecognized argument: %s\n", curr); + exit(1); + } + } + } else { + if (infile) { + printf("error: too many input files provided.\n"); + exit(1); + } + infile = curr; + } + } + + if (!infile) { + printf("error: no input file provided.\n"); + exit(1); + } if (debug) std::cerr << "loading '" << infile << "'...\n"; FILE *f = fopen(argv[1], "r"); - assert(f); + if (!f) { + printf("error: could not open input file: %s\n", infile); + exit(1); + } fseek(f, 0, SEEK_END); int size = ftell(f); char *input = new char[size+1]; @@ -170,6 +199,7 @@ int main(int argc, char **argv) { if (debug) std::cout << root << '\n'; // A .wast may have multiple modules, with some asserts after them + bool checked = false; size_t i = 0; while (i < root.size()) { if (debug) std::cerr << "parsing s-expressions to wasm...\n"; @@ -180,7 +210,7 @@ int main(int argc, char **argv) { auto interface = new ShellExternalInterface(); auto instance = new ModuleInstance(wasm, interface); - if (print_wasm) { + if (print_before) { if (debug) std::cerr << "printing...\n"; std::cout << wasm; } @@ -190,6 +220,7 @@ int main(int argc, char **argv) { Element& curr = *root[i]; IString id = curr[0]->str(); if (id == MODULE) break; + checked = true; Colors::red(std::cerr); std::cerr << i << '/' << (root.size()-1); Colors::green(std::cerr); @@ -240,10 +271,10 @@ int main(int argc, char **argv) { } } - if (debug) { + if (checked) { Colors::green(std::cerr); Colors::bold(std::cerr); - std::cerr << "\ndone.\n"; + std::cerr << "all checks passed.\n"; Colors::normal(std::cerr); } } diff --git a/src/pretty_printing.h b/src/pretty_printing.h index cc2d88272..88028fdec 100644 --- a/src/pretty_printing.h +++ b/src/pretty_printing.h @@ -5,7 +5,7 @@ #include <ostream> -#include "colors.h" +#include "emscripten-optimizer/colors.h" std::ostream &doIndent(std::ostream &o, unsigned indent) { for (unsigned i = 0; i < indent; i++) { diff --git a/src/wasm.h b/src/wasm.h index fcee2915c..6fc4ca5aa 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -24,7 +24,7 @@ #include <map> #include <vector> -#include "simple_ast.h" +#include "emscripten-optimizer/simple_ast.h" #include "pretty_printing.h" namespace wasm { @@ -263,12 +263,10 @@ public: }; Id _id; - Expression() : _id(InvalidId) {} - Expression(Id id) : _id(id) {} - WasmType type; // the type of the expression: its *output*, not necessarily its input(s) - std::ostream& print(std::ostream &o, unsigned indent); // avoid virtual here, for performance + Expression() : _id(InvalidId), type(none) {} + Expression(Id id) : _id(id), type(none) {} template<class T> bool is() { @@ -280,6 +278,12 @@ public: return _id == T()._id ? (T*)this : nullptr; } + std::ostream& print(std::ostream &o, unsigned indent); // avoid virtual here, for performance + + friend std::ostream& operator<<(std::ostream &o, Expression* expression) { + return expression->print(o, 0); + } + static std::ostream& printFullLine(std::ostream &o, unsigned indent, Expression *expression) { doIndent(o, indent); expression->print(o, indent); @@ -704,6 +708,11 @@ public: printFullLine(o, indent, right); return decIndent(o, indent); } + + // the type is always the type of the operands + void finalize() { + type = left->type; + } }; class Compare : public Expression { @@ -849,6 +858,8 @@ public: Name type; // if null, it is implicit in params and result Expression *body; + Function() : result(none) {} + std::ostream& print(std::ostream &o, unsigned indent) { printOpening(o, "func ", true) << name; if (params.size() > 0) { @@ -921,7 +932,7 @@ public: size_t initial, max; std::vector<Segment> segments; - Memory() : initial(0), max(-1) {} + Memory() : initial(0), max((uint32_t)-1) {} }; class Module { |