Reproducer.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //===- tools/dsymutil/Reproducer.h ------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_TOOLS_DSYMUTIL_REPRODUCER_H
  9. #define LLVM_TOOLS_DSYMUTIL_REPRODUCER_H
  10. #include "llvm/Support/Error.h"
  11. #include "llvm/Support/FileCollector.h"
  12. #include "llvm/Support/VirtualFileSystem.h"
  13. namespace llvm {
  14. namespace dsymutil {
  15. /// The reproducer mode.
  16. enum class ReproducerMode {
  17. Generate,
  18. Use,
  19. Off,
  20. };
  21. /// The reproducer class manages the sate related to reproducers in dsymutil.
  22. /// Instances should be created with Reproducer::createReproducer. An instance
  23. /// of this class is returned when reproducers are off. The VFS returned by
  24. /// this instance is the real file system.
  25. class Reproducer {
  26. public:
  27. Reproducer();
  28. virtual ~Reproducer();
  29. IntrusiveRefCntPtr<vfs::FileSystem> getVFS() const { return VFS; }
  30. /// Create a Reproducer instance based on the given mode.
  31. static llvm::Expected<std::unique_ptr<Reproducer>>
  32. createReproducer(ReproducerMode Mode, StringRef Root);
  33. protected:
  34. IntrusiveRefCntPtr<vfs::FileSystem> VFS;
  35. };
  36. /// Reproducer instance used to generate a new reproducer. The VFS returned by
  37. /// this instance is a FileCollectorFileSystem that tracks every file used by
  38. /// dsymutil.
  39. class ReproducerGenerate : public Reproducer {
  40. public:
  41. ReproducerGenerate(std::error_code &EC);
  42. ~ReproducerGenerate() override;
  43. private:
  44. /// The path to the reproducer.
  45. std::string Root;
  46. /// The FileCollector used by the FileCollectorFileSystem.
  47. std::shared_ptr<FileCollector> FC;
  48. };
  49. /// Reproducer instance used to use an existing reproducer. The VFS returned by
  50. /// this instance is a RedirectingFileSystem that remaps paths to their
  51. /// counterpart in the reproducer.
  52. class ReproducerUse : public Reproducer {
  53. public:
  54. ReproducerUse(StringRef Root, std::error_code &EC);
  55. ~ReproducerUse() override;
  56. private:
  57. /// The path to the reproducer.
  58. std::string Root;
  59. };
  60. } // end namespace dsymutil
  61. } // end namespace llvm
  62. #endif // LLVM_TOOLS_DSYMUTIL_REPRODUCER_H