IRObjectFile.h 2.3 KB

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