#include "BitcodeReader.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/AutoUpgrade.h"
#include "llvm/Bitcode/LLVMBitCodes.h"
+#include "llvm/IR/AutoUpgrade.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/InlineAsm.h"
namespace {
class BitcodeErrorCategoryType : public _do_message {
- const char *name() const LLVM_OVERRIDE {
+ const char *name() const override {
return "llvm.bitcode";
}
- std::string message(int IE) const LLVM_OVERRIDE {
+ std::string message(int IE) const override {
BitcodeReader::ErrorType E = static_cast<BitcodeReader::ErrorType>(IE);
switch (E) {
case BitcodeReader::BitcodeStreamInvalidSize:
return M;
}
-/// ParseBitcodeFile - Read the specified bitcode file, returning the module.
-/// If an error occurs, return null and fill in *ErrMsg if non-null.
-Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext& Context,
- std::string *ErrMsg){
+ErrorOr<Module *> llvm::parseBitcodeFile(MemoryBuffer *Buffer,
+ LLVMContext &Context) {
ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModule(Buffer, Context);
- if (error_code EC = ModuleOrErr.getError()) {
- if (ErrMsg)
- *ErrMsg = EC.message();
- return 0;
- }
+ if (!ModuleOrErr)
+ return ModuleOrErr;
Module *M = ModuleOrErr.get();
// Don't let the BitcodeReader dtor delete 'Buffer', regardless of whether
// Read in the entire module, and destroy the BitcodeReader.
if (error_code EC = M->materializeAllPermanently()) {
- if (ErrMsg)
- *ErrMsg = EC.message();
delete M;
- return 0;
+ return EC;
}
// TODO: Restore the use-lists to the in-memory state when the bitcode was