summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/FileOutputBuffer.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2017-11-08 22:57:48 +0000
committerRui Ueyama <ruiu@google.com>2017-11-08 22:57:48 +0000
commitf6490e047a853bb38d435b8039bbeb4b41e863d3 (patch)
tree22d57b9ea1ee196994a1f84f5d3476e89fe99199 /llvm/lib/Support/FileOutputBuffer.cpp
parent75a35179de366c85536a74c513cdfeedefeedddd (diff)
downloadbcm5719-llvm-f6490e047a853bb38d435b8039bbeb4b41e863d3.tar.gz
bcm5719-llvm-f6490e047a853bb38d435b8039bbeb4b41e863d3.zip
[FileOutputBuffer] Move factory methods out of their classes.
InMemoryBuffer and OnDiskBuffer classes have both factory methods and public constructors, and that looks a bit odd. This patch makes factory methods non-member function to fix it. Differential Revision: https://reviews.llvm.org/D39693 llvm-svn: 317739
Diffstat (limited to 'llvm/lib/Support/FileOutputBuffer.cpp')
-rw-r--r--llvm/lib/Support/FileOutputBuffer.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp
index 8906be3aaa2..db8ff38e5b5 100644
--- a/llvm/lib/Support/FileOutputBuffer.cpp
+++ b/llvm/lib/Support/FileOutputBuffer.cpp
@@ -38,9 +38,6 @@ public:
std::unique_ptr<fs::mapped_file_region> Buf)
: FileOutputBuffer(Path), Buffer(std::move(Buf)), TempPath(TempPath) {}
- static Expected<std::unique_ptr<OnDiskBuffer>>
- create(StringRef Path, size_t Size, unsigned Mode);
-
uint8_t *getBufferStart() const override { return (uint8_t *)Buffer->data(); }
uint8_t *getBufferEnd() const override {
@@ -78,16 +75,6 @@ public:
InMemoryBuffer(StringRef Path, MemoryBlock Buf, unsigned Mode)
: FileOutputBuffer(Path), Buffer(Buf), Mode(Mode) {}
- static Expected<std::unique_ptr<InMemoryBuffer>>
- create(StringRef Path, size_t Size, unsigned Mode) {
- std::error_code EC;
- MemoryBlock MB = Memory::allocateMappedMemory(
- Size, nullptr, sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC);
- if (EC)
- return errorCodeToError(EC);
- return llvm::make_unique<InMemoryBuffer>(Path, MB, Mode);
- }
-
uint8_t *getBufferStart() const override { return (uint8_t *)Buffer.base(); }
uint8_t *getBufferEnd() const override {
@@ -111,8 +98,18 @@ private:
unsigned Mode;
};
-Expected<std::unique_ptr<OnDiskBuffer>>
-OnDiskBuffer::create(StringRef Path, size_t Size, unsigned Mode) {
+static Expected<std::unique_ptr<InMemoryBuffer>>
+createInMemoryBuffer(StringRef Path, size_t Size, unsigned Mode) {
+ std::error_code EC;
+ MemoryBlock MB = Memory::allocateMappedMemory(
+ Size, nullptr, sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC);
+ if (EC)
+ return errorCodeToError(EC);
+ return llvm::make_unique<InMemoryBuffer>(Path, MB, Mode);
+}
+
+static Expected<std::unique_ptr<OnDiskBuffer>>
+createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode) {
// Create new file in same directory but with random name.
SmallString<128> TempPath;
int FD;
@@ -165,8 +162,8 @@ FileOutputBuffer::create(StringRef Path, size_t Size, unsigned Flags) {
case fs::file_type::regular_file:
case fs::file_type::file_not_found:
case fs::file_type::status_error:
- return OnDiskBuffer::create(Path, Size, Mode);
+ return createOnDiskBuffer(Path, Size, Mode);
default:
- return InMemoryBuffer::create(Path, Size, Mode);
+ return createInMemoryBuffer(Path, Size, Mode);
}
}
OpenPOWER on IntegriCloud