summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/IRReader/IRReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/IRReader/IRReader.cpp')
-rw-r--r--contrib/llvm/lib/IRReader/IRReader.cpp71
1 files changed, 38 insertions, 33 deletions
diff --git a/contrib/llvm/lib/IRReader/IRReader.cpp b/contrib/llvm/lib/IRReader/IRReader.cpp
index 935e81d..f8d2f5a 100644
--- a/contrib/llvm/lib/IRReader/IRReader.cpp
+++ b/contrib/llvm/lib/IRReader/IRReader.cpp
@@ -8,18 +8,17 @@
//===----------------------------------------------------------------------===//
#include "llvm/IRReader/IRReader.h"
-#include "llvm/ADT/OwningPtr.h"
-#include "llvm/Assembly/Parser.h"
+#include "llvm-c/Core.h"
+#include "llvm-c/IRReader.h"
+#include "llvm/AsmParser/Parser.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"
-#include "llvm/Support/system_error.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
-#include "llvm-c/Core.h"
-#include "llvm-c/IRReader.h"
+#include <system_error>
using namespace llvm;
@@ -30,36 +29,37 @@ namespace llvm {
static const char *const TimeIRParsingGroupName = "LLVM IR Parsing";
static const char *const TimeIRParsingName = "Parse IR";
-
-Module *llvm::getLazyIRModule(MemoryBuffer *Buffer, SMDiagnostic &Err,
- LLVMContext &Context) {
+static Module *getLazyIRModule(MemoryBuffer *Buffer, SMDiagnostic &Err,
+ LLVMContext &Context) {
if (isBitcode((const unsigned char *)Buffer->getBufferStart(),
(const unsigned char *)Buffer->getBufferEnd())) {
std::string ErrMsg;
- Module *M = getLazyBitcodeModule(Buffer, Context, &ErrMsg);
- if (M == 0) {
+ ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModule(Buffer, Context);
+ if (std::error_code EC = ModuleOrErr.getError()) {
Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
- ErrMsg);
- // ParseBitcodeFile does not take ownership of the Buffer in the
+ EC.message());
+ // getLazyBitcodeModule does not take ownership of the Buffer in the
// case of an error.
delete Buffer;
+ return nullptr;
}
- return M;
+ return ModuleOrErr.get();
}
- return ParseAssembly(Buffer, 0, Err, Context);
+ return ParseAssembly(Buffer, nullptr, Err, Context);
}
Module *llvm::getLazyIRFileModule(const std::string &Filename, SMDiagnostic &Err,
LLVMContext &Context) {
- OwningPtr<MemoryBuffer> File;
- if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, File)) {
+ ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
+ MemoryBuffer::getFileOrSTDIN(Filename);
+ if (std::error_code EC = FileOrErr.getError()) {
Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
- "Could not open input file: " + ec.message());
- return 0;
+ "Could not open input file: " + EC.message());
+ return nullptr;
}
- return getLazyIRModule(File.take(), Err, Context);
+ return getLazyIRModule(FileOrErr.get().release(), Err, Context);
}
Module *llvm::ParseIR(MemoryBuffer *Buffer, SMDiagnostic &Err,
@@ -68,29 +68,33 @@ Module *llvm::ParseIR(MemoryBuffer *Buffer, SMDiagnostic &Err,
TimePassesIsEnabled);
if (isBitcode((const unsigned char *)Buffer->getBufferStart(),
(const unsigned char *)Buffer->getBufferEnd())) {
- std::string ErrMsg;
- Module *M = ParseBitcodeFile(Buffer, Context, &ErrMsg);
- if (M == 0)
+ ErrorOr<Module *> ModuleOrErr = parseBitcodeFile(Buffer, Context);
+ Module *M = nullptr;
+ if (std::error_code EC = ModuleOrErr.getError())
Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
- ErrMsg);
- // ParseBitcodeFile does not take ownership of the Buffer.
- delete Buffer;
+ EC.message());
+ else
+ M = ModuleOrErr.get();
+ // parseBitcodeFile does not take ownership of the Buffer.
return M;
}
- return ParseAssembly(Buffer, 0, Err, Context);
+ return ParseAssembly(MemoryBuffer::getMemBuffer(
+ Buffer->getBuffer(), Buffer->getBufferIdentifier()),
+ nullptr, Err, Context);
}
Module *llvm::ParseIRFile(const std::string &Filename, SMDiagnostic &Err,
LLVMContext &Context) {
- OwningPtr<MemoryBuffer> File;
- if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, File)) {
+ ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
+ MemoryBuffer::getFileOrSTDIN(Filename);
+ if (std::error_code EC = FileOrErr.getError()) {
Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
- "Could not open input file: " + ec.message());
- return 0;
+ "Could not open input file: " + EC.message());
+ return nullptr;
}
- return ParseIR(File.take(), Err, Context);
+ return ParseIR(FileOrErr.get().get(), Err, Context);
}
//===----------------------------------------------------------------------===//
@@ -102,14 +106,15 @@ LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
char **OutMessage) {
SMDiagnostic Diag;
- *OutM = wrap(ParseIR(unwrap(MemBuf), Diag, *unwrap(ContextRef)));
+ std::unique_ptr<MemoryBuffer> MB(unwrap(MemBuf));
+ *OutM = wrap(ParseIR(MB.get(), Diag, *unwrap(ContextRef)));
if(!*OutM) {
if (OutMessage) {
std::string buf;
raw_string_ostream os(buf);
- Diag.print(NULL, os, false);
+ Diag.print(nullptr, os, false);
os.flush();
*OutMessage = strdup(buf.c_str());
OpenPOWER on IntegriCloud