IRObjectFile.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- IRObjectFile.h - LLVM IR object file implementation ------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares the IRObjectFile template class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_OBJECT_IROBJECTFILE_H
  18. #define LLVM_OBJECT_IROBJECTFILE_H
  19. #include "llvm/Bitcode/BitcodeReader.h"
  20. #include "llvm/Object/IRSymtab.h"
  21. #include "llvm/Object/ModuleSymbolTable.h"
  22. #include "llvm/Object/SymbolicFile.h"
  23. namespace llvm {
  24. class Module;
  25. namespace object {
  26. class ObjectFile;
  27. class IRObjectFile : public SymbolicFile {
  28. std::vector<std::unique_ptr<Module>> Mods;
  29. ModuleSymbolTable SymTab;
  30. IRObjectFile(MemoryBufferRef Object,
  31. std::vector<std::unique_ptr<Module>> Mods);
  32. public:
  33. ~IRObjectFile() override;
  34. void moveSymbolNext(DataRefImpl &Symb) const override;
  35. Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override;
  36. Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
  37. basic_symbol_iterator symbol_begin() const override;
  38. basic_symbol_iterator symbol_end() const override;
  39. StringRef getTargetTriple() const;
  40. static bool classof(const Binary *v) {
  41. return v->isIR();
  42. }
  43. using module_iterator =
  44. pointee_iterator<std::vector<std::unique_ptr<Module>>::const_iterator,
  45. const Module>;
  46. module_iterator module_begin() const { return module_iterator(Mods.begin()); }
  47. module_iterator module_end() const { return module_iterator(Mods.end()); }
  48. iterator_range<module_iterator> modules() const {
  49. return make_range(module_begin(), module_end());
  50. }
  51. /// Finds and returns bitcode embedded in the given object file, or an
  52. /// error code if not found.
  53. static Expected<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);
  54. /// Finds and returns bitcode in the given memory buffer (which may
  55. /// be either a bitcode file or a native object file with embedded bitcode),
  56. /// or an error code if not found.
  57. static Expected<MemoryBufferRef>
  58. findBitcodeInMemBuffer(MemoryBufferRef Object);
  59. static Expected<std::unique_ptr<IRObjectFile>> create(MemoryBufferRef Object,
  60. LLVMContext &Context);
  61. };
  62. /// The contents of a bitcode file and its irsymtab. Any underlying data
  63. /// for the irsymtab are owned by Symtab and Strtab.
  64. struct IRSymtabFile {
  65. std::vector<BitcodeModule> Mods;
  66. SmallVector<char, 0> Symtab, Strtab;
  67. irsymtab::Reader TheReader;
  68. };
  69. /// Reads a bitcode file, creating its irsymtab if necessary.
  70. Expected<IRSymtabFile> readIRSymtab(MemoryBufferRef MBRef);
  71. }
  72. } // namespace llvm
  73. #endif
  74. #ifdef __GNUC__
  75. #pragma GCC diagnostic pop
  76. #endif