summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm-main.cpp4
-rw-r--r--src/binaryen-shell.cpp2
-rw-r--r--src/s2wasm-main.cpp4
-rw-r--r--src/support/file.cpp19
-rw-r--r--src/support/file.h8
-rw-r--r--src/wasm-as.cpp4
-rw-r--r--src/wasm-dis.cpp4
-rw-r--r--src/wasm2asm-main.cpp4
8 files changed, 27 insertions, 22 deletions
diff --git a/src/asm2wasm-main.cpp b/src/asm2wasm-main.cpp
index 56e8a417f..3e4c40ddc 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"], options.debug));
+ read_file<std::vector<char>>(options.extra["infile"], false, options.debug));
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"], options.debug);
+ Output output(options.extra["output"], false, options.debug);
printWasm(&wasm, output.getStream());
if (mappedGlobals) {
diff --git a/src/binaryen-shell.cpp b/src/binaryen-shell.cpp
index 93d4c65ce..218ad7226 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"], options.debug));
+ auto input(read_file<std::vector<char>>(options.extra["infile"], false, options.debug));
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 40009cbc9..59258cfd5 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"], options.debug));
+ auto input(read_file<std::string>(options.extra["infile"], false, options.debug));
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"], options.debug);
+ Output output(options.extra["output"], false, options.debug);
printWasm(&wasm, output.getStream());
output << meta.str() << std::endl;
diff --git a/src/support/file.cpp b/src/support/file.cpp
index ba69a1be1..0ec460041 100644
--- a/src/support/file.cpp
+++ b/src/support/file.cpp
@@ -20,9 +20,12 @@
#include <limits>
template <typename T>
-T wasm::read_file(const std::string &filename, bool debug) {
+T wasm::read_file(const std::string &filename, bool binary, bool debug) {
if (debug) std::cerr << "Loading '" << filename << "'..." << std::endl;
- std::ifstream infile(filename);
+ std::ifstream infile;
+ auto flags = std::ifstream::in;
+ if (binary) flags |= std::ifstream::binary;
+ infile.open(filename, flags);
if (!infile.is_open()) {
std::cerr << "Failed opening '" << filename << "'" << std::endl;
exit(EXIT_FAILURE);
@@ -41,15 +44,17 @@ T wasm::read_file(const std::string &filename, bool debug) {
}
// Explicit instantiations for the explicit specializations.
-template std::string wasm::read_file<>(const std::string &, bool);
-template std::vector<char> wasm::read_file<>(const std::string &, bool);
+template std::string wasm::read_file<>(const std::string &, bool, bool);
+template std::vector<char> wasm::read_file<>(const std::string &, bool, bool);
-wasm::Output::Output(const std::string &filename, bool debug)
- : outfile(), out([this, filename, debug]() {
+wasm::Output::Output(const std::string &filename, bool binary, bool debug)
+ : outfile(), out([this, filename, binary, debug]() {
std::streambuf *buffer;
if (filename.size()) {
if (debug) std::cerr << "Opening '" << filename << std::endl;
- outfile.open(filename, std::ofstream::out | std::ofstream::trunc);
+ auto flags = std::ofstream::out | std::ofstream::trunc;
+ if (binary) flags |= std::ofstream::binary;
+ outfile.open(filename, flags);
if (!outfile.is_open()) {
std::cerr << "Failed opening '" << filename << "'" << std::endl;
exit(EXIT_FAILURE);
diff --git a/src/support/file.h b/src/support/file.h
index 47f7ececb..8d92b5ab4 100644
--- a/src/support/file.h
+++ b/src/support/file.h
@@ -29,15 +29,15 @@
namespace wasm {
template <typename T>
-T read_file(const std::string &filename, bool debug);
+T read_file(const std::string &filename, bool binary, bool debug);
// Declare the valid explicit specializations.
-extern template std::string read_file<>(const std::string &, bool);
-extern template std::vector<char> read_file<>(const std::string &, bool);
+extern template std::string read_file<>(const std::string &, bool, bool);
+extern template std::vector<char> read_file<>(const std::string &, bool, bool);
class Output {
public:
// An empty filename will open stdout instead.
- Output(const std::string &filename, bool debug);
+ Output(const std::string &filename, bool binary, bool 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 48ec0fc4c..722ab398b 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"], options.debug));
+ auto input(read_file<std::string>(options.extra["infile"], false, options.debug));
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"], options.debug);
+ Output output(options.extra["output"], true, options.debug);
buffer.writeTo(output);
if (options.debug) std::cerr << "Done." << std::endl;
diff --git a/src/wasm-dis.cpp b/src/wasm-dis.cpp
index 7486e0bbd..9ad7e2c68 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"], options.debug));
+ auto input(read_file<std::vector<char>>(options.extra["infile"], true, options.debug));
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"], options.debug);
+ Output output(options.extra["output"], false, options.debug);
printWasm(&wasm, output.getStream());
output << '\n';
diff --git a/src/wasm2asm-main.cpp b/src/wasm2asm-main.cpp
index c75272b8d..157c75d98 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"], options.debug));
+ read_file<std::vector<char>>(options.extra["infile"], false, options.debug));
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"], options.debug);
+ Output output(options.extra["output"], false, options.debug);
output << jser.buffer << std::endl;
if (options.debug) std::cerr << "done." << std::endl;