LCOV - code coverage report
Current view: top level - lib/Object - SymbolicFile.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 22 23 95.7 %
Date: 2018-06-17 00:07:59 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- SymbolicFile.cpp - Interface that only provides symbols ------------===//
       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/SymbolicFile.h"
      15             : #include "llvm/ADT/StringRef.h"
      16             : #include "llvm/BinaryFormat/Magic.h"
      17             : #include "llvm/Object/COFFImportFile.h"
      18             : #include "llvm/Object/Error.h"
      19             : #include "llvm/Object/IRObjectFile.h"
      20             : #include "llvm/Object/ObjectFile.h"
      21             : #include "llvm/Support/Compiler.h"
      22             : #include "llvm/Support/Error.h"
      23             : #include "llvm/Support/ErrorHandling.h"
      24             : #include "llvm/Support/ErrorOr.h"
      25             : #include "llvm/Support/FileSystem.h"
      26             : #include "llvm/Support/MemoryBuffer.h"
      27             : #include <algorithm>
      28             : #include <memory>
      29             : 
      30             : using namespace llvm;
      31             : using namespace object;
      32             : 
      33       21194 : SymbolicFile::SymbolicFile(unsigned int Type, MemoryBufferRef Source)
      34       21194 :     : Binary(Type, Source) {}
      35             : 
      36             : SymbolicFile::~SymbolicFile() = default;
      37             : 
      38             : Expected<std::unique_ptr<SymbolicFile>>
      39        8080 : SymbolicFile::createSymbolicFile(MemoryBufferRef Object, file_magic Type,
      40             :                                  LLVMContext *Context) {
      41        8080 :   StringRef Data = Object.getBuffer();
      42        8080 :   if (Type == file_magic::unknown)
      43         854 :     Type = identify_magic(Data);
      44             : 
      45        8080 :   switch (Type) {
      46          49 :   case file_magic::bitcode:
      47          49 :     if (Context)
      48          98 :       return IRObjectFile::create(Object, *Context);
      49             :     LLVM_FALLTHROUGH;
      50             :   case file_magic::unknown:
      51             :   case file_magic::archive:
      52             :   case file_magic::coff_cl_gl_object:
      53             :   case file_magic::macho_universal_binary:
      54             :   case file_magic::windows_resource:
      55             :   case file_magic::pdb:
      56         180 :     return errorCodeToError(object_error::invalid_file_type);
      57        3007 :   case file_magic::elf:
      58             :   case file_magic::elf_executable:
      59             :   case file_magic::elf_shared_object:
      60             :   case file_magic::elf_core:
      61             :   case file_magic::macho_executable:
      62             :   case file_magic::macho_fixed_virtual_memory_shared_lib:
      63             :   case file_magic::macho_core:
      64             :   case file_magic::macho_preload_executable:
      65             :   case file_magic::macho_dynamically_linked_shared_lib:
      66             :   case file_magic::macho_dynamic_linker:
      67             :   case file_magic::macho_bundle:
      68             :   case file_magic::macho_dynamically_linked_shared_lib_stub:
      69             :   case file_magic::macho_dsym_companion:
      70             :   case file_magic::macho_kext_bundle:
      71             :   case file_magic::pecoff_executable:
      72             :   case file_magic::wasm_object:
      73        6013 :     return ObjectFile::createObjectFile(Object, Type);
      74         268 :   case file_magic::coff_import_library:
      75         268 :     return std::unique_ptr<SymbolicFile>(new COFFImportFile(Object));
      76        4666 :   case file_magic::elf_relocatable:
      77             :   case file_magic::macho_object:
      78             :   case file_magic::coff_object: {
      79             :     Expected<std::unique_ptr<ObjectFile>> Obj =
      80        9332 :         ObjectFile::createObjectFile(Object, Type);
      81        4666 :     if (!Obj || !Context)
      82             :       return std::move(Obj);
      83             : 
      84             :     Expected<MemoryBufferRef> BCData =
      85         777 :         IRObjectFile::findBitcodeInObject(*Obj->get());
      86         777 :     if (!BCData) {
      87        1548 :       consumeError(BCData.takeError());
      88             :       return std::move(Obj);
      89             :     }
      90             : 
      91           6 :     return IRObjectFile::create(
      92             :         MemoryBufferRef(BCData->getBuffer(), Object.getBufferIdentifier()),
      93             :         *Context);
      94             :   }
      95             :   }
      96           0 :   llvm_unreachable("Unexpected Binary File Type");
      97             : }

Generated by: LCOV version 1.13