summaryrefslogtreecommitdiff
path: root/include/llvm/Support/MemoryBuffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Support/MemoryBuffer.h')
-rw-r--r--include/llvm/Support/MemoryBuffer.h28
1 files changed, 19 insertions, 9 deletions
diff --git a/include/llvm/Support/MemoryBuffer.h b/include/llvm/Support/MemoryBuffer.h
index 73d643537a6f..f739d19907b0 100644
--- a/include/llvm/Support/MemoryBuffer.h
+++ b/include/llvm/Support/MemoryBuffer.h
@@ -14,13 +14,17 @@
#ifndef LLVM_SUPPORT_MEMORYBUFFER_H
#define LLVM_SUPPORT_MEMORYBUFFER_H
+#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/CBindingWrapping.h"
-#include "llvm/Support/DataTypes.h"
#include "llvm/Support/ErrorOr.h"
+#include "llvm-c/Types.h"
#include <memory>
+#include <cstddef>
+#include <cstdint>
namespace llvm {
+
class MemoryBufferRef;
/// This interface provides simple read-only access to a block of memory, and
@@ -37,13 +41,15 @@ class MemoryBuffer {
const char *BufferStart; // Start of the buffer.
const char *BufferEnd; // End of the buffer.
- MemoryBuffer(const MemoryBuffer &) = delete;
- MemoryBuffer &operator=(const MemoryBuffer &) = delete;
+
protected:
- MemoryBuffer() {}
+ MemoryBuffer() = default;
+
void init(const char *BufStart, const char *BufEnd,
bool RequiresNullTerminator);
public:
+ MemoryBuffer(const MemoryBuffer &) = delete;
+ MemoryBuffer &operator=(const MemoryBuffer &) = delete;
virtual ~MemoryBuffer();
const char *getBufferStart() const { return BufferStart; }
@@ -56,9 +62,7 @@ public:
/// Return an identifier for this buffer, typically the filename it was read
/// from.
- virtual const char *getBufferIdentifier() const {
- return "Unknown buffer";
- }
+ virtual StringRef getBufferIdentifier() const { return "Unknown buffer"; }
/// Open the specified file as a MemoryBuffer, returning a new MemoryBuffer
/// if successful, otherwise returning null. If FileSize is specified, this
@@ -72,6 +76,12 @@ public:
getFile(const Twine &Filename, int64_t FileSize = -1,
bool RequiresNullTerminator = true, bool IsVolatileSize = false);
+ /// Read all of the specified file into a MemoryBuffer as a stream
+ /// (i.e. until EOF reached). This is useful for special files that
+ /// look like a regular file but have 0 size (e.g. /proc/cpuinfo on Linux).
+ static ErrorOr<std::unique_ptr<MemoryBuffer>>
+ getFileAsStream(const Twine &Filename);
+
/// Given an already-open file descriptor, map some slice of it into a
/// MemoryBuffer. The slice is specified by an \p Offset and \p MapSize.
/// Since this is in the middle of a file, the buffer is not null terminated.
@@ -150,7 +160,7 @@ class MemoryBufferRef {
StringRef Identifier;
public:
- MemoryBufferRef() {}
+ MemoryBufferRef() = default;
MemoryBufferRef(MemoryBuffer& Buffer)
: Buffer(Buffer.getBuffer()), Identifier(Buffer.getBufferIdentifier()) {}
MemoryBufferRef(StringRef Buffer, StringRef Identifier)
@@ -170,4 +180,4 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer, LLVMMemoryBufferRef)
} // end namespace llvm
-#endif
+#endif // LLVM_SUPPORT_MEMORYBUFFER_H