Be a bit more consistent about using ErrorOr when constructing Binary objects.
[oota-llvm.git] / lib / Object / Binary.cpp
index f1da11ceab58bb92d4dd90d8b2f528b4b3fe4bc3..4f35d9752626353d49e4029463e7051218f435e9 100644 (file)
@@ -19,7 +19,6 @@
 
 // Include headers for createBinary.
 #include "llvm/Object/Archive.h"
-#include "llvm/Object/COFF.h"
 #include "llvm/Object/MachOUniversal.h"
 #include "llvm/Object/ObjectFile.h"
 
@@ -45,24 +44,14 @@ StringRef Binary::getFileName() const {
 ErrorOr<Binary *> object::createBinary(MemoryBuffer *Source) {
   OwningPtr<MemoryBuffer> scopedSource(Source);
   sys::fs::file_magic type = sys::fs::identify_magic(Source->getBuffer());
-  error_code EC;
   switch (type) {
-    case sys::fs::file_magic::archive: {
-      OwningPtr<Binary> Ret(new Archive(scopedSource.take(), EC));
-      if (EC)
-        return EC;
-      return Ret.take();
-    }
+    case sys::fs::file_magic::archive:
+      return Archive::create(scopedSource.take());
     case sys::fs::file_magic::elf_relocatable:
     case sys::fs::file_magic::elf_executable:
     case sys::fs::file_magic::elf_shared_object:
-    case sys::fs::file_magic::elf_core: {
-      OwningPtr<Binary> Ret(
-          ObjectFile::createELFObjectFile(scopedSource.take()));
-      if (!Ret)
-        return object_error::invalid_file_type;
-      return Ret.take();
-    }
+    case sys::fs::file_magic::elf_core:
+      return ObjectFile::createELFObjectFile(scopedSource.take());
     case sys::fs::file_magic::macho_object:
     case sys::fs::file_magic::macho_executable:
     case sys::fs::file_magic::macho_fixed_virtual_memory_shared_lib:
@@ -72,28 +61,14 @@ ErrorOr<Binary *> object::createBinary(MemoryBuffer *Source) {
     case sys::fs::file_magic::macho_dynamic_linker:
     case sys::fs::file_magic::macho_bundle:
     case sys::fs::file_magic::macho_dynamically_linked_shared_lib_stub:
-    case sys::fs::file_magic::macho_dsym_companion: {
-      OwningPtr<Binary> Ret(
-          ObjectFile::createMachOObjectFile(scopedSource.take()));
-      if (!Ret)
-        return object_error::invalid_file_type;
-      return Ret.take();
-    }
-    case sys::fs::file_magic::macho_universal_binary: {
-      OwningPtr<Binary> Ret(new MachOUniversalBinary(scopedSource.take(), EC));
-      if (EC)
-        return EC;
-      return Ret.take();
-    }
+    case sys::fs::file_magic::macho_dsym_companion:
+      return ObjectFile::createMachOObjectFile(scopedSource.take());
+    case sys::fs::file_magic::macho_universal_binary:
+      return MachOUniversalBinary::create(scopedSource.take());
     case sys::fs::file_magic::coff_object:
     case sys::fs::file_magic::coff_import_library:
-    case sys::fs::file_magic::pecoff_executable: {
-      OwningPtr<Binary> Ret(
-          ObjectFile::createCOFFObjectFile(scopedSource.take()));
-      if (!Ret)
-        return object_error::invalid_file_type;
-      return Ret.take();
-    }
+    case sys::fs::file_magic::pecoff_executable:
+      return ObjectFile::createCOFFObjectFile(scopedSource.take());
     case sys::fs::file_magic::unknown:
     case sys::fs::file_magic::bitcode:
     case sys::fs::file_magic::windows_resource: {