Pass a std::unique_ptr& to the create??? methods is lib/Object.
[oota-llvm.git] / lib / Object / SymbolicFile.cpp
1 //===- SymbolicFile.cpp - Interface that only provides symbols --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a file format independent SymbolicFile class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Object/IRObjectFile.h"
15 #include "llvm/Object/ObjectFile.h"
16 #include "llvm/Object/SymbolicFile.h"
17 #include "llvm/Support/MemoryBuffer.h"
18
19 using namespace llvm;
20 using namespace object;
21
22 SymbolicFile::SymbolicFile(unsigned int Type, MemoryBuffer *Source)
23     : Binary(Type, Source) {}
24
25 SymbolicFile::~SymbolicFile() {}
26
27 ErrorOr<SymbolicFile *>
28 SymbolicFile::createSymbolicFile(std::unique_ptr<MemoryBuffer> &Object,
29                                  sys::fs::file_magic Type,
30                                  LLVMContext *Context) {
31   if (Type == sys::fs::file_magic::unknown)
32     Type = sys::fs::identify_magic(Object->getBuffer());
33
34   switch (Type) {
35   case sys::fs::file_magic::bitcode:
36     if (Context)
37       return IRObjectFile::createIRObjectFile(Object.release(), *Context);
38   // Fallthrough
39   case sys::fs::file_magic::unknown:
40   case sys::fs::file_magic::archive:
41   case sys::fs::file_magic::macho_universal_binary:
42   case sys::fs::file_magic::windows_resource:
43     return object_error::invalid_file_type;
44   case sys::fs::file_magic::elf_relocatable:
45   case sys::fs::file_magic::elf_executable:
46   case sys::fs::file_magic::elf_shared_object:
47   case sys::fs::file_magic::elf_core:
48   case sys::fs::file_magic::macho_object:
49   case sys::fs::file_magic::macho_executable:
50   case sys::fs::file_magic::macho_fixed_virtual_memory_shared_lib:
51   case sys::fs::file_magic::macho_core:
52   case sys::fs::file_magic::macho_preload_executable:
53   case sys::fs::file_magic::macho_dynamically_linked_shared_lib:
54   case sys::fs::file_magic::macho_dynamic_linker:
55   case sys::fs::file_magic::macho_bundle:
56   case sys::fs::file_magic::macho_dynamically_linked_shared_lib_stub:
57   case sys::fs::file_magic::macho_dsym_companion:
58   case sys::fs::file_magic::coff_object:
59   case sys::fs::file_magic::coff_import_library:
60   case sys::fs::file_magic::pecoff_executable:
61     return ObjectFile::createObjectFile(Object, Type);
62   }
63   llvm_unreachable("Unexpected Binary File Type");
64 }