diff options
author | Alon Zakai <azakai@google.com> | 2019-04-26 16:59:41 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-26 16:59:41 -0700 |
commit | db9124f1de0478dcac525009b6f1589b44a7edd8 (patch) | |
tree | fa26395a0f6cca53cf5cb6e10189f989c5bfa847 /src/support/file.cpp | |
parent | 87636dccd404a340d75acb1d96301581343f29ca (diff) | |
download | binaryen-db9124f1de0478dcac525009b6f1589b44a7edd8.tar.gz binaryen-db9124f1de0478dcac525009b6f1589b44a7edd8.tar.bz2 binaryen-db9124f1de0478dcac525009b6f1589b44a7edd8.zip |
Apply format changes from #2048 (#2059)
Mass change to apply clang-format to everything. We are applying this in a PR by me so the (git) blame is all mine ;) but @aheejin did all the work to get clang-format set up and all the manual work to tidy up some things to make the output nicer in #2048
Diffstat (limited to 'src/support/file.cpp')
-rw-r--r-- | src/support/file.cpp | 83 |
1 files changed, 50 insertions, 33 deletions
diff --git a/src/support/file.cpp b/src/support/file.cpp index c10646720..3af7af44b 100644 --- a/src/support/file.cpp +++ b/src/support/file.cpp @@ -16,13 +16,14 @@ #include "support/file.h" -#include <iostream> -#include <cstdlib> #include <cstdint> +#include <cstdlib> +#include <iostream> #include <limits> std::vector<char> wasm::read_stdin(Flags::DebugOption debug) { - if (debug == Flags::Debug) std::cerr << "Loading stdin..." << std::endl; + if (debug == Flags::Debug) + std::cerr << "Loading stdin..." << std::endl; std::vector<char> input; char c; while (std::cin.get(c) && !std::cin.eof()) { @@ -31,13 +32,16 @@ std::vector<char> wasm::read_stdin(Flags::DebugOption debug) { return input; } - template<typename T> -T wasm::read_file(const std::string& filename, Flags::BinaryOption binary, Flags::DebugOption debug) { - if (debug == Flags::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; std::ios_base::openmode flags = std::ifstream::in; - if (binary == Flags::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; @@ -46,47 +50,60 @@ T wasm::read_file(const std::string& filename, Flags::BinaryOption binary, Flags infile.seekg(0, std::ios::end); std::streampos insize = infile.tellg(); if (uint64_t(insize) >= std::numeric_limits<size_t>::max()) { - // Building a 32-bit executable where size_t == 32 bits, we are not able to create strings larger than 2^32 bytes in length, so must abort here. - std::cerr << "Failed opening '" << filename << "': Input file too large: " << insize << " bytes. Try rebuilding in 64-bit mode." << std::endl; + // Building a 32-bit executable where size_t == 32 bits, we are not able to + // create strings larger than 2^32 bytes in length, so must abort here. + std::cerr << "Failed opening '" << filename + << "': Input file too large: " << insize + << " bytes. Try rebuilding in 64-bit mode." << std::endl; exit(EXIT_FAILURE); } T input(size_t(insize) + (binary == Flags::Binary ? 0 : 1), '\0'); - if (size_t(insize) == 0) return input; + if (size_t(insize) == 0) + return input; infile.seekg(0); infile.read(&input[0], insize); if (binary == Flags::Text) { size_t chars = size_t(infile.gcount()); - input.resize(chars+1); // Truncate size to the number of ASCII characters actually read in text mode (which is generally less than the number of bytes on Windows, if \r\n line endings are present) + // Truncate size to the number of ASCII characters actually read in text + // mode (which is generally less than the number of bytes on Windows, if + // \r\n line endings are present) + input.resize(chars + 1); input[chars] = '\0'; } return input; } // Explicit instantiations for the explicit specializations. -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); +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, Flags::BinaryOption binary, Flags::DebugOption debug) - : outfile(), out([this, filename, binary, debug]() { - if (filename == "-") { - return std::cout.rdbuf(); - } - std::streambuf *buffer; - if (filename.size()) { - if (debug == Flags::Debug) std::cerr << "Opening '" << filename << "'" << std::endl; - auto flags = std::ofstream::out | std::ofstream::trunc; - if (binary == Flags::Binary) flags |= std::ofstream::binary; - outfile.open(filename, flags); - if (!outfile.is_open()) { - std::cerr << "Failed opening '" << filename << "'" << std::endl; - exit(EXIT_FAILURE); - } - buffer = outfile.rdbuf(); - } else { - buffer = std::cout.rdbuf(); +wasm::Output::Output(const std::string& filename, + Flags::BinaryOption binary, + Flags::DebugOption debug) + : outfile(), out([this, filename, binary, debug]() { + if (filename == "-") { + return std::cout.rdbuf(); + } + std::streambuf* buffer; + if (filename.size()) { + if (debug == Flags::Debug) + std::cerr << "Opening '" << filename << "'" << std::endl; + auto flags = std::ofstream::out | std::ofstream::trunc; + if (binary == Flags::Binary) + flags |= std::ofstream::binary; + outfile.open(filename, flags); + if (!outfile.is_open()) { + std::cerr << "Failed opening '" << filename << "'" << std::endl; + exit(EXIT_FAILURE); } - return buffer; - }()) {} + buffer = outfile.rdbuf(); + } else { + buffer = std::cout.rdbuf(); + } + return buffer; + }()) {} void wasm::copy_file(std::string input, std::string output) { std::ifstream src(input, std::ios::binary); |