mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-20 16:17:38 +00:00
Use ErrorOr for the ::create factory on instrumented and sample profilers.
Summary: As discussed in http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20141027/242445.html, the creation of reader and writer instances is better done using ErrorOr. There are no functional changes, but several callers needed to be adjusted. Reviewers: bogner Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6076 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221120 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -21,32 +21,34 @@
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
static std::error_code
|
||||
setupMemoryBuffer(std::string Path, std::unique_ptr<MemoryBuffer> &Buffer) {
|
||||
static ErrorOr<std::unique_ptr<MemoryBuffer>>
|
||||
setupMemoryBuffer(std::string Path) {
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
|
||||
MemoryBuffer::getFileOrSTDIN(Path);
|
||||
if (std::error_code EC = BufferOrErr.getError())
|
||||
return EC;
|
||||
Buffer = std::move(BufferOrErr.get());
|
||||
auto Buffer = std::move(BufferOrErr.get());
|
||||
|
||||
// Sanity check the file.
|
||||
if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())
|
||||
return instrprof_error::too_large;
|
||||
return instrprof_error::success;
|
||||
return std::move(Buffer);
|
||||
}
|
||||
|
||||
static std::error_code initializeReader(InstrProfReader &Reader) {
|
||||
return Reader.readHeader();
|
||||
}
|
||||
|
||||
std::error_code
|
||||
InstrProfReader::create(std::string Path,
|
||||
std::unique_ptr<InstrProfReader> &Result) {
|
||||
ErrorOr<std::unique_ptr<InstrProfReader>>
|
||||
InstrProfReader::create(std::string Path) {
|
||||
// Set up the buffer to read.
|
||||
std::unique_ptr<MemoryBuffer> Buffer;
|
||||
if (std::error_code EC = setupMemoryBuffer(Path, Buffer))
|
||||
auto BufferOrError = setupMemoryBuffer(Path);
|
||||
if (std::error_code EC = BufferOrError.getError())
|
||||
return EC;
|
||||
|
||||
auto Buffer = std::move(BufferOrError.get());
|
||||
std::unique_ptr<InstrProfReader> Result;
|
||||
|
||||
// Create the reader.
|
||||
if (IndexedInstrProfReader::hasFormat(*Buffer))
|
||||
Result.reset(new IndexedInstrProfReader(std::move(Buffer)));
|
||||
@@ -58,16 +60,20 @@ InstrProfReader::create(std::string Path,
|
||||
Result.reset(new TextInstrProfReader(std::move(Buffer)));
|
||||
|
||||
// Initialize the reader and return the result.
|
||||
return initializeReader(*Result);
|
||||
if (std::error_code EC = initializeReader(*Result))
|
||||
return EC;
|
||||
|
||||
return std::move(Result);
|
||||
}
|
||||
|
||||
std::error_code IndexedInstrProfReader::create(
|
||||
std::string Path, std::unique_ptr<IndexedInstrProfReader> &Result) {
|
||||
// Set up the buffer to read.
|
||||
std::unique_ptr<MemoryBuffer> Buffer;
|
||||
if (std::error_code EC = setupMemoryBuffer(Path, Buffer))
|
||||
auto BufferOrError = setupMemoryBuffer(Path);
|
||||
if (std::error_code EC = BufferOrError.getError())
|
||||
return EC;
|
||||
|
||||
auto Buffer = std::move(BufferOrError.get());
|
||||
// Create the reader.
|
||||
if (!IndexedInstrProfReader::hasFormat(*Buffer))
|
||||
return instrprof_error::bad_magic;
|
||||
|
||||
Reference in New Issue
Block a user