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