[Object] Fix a bug in a condition introduced in r226217 - visibility can't be
[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   GlobalValue *getSymbolGV(DataRefImpl Symb);
40   const GlobalValue *getSymbolGV(DataRefImpl Symb) const {
41     return const_cast<IRObjectFile *>(this)->getSymbolGV(Symb);
42   }
43   basic_symbol_iterator symbol_begin_impl() const override;
44   basic_symbol_iterator symbol_end_impl() const override;
45
46   const Module &getModule() const {
47     return const_cast<IRObjectFile*>(this)->getModule();
48   }
49   Module &getModule() {
50     return *M;
51   }
52   std::unique_ptr<Module> takeModule();
53
54   static inline bool classof(const Binary *v) {
55     return v->isIR();
56   }
57
58   /// \brief Finds and returns bitcode embedded in the given object file, or an
59   /// error code if not found.
60   static ErrorOr<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);
61
62   /// \brief Finds and returns bitcode in the given memory buffer (which may
63   /// be either a bitcode file or a native object file with embedded bitcode),
64   /// or an error code if not found.
65   static ErrorOr<MemoryBufferRef>
66   findBitcodeInMemBuffer(MemoryBufferRef Object);
67
68   static ErrorOr<std::unique_ptr<IRObjectFile>> create(MemoryBufferRef Object,
69                                                        LLVMContext &Context);
70 };
71 }
72 }
73
74 #endif