LCOV - code coverage report
Current view: top level - include/llvm/Object - COFFImportFile.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 15 16 93.8 %
Date: 2018-10-20 13:21:21 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- COFFImportFile.h - COFF short import file implementation -*- 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             : // COFF short import file is a special kind of file which contains
      11             : // only symbol names for DLL-exported symbols. This class implements
      12             : // exporting of Symbols to create libraries and a SymbolicFile
      13             : // interface for the file type.
      14             : //
      15             : //===----------------------------------------------------------------------===//
      16             : 
      17             : #ifndef LLVM_OBJECT_COFF_IMPORT_FILE_H
      18             : #define LLVM_OBJECT_COFF_IMPORT_FILE_H
      19             : 
      20             : #include "llvm/ADT/ArrayRef.h"
      21             : #include "llvm/Object/COFF.h"
      22             : #include "llvm/Object/IRObjectFile.h"
      23             : #include "llvm/Object/ObjectFile.h"
      24             : #include "llvm/Object/SymbolicFile.h"
      25             : #include "llvm/Support/MemoryBuffer.h"
      26             : #include "llvm/Support/raw_ostream.h"
      27             : 
      28             : namespace llvm {
      29             : namespace object {
      30             : 
      31             : class COFFImportFile : public SymbolicFile {
      32             : public:
      33             :   COFFImportFile(MemoryBufferRef Source)
      34         285 :       : SymbolicFile(ID_COFFImportFile, Source) {}
      35             : 
      36           0 :   static bool classof(Binary const *V) { return V->isCOFFImportFile(); }
      37             : 
      38         547 :   void moveSymbolNext(DataRefImpl &Symb) const override { ++Symb.p; }
      39             : 
      40         547 :   std::error_code printSymbolName(raw_ostream &OS,
      41             :                                   DataRefImpl Symb) const override {
      42         547 :     if (Symb.p == 0)
      43         282 :       OS << "__imp_";
      44        1094 :     OS << StringRef(Data.getBufferStart() + sizeof(coff_import_header));
      45         547 :     return std::error_code();
      46             :   }
      47             : 
      48         502 :   uint32_t getSymbolFlags(DataRefImpl Symb) const override {
      49         502 :     return SymbolRef::SF_Global;
      50             :   }
      51             : 
      52         282 :   basic_symbol_iterator symbol_begin() const override {
      53         846 :     return BasicSymbolRef(DataRefImpl(), this);
      54             :   }
      55             : 
      56         282 :   basic_symbol_iterator symbol_end() const override {
      57             :     DataRefImpl Symb;
      58         282 :     Symb.p = isData() ? 1 : 2;
      59         846 :     return BasicSymbolRef(Symb, this);
      60             :   }
      61             : 
      62             :   const coff_import_header *getCOFFImportHeader() const {
      63             :     return reinterpret_cast<const object::coff_import_header *>(
      64             :         Data.getBufferStart());
      65             :   }
      66             : 
      67             : private:
      68             :   bool isData() const {
      69             :     return getCOFFImportHeader()->getType() == COFF::IMPORT_DATA;
      70             :   }
      71             : };
      72             : 
      73         246 : struct COFFShortExport {
      74             :   std::string Name;
      75             :   std::string ExtName;
      76             :   std::string SymbolName;
      77             :   std::string AliasTarget;
      78             : 
      79             :   uint16_t Ordinal = 0;
      80             :   bool Noname = false;
      81             :   bool Data = false;
      82             :   bool Private = false;
      83             :   bool Constant = false;
      84             : 
      85             :   friend bool operator==(const COFFShortExport &L, const COFFShortExport &R) {
      86             :     return L.Name == R.Name && L.ExtName == R.ExtName &&
      87             :             L.Ordinal == R.Ordinal && L.Noname == R.Noname &&
      88             :             L.Data == R.Data && L.Private == R.Private;
      89             :   }
      90             : 
      91             :   friend bool operator!=(const COFFShortExport &L, const COFFShortExport &R) {
      92             :     return !(L == R);
      93             :   }
      94             : };
      95             : 
      96             : Error writeImportLibrary(StringRef ImportName, StringRef Path,
      97             :                          ArrayRef<COFFShortExport> Exports,
      98             :                          COFF::MachineTypes Machine, bool MinGW);
      99             : 
     100             : } // namespace object
     101             : } // namespace llvm
     102             : 
     103             : #endif

Generated by: LCOV version 1.13