LTO: introduce object file-based on-disk module format.
[oota-llvm.git] / include / llvm / Object / IRObjectFile.h
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/Object/SymbolicFile.h"
18
19 namespace llvm {
20 class Mangler;
21 class Module;
22 class GlobalValue;
23
24 namespace object {
25 class ObjectFile;
26
27 class IRObjectFile : public SymbolicFile {
28   std::unique_ptr<Module> M;
29   std::unique_ptr<Mangler> Mang;
30   std::vector<std::pair<std::string, uint32_t>> AsmSymbols;
31
32 public:
33   IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> M);
34   ~IRObjectFile();
35   void moveSymbolNext(DataRefImpl &Symb) const override;
36   std::error_code printSymbolName(raw_ostream &OS,
37                                   DataRefImpl Symb) const override;
38   uint32_t getSymbolFlags(DataRefImpl Symb) const override;
39   const GlobalValue *getSymbolGV(DataRefImpl Symb) const;
40   basic_symbol_iterator symbol_begin_impl() const override;
41   basic_symbol_iterator symbol_end_impl() const override;
42
43   const Module &getModule() const {
44     return const_cast<IRObjectFile*>(this)->getModule();
45   }
46   Module &getModule() {
47     return *M;
48   }
49
50   static inline bool classof(const Binary *v) {
51     return v->isIR();
52   }
53
54   /// \brief Finds and returns bitcode embedded in the given object file, or an
55   /// error code if not found.
56   static ErrorOr<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);
57
58   /// \brief Finds and returns bitcode in the given memory buffer (which may
59   /// be either a bitcode file or a native object file with embedded bitcode),
60   /// or an error code if not found.
61   static ErrorOr<MemoryBufferRef>
62   findBitcodeInMemBuffer(MemoryBufferRef Object);
63
64   static ErrorOr<std::unique_ptr<IRObjectFile>>
65   createIRObjectFile(MemoryBufferRef Object, LLVMContext &Context);
66 };
67 }
68 }
69
70 #endif