diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 21:25:48 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 21:25:48 +0000 |
| commit | d88c1a5a572cdb661c111098831fa526e933756f (patch) | |
| tree | 97b32c3372106ac47ded3d1a99f9c023a8530073 /contrib/llvm/lib/Support/MemoryBuffer.cpp | |
| parent | 715652a404ee99f10c09c0a5edbb5883961b8c25 (diff) | |
| parent | b915e9e0fc85ba6f398b3fab0db6a81a8913af94 (diff) | |
Notes
Diffstat (limited to 'contrib/llvm/lib/Support/MemoryBuffer.cpp')
| -rw-r--r-- | contrib/llvm/lib/Support/MemoryBuffer.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/contrib/llvm/lib/Support/MemoryBuffer.cpp b/contrib/llvm/lib/Support/MemoryBuffer.cpp index b935cbf1ae7a..a3a18c9283ce 100644 --- a/contrib/llvm/lib/Support/MemoryBuffer.cpp +++ b/contrib/llvm/lib/Support/MemoryBuffer.cpp @@ -90,9 +90,9 @@ public: /// tail-allocated data. void operator delete(void *p) { ::operator delete(p); } - const char *getBufferIdentifier() const override { - // The name is stored after the class itself. - return reinterpret_cast<const char*>(this + 1); + StringRef getBufferIdentifier() const override { + // The name is stored after the class itself. + return StringRef(reinterpret_cast<const char *>(this + 1)); } BufferKind getBufferKind() const override { @@ -221,9 +221,9 @@ public: /// tail-allocated data. void operator delete(void *p) { ::operator delete(p); } - const char *getBufferIdentifier() const override { + StringRef getBufferIdentifier() const override { // The name is stored after the class itself. - return reinterpret_cast<const char *>(this + 1); + return StringRef(reinterpret_cast<const char *>(this + 1)); } BufferKind getBufferKind() const override { @@ -438,6 +438,18 @@ ErrorOr<std::unique_ptr<MemoryBuffer>> MemoryBuffer::getSTDIN() { return getMemoryBufferForStream(0, "<stdin>"); } +ErrorOr<std::unique_ptr<MemoryBuffer>> +MemoryBuffer::getFileAsStream(const Twine &Filename) { + int FD; + std::error_code EC = sys::fs::openFileForRead(Filename, FD); + if (EC) + return EC; + ErrorOr<std::unique_ptr<MemoryBuffer>> Ret = + getMemoryBufferForStream(FD, Filename); + close(FD); + return Ret; +} + MemoryBufferRef MemoryBuffer::getMemBufferRef() const { StringRef Data = getBuffer(); StringRef Identifier = getBufferIdentifier(); |
