Add whitespace to try to fix bulleted list.
[oota-llvm.git] / lib / Object / Binary.cpp
index a0c412a64b282b83975a09a8f29de3b12288b00d..c7f868fcdd1453050ac80a4b880737b2bc6908bf 100644 (file)
@@ -26,12 +26,12 @@ using namespace llvm;
 using namespace object;
 
 Binary::~Binary() {
-  delete Data;
+  if (BufferOwned)
+    delete Data;
 }
 
-Binary::Binary(unsigned int Type, MemoryBuffer *Source)
-  : TypeID(Type)
-  , Data(Source) {}
+Binary::Binary(unsigned int Type, MemoryBuffer *Source, bool BufferOwned)
+  : TypeID(Type), BufferOwned(BufferOwned), Data(Source) {}
 
 StringRef Binary::getData() const {
   return Data->getBuffer();
@@ -42,10 +42,9 @@ StringRef Binary::getFileName() const {
 }
 
 ErrorOr<Binary *> object::createBinary(MemoryBuffer *Source,
-                                       sys::fs::file_magic Type) {
+                                       LLVMContext *Context) {
   OwningPtr<MemoryBuffer> scopedSource(Source);
-  if (Type == sys::fs::file_magic::unknown)
-    Type = sys::fs::identify_magic(Source->getBuffer());
+  sys::fs::file_magic Type = sys::fs::identify_magic(Source->getBuffer());
 
   switch (Type) {
     case sys::fs::file_magic::archive:
@@ -67,11 +66,12 @@ ErrorOr<Binary *> object::createBinary(MemoryBuffer *Source,
     case sys::fs::file_magic::coff_object:
     case sys::fs::file_magic::coff_import_library:
     case sys::fs::file_magic::pecoff_executable:
-      return ObjectFile::createObjectFile(scopedSource.take(), Type);
+    case sys::fs::file_magic::bitcode:
+      return ObjectFile::createSymbolicFile(scopedSource.take(), true, Type,
+                                            Context);
     case sys::fs::file_magic::macho_universal_binary:
       return MachOUniversalBinary::create(scopedSource.take());
     case sys::fs::file_magic::unknown:
-    case sys::fs::file_magic::bitcode:
     case sys::fs::file_magic::windows_resource:
       // Unrecognized object file format.
       return object_error::invalid_file_type;