Line data Source code
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 1606 : return v->isIR();
51 : }
52 :
53 : using module_iterator =
54 : pointee_iterator<std::vector<std::unique_ptr<Module>>::const_iterator,
55 : const Module>;
56 :
57 : module_iterator module_begin() const { return module_iterator(Mods.begin()); }
58 : module_iterator module_end() const { return module_iterator(Mods.end()); }
59 :
60 : iterator_range<module_iterator> modules() const {
61 : return make_range(module_begin(), module_end());
62 : }
63 :
64 : /// Finds and returns bitcode embedded in the given object file, or an
65 : /// error code if not found.
66 : static Expected<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);
67 :
68 : /// Finds and returns bitcode in the given memory buffer (which may
69 : /// be either a bitcode file or a native object file with embedded bitcode),
70 : /// or an error code if not found.
71 : static Expected<MemoryBufferRef>
72 : findBitcodeInMemBuffer(MemoryBufferRef Object);
73 :
74 : static Expected<std::unique_ptr<IRObjectFile>> create(MemoryBufferRef Object,
75 : LLVMContext &Context);
76 : };
77 :
78 : /// The contents of a bitcode file and its irsymtab. Any underlying data
79 : /// for the irsymtab are owned by Symtab and Strtab.
80 : struct IRSymtabFile {
81 : std::vector<BitcodeModule> Mods;
82 : SmallVector<char, 0> Symtab, Strtab;
83 : irsymtab::Reader TheReader;
84 : };
85 :
86 : /// Reads a bitcode file, creating its irsymtab if necessary.
87 : Expected<IRSymtabFile> readIRSymtab(MemoryBufferRef MBRef);
88 :
89 : }
90 :
91 : }
92 :
93 : #endif
|