X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FDataStream.cpp;h=3b10fc5eecaa3442e40da172429a5573a4e43be9;hb=9be4dc8ab20a009ed5f24610888421ba84f8ec65;hp=eec858416a8f9145786f7703de3bac13c182797c;hpb=c722ba49b2e5127a43ed73b0ad7443a0442f4a1a;p=oota-llvm.git diff --git a/lib/Support/DataStream.cpp b/lib/Support/DataStream.cpp index eec858416a8..3b10fc5eeca 100644 --- a/lib/Support/DataStream.cpp +++ b/lib/Support/DataStream.cpp @@ -16,12 +16,11 @@ #include "llvm/Support/DataStream.h" #include "llvm/ADT/Statistic.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Program.h" -#include "llvm/Support/system_error.h" -#include -#include #include +#include #if !defined(_MSC_VER) && !defined(__MINGW32__) #include #else @@ -32,12 +31,12 @@ using namespace llvm; #define DEBUG_TYPE "Data-stream" // Interface goals: -// * StreamableMemoryObject doesn't care about complexities like using +// * StreamingMemoryObject doesn't care about complexities like using // threads/async callbacks to actually overlap download+compile // * Don't want to duplicate Data in memory // * Don't need to know total Data len in advance // Non-goals: -// StreamableMemoryObject already has random access so this interface only does +// StreamingMemoryObject already has random access so this interface only does // in-order streaming (no arbitrary seeking, else we'd have to buffer all the // Data here in addition to MemoryObject). This also means that if we want // to be able to to free Data, BitstreamBytes/BitcodeReader will implement it @@ -56,19 +55,17 @@ class DataFileStreamer : public DataStreamer { int Fd; public: DataFileStreamer() : Fd(0) {} - virtual ~DataFileStreamer() { - close(Fd); - } + ~DataFileStreamer() override { close(Fd); } size_t GetBytes(unsigned char *buf, size_t len) override { NumStreamFetches++; return read(Fd, buf, len); } - error_code OpenFile(const std::string &Filename) { + std::error_code OpenFile(const std::string &Filename) { if (Filename == "-") { Fd = 0; sys::ChangeStdinToBinary(); - return error_code::success(); + return std::error_code(); } return sys::fs::openFileForRead(Filename, Fd); @@ -77,16 +74,13 @@ public: } -namespace llvm { -DataStreamer *getDataFileStreamer(const std::string &Filename, - std::string *StrError) { - DataFileStreamer *s = new DataFileStreamer(); - if (error_code e = s->OpenFile(Filename)) { +std::unique_ptr +llvm::getDataFileStreamer(const std::string &Filename, std::string *StrError) { + std::unique_ptr s = make_unique(); + if (std::error_code e = s->OpenFile(Filename)) { *StrError = std::string("Could not open ") + Filename + ": " + e.message() + "\n"; return nullptr; } - return s; -} - + return std::move(s); }