LLVM API Documentation

SymbolicFile.cpp
Go to the documentation of this file.
00001 //===- SymbolicFile.cpp - Interface that only provides symbols --*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines a file format independent SymbolicFile class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Object/IRObjectFile.h"
00015 #include "llvm/Object/ObjectFile.h"
00016 #include "llvm/Object/SymbolicFile.h"
00017 #include "llvm/Support/MemoryBuffer.h"
00018 
00019 using namespace llvm;
00020 using namespace object;
00021 
00022 SymbolicFile::SymbolicFile(unsigned int Type, MemoryBufferRef Source)
00023     : Binary(Type, Source) {}
00024 
00025 SymbolicFile::~SymbolicFile() {}
00026 
00027 ErrorOr<std::unique_ptr<SymbolicFile>> SymbolicFile::createSymbolicFile(
00028     MemoryBufferRef Object, sys::fs::file_magic Type, LLVMContext *Context) {
00029   StringRef Data = Object.getBuffer();
00030   if (Type == sys::fs::file_magic::unknown)
00031     Type = sys::fs::identify_magic(Data);
00032 
00033   switch (Type) {
00034   case sys::fs::file_magic::bitcode:
00035     if (Context)
00036       return IRObjectFile::createIRObjectFile(Object, *Context);
00037   // Fallthrough
00038   case sys::fs::file_magic::unknown:
00039   case sys::fs::file_magic::archive:
00040   case sys::fs::file_magic::macho_universal_binary:
00041   case sys::fs::file_magic::windows_resource:
00042     return object_error::invalid_file_type;
00043   case sys::fs::file_magic::elf_relocatable:
00044   case sys::fs::file_magic::elf_executable:
00045   case sys::fs::file_magic::elf_shared_object:
00046   case sys::fs::file_magic::elf_core:
00047   case sys::fs::file_magic::macho_object:
00048   case sys::fs::file_magic::macho_executable:
00049   case sys::fs::file_magic::macho_fixed_virtual_memory_shared_lib:
00050   case sys::fs::file_magic::macho_core:
00051   case sys::fs::file_magic::macho_preload_executable:
00052   case sys::fs::file_magic::macho_dynamically_linked_shared_lib:
00053   case sys::fs::file_magic::macho_dynamic_linker:
00054   case sys::fs::file_magic::macho_bundle:
00055   case sys::fs::file_magic::macho_dynamically_linked_shared_lib_stub:
00056   case sys::fs::file_magic::macho_dsym_companion:
00057   case sys::fs::file_magic::coff_object:
00058   case sys::fs::file_magic::coff_import_library:
00059   case sys::fs::file_magic::pecoff_executable:
00060     return ObjectFile::createObjectFile(Object, Type);
00061   }
00062   llvm_unreachable("Unexpected Binary File Type");
00063 }