diff options
-rw-r--r-- | src/asm2wasm-main.cpp | 4 | ||||
-rw-r--r-- | src/binaryen-shell.cpp | 2 | ||||
-rw-r--r-- | src/s2wasm-main.cpp | 4 | ||||
-rw-r--r-- | src/support/file.cpp | 16 | ||||
-rw-r--r-- | src/support/file.h | 20 | ||||
-rw-r--r-- | src/wasm-as.cpp | 4 | ||||
-rw-r--r-- | src/wasm-dis.cpp | 4 | ||||
-rw-r--r-- | src/wasm2asm-main.cpp | 4 |
8 files changed, 35 insertions, 23 deletions
diff --git a/src/asm2wasm-main.cpp b/src/asm2wasm-main.cpp index 3e4c40ddc..12a06d0de 100644 --- a/src/asm2wasm-main.cpp +++ b/src/asm2wasm-main.cpp @@ -77,7 +77,7 @@ int main(int argc, const char *argv[]) { Asm2WasmPreProcessor pre; auto input( - read_file<std::vector<char>>(options.extra["infile"], false, options.debug)); + read_file<std::vector<char>>(options.extra["infile"], Flags::Text, options.debug ? Flags::Debug : Flags::Release)); char *start = pre.process(input.data()); if (options.debug) std::cerr << "parsing..." << std::endl; @@ -101,7 +101,7 @@ int main(int argc, const char *argv[]) { } if (options.debug) std::cerr << "printing..." << std::endl; - Output output(options.extra["output"], false, options.debug); + Output output(options.extra["output"], Flags::Text, options.debug ? Flags::Debug : Flags::Release); printWasm(&wasm, output.getStream()); if (mappedGlobals) { diff --git a/src/binaryen-shell.cpp b/src/binaryen-shell.cpp index 218ad7226..c2b6fcaa7 100644 --- a/src/binaryen-shell.cpp +++ b/src/binaryen-shell.cpp @@ -372,7 +372,7 @@ int main(int argc, const char* argv[]) { } options.parse(argc, argv); - auto input(read_file<std::vector<char>>(options.extra["infile"], false, options.debug)); + auto input(read_file<std::vector<char>>(options.extra["infile"], Flags::Text, options.debug ? Flags::Debug : Flags::Release)); if (options.debug) std::cerr << "parsing text to s-expressions...\n"; SExpressionParser parser(input.data()); diff --git a/src/s2wasm-main.cpp b/src/s2wasm-main.cpp index 59258cfd5..8cbb7f5f5 100644 --- a/src/s2wasm-main.cpp +++ b/src/s2wasm-main.cpp @@ -74,7 +74,7 @@ int main(int argc, const char *argv[]) { }); options.parse(argc, argv); - auto input(read_file<std::string>(options.extra["infile"], false, options.debug)); + auto input(read_file<std::string>(options.extra["infile"], Flags::Text, options.debug ? Flags::Debug : Flags::Release)); if (options.debug) std::cerr << "Parsing and wasming..." << std::endl; AllocatingModule wasm; @@ -103,7 +103,7 @@ int main(int argc, const char *argv[]) { s2wasm.emscriptenGlue(meta); if (options.debug) std::cerr << "Printing..." << std::endl; - Output output(options.extra["output"], false, options.debug); + Output output(options.extra["output"], Flags::Text, options.debug ? Flags::Debug : Flags::Release); printWasm(&wasm, output.getStream()); output << meta.str() << std::endl; diff --git a/src/support/file.cpp b/src/support/file.cpp index 0ec460041..b71361d99 100644 --- a/src/support/file.cpp +++ b/src/support/file.cpp @@ -20,11 +20,11 @@ #include <limits> template <typename T> -T wasm::read_file(const std::string &filename, bool binary, bool debug) { - if (debug) std::cerr << "Loading '" << filename << "'..." << std::endl; +T wasm::read_file(const std::string &filename, Flags::BinaryOption binary, Flags::DebugOption debug) { + if (debug == Flags::Debug) std::cerr << "Loading '" << filename << "'..." << std::endl; std::ifstream infile; auto flags = std::ifstream::in; - if (binary) flags |= std::ifstream::binary; + if (binary == Flags::Binary) flags |= std::ifstream::binary; infile.open(filename, flags); if (!infile.is_open()) { std::cerr << "Failed opening '" << filename << "'" << std::endl; @@ -44,16 +44,16 @@ T wasm::read_file(const std::string &filename, bool binary, bool debug) { } // Explicit instantiations for the explicit specializations. -template std::string wasm::read_file<>(const std::string &, bool, bool); -template std::vector<char> wasm::read_file<>(const std::string &, bool, bool); +template std::string wasm::read_file<>(const std::string &, Flags::BinaryOption, Flags::DebugOption); +template std::vector<char> wasm::read_file<>(const std::string &, Flags::BinaryOption, Flags::DebugOption); -wasm::Output::Output(const std::string &filename, bool binary, bool debug) +wasm::Output::Output(const std::string &filename, Flags::BinaryOption binary, Flags::DebugOption debug) : outfile(), out([this, filename, binary, debug]() { std::streambuf *buffer; if (filename.size()) { - if (debug) std::cerr << "Opening '" << filename << std::endl; + if (debug == Flags::Debug) std::cerr << "Opening '" << filename << std::endl; auto flags = std::ofstream::out | std::ofstream::trunc; - if (binary) flags |= std::ofstream::binary; + if (binary == Flags::Binary) flags |= std::ofstream::binary; outfile.open(filename, flags); if (!outfile.is_open()) { std::cerr << "Failed opening '" << filename << "'" << std::endl; diff --git a/src/support/file.h b/src/support/file.h index 8d92b5ab4..01c7a8546 100644 --- a/src/support/file.h +++ b/src/support/file.h @@ -28,16 +28,28 @@ #include <vector> namespace wasm { + +namespace Flags { + enum BinaryOption { + Binary, + Text + }; + enum DebugOption { + Debug, + Release + }; +} + template <typename T> -T read_file(const std::string &filename, bool binary, bool debug); +T read_file(const std::string &filename, Flags::BinaryOption binary, Flags::DebugOption debug); // Declare the valid explicit specializations. -extern template std::string read_file<>(const std::string &, bool, bool); -extern template std::vector<char> read_file<>(const std::string &, bool, bool); +extern template std::string read_file<>(const std::string &, Flags::BinaryOption, Flags::DebugOption); +extern template std::vector<char> read_file<>(const std::string &, Flags::BinaryOption, Flags::DebugOption); class Output { public: // An empty filename will open stdout instead. - Output(const std::string &filename, bool binary, bool debug); + Output(const std::string &filename, Flags::BinaryOption binary, Flags::DebugOption debug); ~Output() = default; template <typename T> std::ostream &operator<<(const T &v) { diff --git a/src/wasm-as.cpp b/src/wasm-as.cpp index 722ab398b..c2a8abc6e 100644 --- a/src/wasm-as.cpp +++ b/src/wasm-as.cpp @@ -41,7 +41,7 @@ int main(int argc, const char *argv[]) { }); options.parse(argc, argv); - auto input(read_file<std::string>(options.extra["infile"], false, options.debug)); + auto input(read_file<std::string>(options.extra["infile"], Flags::Text, options.debug ? Flags::Debug : Flags::Release)); if (options.debug) std::cerr << "s-parsing..." << std::endl; SExpressionParser parser(const_cast<char*>(input.c_str())); @@ -57,7 +57,7 @@ int main(int argc, const char *argv[]) { writer.write(); if (options.debug) std::cerr << "writing to output..." << std::endl; - Output output(options.extra["output"], true, options.debug); + Output output(options.extra["output"], Flags::Binary, options.debug ? Flags::Debug : Flags::Release); buffer.writeTo(output); if (options.debug) std::cerr << "Done." << std::endl; diff --git a/src/wasm-dis.cpp b/src/wasm-dis.cpp index 9ad7e2c68..c3197a1a2 100644 --- a/src/wasm-dis.cpp +++ b/src/wasm-dis.cpp @@ -41,7 +41,7 @@ int main(int argc, const char *argv[]) { }); options.parse(argc, argv); - auto input(read_file<std::vector<char>>(options.extra["infile"], true, options.debug)); + auto input(read_file<std::vector<char>>(options.extra["infile"], Flags::Binary, options.debug ? Flags::Debug : Flags::Release)); if (options.debug) std::cerr << "parsing binary..." << std::endl; AllocatingModule wasm; @@ -49,7 +49,7 @@ int main(int argc, const char *argv[]) { parser.read(); if (options.debug) std::cerr << "Printing..." << std::endl; - Output output(options.extra["output"], false, options.debug); + Output output(options.extra["output"], Flags::Text, options.debug ? Flags::Debug : Flags::Release); printWasm(&wasm, output.getStream()); output << '\n'; diff --git a/src/wasm2asm-main.cpp b/src/wasm2asm-main.cpp index 157c75d98..2234f2343 100644 --- a/src/wasm2asm-main.cpp +++ b/src/wasm2asm-main.cpp @@ -44,7 +44,7 @@ int main(int argc, const char *argv[]) { options.parse(argc, argv); auto input( - read_file<std::vector<char>>(options.extra["infile"], false, options.debug)); + read_file<std::vector<char>>(options.extra["infile"], Flags::Text, options.debug ? Flags::Debug : Flags::Release)); if (options.debug) std::cerr << "s-parsing..." << std::endl; SExpressionParser parser(input.data()); @@ -67,7 +67,7 @@ int main(int argc, const char *argv[]) { if (options.debug) std::cerr << "j-printing..." << std::endl; JSPrinter jser(true, true, asmjs); jser.printAst(); - Output output(options.extra["output"], false, options.debug); + Output output(options.extra["output"], Flags::Text, options.debug ? Flags::Debug : Flags::Release); output << jser.buffer << std::endl; if (options.debug) std::cerr << "done." << std::endl; |