X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FDataStream.cpp;h=32653de5194383549de9bb6b88b427383cca9f1f;hb=ad591b341bf22bb4d3a7526d59d4ae6c414420ee;hp=b2dd979e7f1169e90f3b5d450ef57c527737e90f;hpb=eb446511ce5f1761962f12f1e8a0c7b342733d1c;p=oota-llvm.git diff --git a/lib/Support/DataStream.cpp b/lib/Support/DataStream.cpp index b2dd979e7f1..32653de5194 100644 --- a/lib/Support/DataStream.cpp +++ b/lib/Support/DataStream.cpp @@ -14,22 +14,23 @@ // //===----------------------------------------------------------------------===// -#define DEBUG_TYPE "Data-stream" -#include "llvm/ADT/Statistic.h" #include "llvm/Support/DataStream.h" +#include "llvm/ADT/Statistic.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Program.h" -#include "llvm/Support/system_error.h" -#include #include #include +#include +#include #if !defined(_MSC_VER) && !defined(__MINGW32__) #include #else #include #endif -#include using namespace llvm; +#define DEBUG_TYPE "Data-stream" + // Interface goals: // * StreamableMemoryObject doesn't care about complexities like using // threads/async callbacks to actually overlap download+compile @@ -49,8 +50,6 @@ DataStreamer::~DataStreamer() {} namespace { -const static error_code success; - // Very simple stream backed by a file. Mostly useful for stdin and debugging; // actual file access is probably still best done with mmap. class DataFileStreamer : public DataStreamer { @@ -60,24 +59,19 @@ public: virtual ~DataFileStreamer() { close(Fd); } - virtual size_t GetBytes(unsigned char *buf, size_t len) { + size_t GetBytes(unsigned char *buf, size_t len) override { NumStreamFetches++; return read(Fd, buf, len); } - error_code OpenFile(const std::string &Filename) { - int OpenFlags = O_RDONLY; -#ifdef O_BINARY - OpenFlags |= O_BINARY; // Open input file in binary mode on win32. -#endif + std::error_code OpenFile(const std::string &Filename) { if (Filename == "-") { Fd = 0; - sys::Program::ChangeStdinToBinary(); + sys::ChangeStdinToBinary(); + return std::error_code(); } - else - Fd = ::open(Filename.c_str(), OpenFlags); - if (Fd == -1) return error_code(errno, posix_category()); - return success; + + return sys::fs::openFileForRead(Filename, Fd); } }; @@ -87,11 +81,10 @@ namespace llvm { DataStreamer *getDataFileStreamer(const std::string &Filename, std::string *StrError) { DataFileStreamer *s = new DataFileStreamer(); - error_code e = s->OpenFile(Filename); - if (e != success) { + if (std::error_code e = s->OpenFile(Filename)) { *StrError = std::string("Could not open ") + Filename + ": " + e.message() + "\n"; - return NULL; + return nullptr; } return s; }