IRObjectFile.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/ADT/PointerUnion.h"
  20. #include "llvm/Object/IRSymtab.h"
  21. #include "llvm/Object/ModuleSymbolTable.h"
  22. #include "llvm/Object/SymbolicFile.h"
  23. namespace llvm {
  24. class BitcodeModule;
  25. class Mangler;
  26. class Module;
  27. class GlobalValue;
  28. class Triple;
  29. namespace object {
  30. class ObjectFile;
  31. class IRObjectFile : public SymbolicFile {
  32. std::vector<std::unique_ptr<Module>> Mods;
  33. ModuleSymbolTable SymTab;
  34. IRObjectFile(MemoryBufferRef Object,
  35. std::vector<std::unique_ptr<Module>> Mods);
  36. public:
  37. ~IRObjectFile() override;
  38. void moveSymbolNext(DataRefImpl &Symb) const override;
  39. Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override;
  40. Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
  41. basic_symbol_iterator symbol_begin() const override;
  42. basic_symbol_iterator symbol_end() const override;
  43. StringRef getTargetTriple() const;
  44. static bool classof(const Binary *v) {
  45. return v->isIR();
  46. }
  47. using module_iterator =
  48. pointee_iterator<std::vector<std::unique_ptr<Module>>::const_iterator,
  49. const Module>;
  50. module_iterator module_begin() const { return module_iterator(Mods.begin()); }
  51. module_iterator module_end() const { return module_iterator(Mods.end()); }
  52. iterator_range<module_iterator> modules() const {
  53. return make_range(module_begin(), module_end());
  54. }
  55. /// Finds and returns bitcode embedded in the given object file, or an
  56. /// error code if not found.
  57. static Expected<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);
  58. /// 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 Expected<MemoryBufferRef>
  62. findBitcodeInMemBuffer(MemoryBufferRef Object);
  63. static Expected<std::unique_ptr<IRObjectFile>> create(MemoryBufferRef Object,
  64. LLVMContext &Context);
  65. };
  66. /// The contents of a bitcode file and its irsymtab. Any underlying data
  67. /// for the irsymtab are owned by Symtab and Strtab.
  68. struct IRSymtabFile {
  69. std::vector<BitcodeModule> Mods;
  70. SmallVector<char, 0> Symtab, Strtab;
  71. irsymtab::Reader TheReader;
  72. };
  73. /// Reads a bitcode file, creating its irsymtab if necessary.
  74. Expected<IRSymtabFile> readIRSymtab(MemoryBufferRef MBRef);
  75. }
  76. }
  77. #endif
  78. #ifdef __GNUC__
  79. #pragma GCC diagnostic pop
  80. #endif