blob: 790d5a75ba7f68db7e3c5f00951a899fd043b87e [file] [log] [blame]
Rafael Espindolaf12b8282014-02-21 20:10:59 +00001//===- 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
19using namespace llvm;
20using namespace object;
21
Rafael Espindola2e60ca92014-06-24 13:56:32 +000022SymbolicFile::SymbolicFile(unsigned int Type,
23 std::unique_ptr<MemoryBuffer> Source)
24 : Binary(Type, std::move(Source)) {}
Rafael Espindolaf12b8282014-02-21 20:10:59 +000025
26SymbolicFile::~SymbolicFile() {}
27
Rafael Espindola437b0d52014-07-31 03:12:45 +000028ErrorOr<std::unique_ptr<SymbolicFile>>
Rafael Espindola6304e942014-06-23 22:00:37 +000029SymbolicFile::createSymbolicFile(std::unique_ptr<MemoryBuffer> &Object,
30 sys::fs::file_magic Type,
Rafael Espindolaf12b8282014-02-21 20:10:59 +000031 LLVMContext *Context) {
32 if (Type == sys::fs::file_magic::unknown)
33 Type = sys::fs::identify_magic(Object->getBuffer());
34
35 switch (Type) {
36 case sys::fs::file_magic::bitcode:
37 if (Context)
Rafael Espindola2e60ca92014-06-24 13:56:32 +000038 return IRObjectFile::createIRObjectFile(std::move(Object), *Context);
Rafael Espindolaf12b8282014-02-21 20:10:59 +000039 // Fallthrough
40 case sys::fs::file_magic::unknown:
41 case sys::fs::file_magic::archive:
42 case sys::fs::file_magic::macho_universal_binary:
43 case sys::fs::file_magic::windows_resource:
Rafael Espindolaf12b8282014-02-21 20:10:59 +000044 return object_error::invalid_file_type;
45 case sys::fs::file_magic::elf_relocatable:
46 case sys::fs::file_magic::elf_executable:
47 case sys::fs::file_magic::elf_shared_object:
48 case sys::fs::file_magic::elf_core:
49 case sys::fs::file_magic::macho_object:
50 case sys::fs::file_magic::macho_executable:
51 case sys::fs::file_magic::macho_fixed_virtual_memory_shared_lib:
52 case sys::fs::file_magic::macho_core:
53 case sys::fs::file_magic::macho_preload_executable:
54 case sys::fs::file_magic::macho_dynamically_linked_shared_lib:
55 case sys::fs::file_magic::macho_dynamic_linker:
56 case sys::fs::file_magic::macho_bundle:
57 case sys::fs::file_magic::macho_dynamically_linked_shared_lib_stub:
58 case sys::fs::file_magic::macho_dsym_companion:
59 case sys::fs::file_magic::coff_object:
60 case sys::fs::file_magic::coff_import_library:
61 case sys::fs::file_magic::pecoff_executable:
Rafael Espindolac3f9b5a2014-06-23 21:53:12 +000062 return ObjectFile::createObjectFile(Object, Type);
Rafael Espindolaf12b8282014-02-21 20:10:59 +000063 }
64 llvm_unreachable("Unexpected Binary File Type");
65}