1 //===- IRObjectFile.h - LLVM IR object 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 // This file declares the IRObjectFile template class. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_OBJECT_IROBJECTFILE_H 15 #define LLVM_OBJECT_IROBJECTFILE_H 16 17 #include "llvm/ADT/PointerUnion.h" 18 #include "llvm/Object/IRSymtab.h" 19 #include "llvm/Object/ModuleSymbolTable.h" 20 #include "llvm/Object/SymbolicFile.h" 21 22 namespace llvm { 23 class BitcodeModule; 24 class Mangler; 25 class Module; 26 class GlobalValue; 27 class Triple; 28 29 namespace object { 30 class ObjectFile; 31 32 class IRObjectFile : public SymbolicFile { 33 std::vector<std::unique_ptr<Module>> Mods; 34 ModuleSymbolTable SymTab; 35 IRObjectFile(MemoryBufferRef Object, 36 std::vector<std::unique_ptr<Module>> Mods); 37 38 public: 39 ~IRObjectFile() override; 40 void moveSymbolNext(DataRefImpl &Symb) const override; 41 std::error_code printSymbolName(raw_ostream &OS, 42 DataRefImpl Symb) const override; 43 uint32_t getSymbolFlags(DataRefImpl Symb) const override; 44 basic_symbol_iterator symbol_begin() const override; 45 basic_symbol_iterator symbol_end() const override; 46 47 StringRef getTargetTriple() const; 48 49 static bool classof(const Binary *v) { 50 return v->isIR(); 51 } 52 53 /// \brief Finds and returns bitcode embedded in the given object file, or an 54 /// error code if not found. 55 static Expected<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj); 56 57 /// \brief Finds and returns bitcode in the given memory buffer (which may 58 /// be either a bitcode file or a native object file with embedded bitcode), 59 /// or an error code if not found. 60 static Expected<MemoryBufferRef> 61 findBitcodeInMemBuffer(MemoryBufferRef Object); 62 63 static Expected<std::unique_ptr<IRObjectFile>> create(MemoryBufferRef Object, 64 LLVMContext &Context); 65 }; 66 67 /// The contents of a bitcode file and its irsymtab. Any underlying data 68 /// for the irsymtab are owned by Symtab and Strtab. 69 struct IRSymtabFile { 70 std::vector<BitcodeModule> Mods; 71 SmallVector<char, 0> Symtab, Strtab; 72 irsymtab::Reader TheReader; 73 }; 74 75 /// Reads a bitcode file, creating its irsymtab if necessary. 76 Expected<IRSymtabFile> readIRSymtab(MemoryBufferRef MBRef); 77 78 } 79 80 } 81 82 #endif 83