driver_env.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_DRIVER_DRIVER_ENV_H_
  5. #define CARBON_TOOLCHAIN_DRIVER_DRIVER_ENV_H_
  6. #include <cstdio>
  7. #include <utility>
  8. #include "common/ostream.h"
  9. #include "llvm/Support/ThreadPool.h"
  10. #include "llvm/Support/Threading.h"
  11. #include "llvm/Support/VirtualFileSystem.h"
  12. #include "toolchain/base/install_paths.h"
  13. #include "toolchain/diagnostics/diagnostic_emitter.h"
  14. #include "toolchain/driver/runtimes_cache.h"
  15. namespace Carbon {
  16. // Driver environment information, encapsulated for easy passing to subcommands.
  17. struct DriverEnv {
  18. explicit DriverEnv(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
  19. const InstallPaths* installation, FILE* input_stream,
  20. llvm::raw_pwrite_stream* output_stream,
  21. llvm::raw_pwrite_stream* error_stream, bool fuzzing,
  22. bool enable_leaking)
  23. : fs(std::move(fs)),
  24. installation(installation),
  25. input_stream(input_stream),
  26. output_stream(output_stream),
  27. error_stream(error_stream),
  28. fuzzing(fuzzing),
  29. enable_leaking(enable_leaking),
  30. consumer(error_stream),
  31. emitter(&consumer) {}
  32. // The filesystem for source code.
  33. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs;
  34. // Helper to locate the toolchain installation's files.
  35. const InstallPaths* installation;
  36. // Standard input; stdin. May be null, to prevent accidental use.
  37. FILE* input_stream;
  38. // Standard output; stdout.
  39. llvm::raw_pwrite_stream* output_stream;
  40. // Error output; stderr.
  41. llvm::raw_pwrite_stream* error_stream;
  42. // Tracks when the driver is being fuzzed. This allows specific commands to
  43. // error rather than perform operations that aren't well behaved during
  44. // fuzzing.
  45. bool fuzzing;
  46. // Tracks whether the driver can leak resources, typically because it is being
  47. // invoked as part of a single command line program execution. Defaults to
  48. // `false` for safe and correct library execution.
  49. bool enable_leaking = false;
  50. // A diagnostic consumer, to be able to connect output.
  51. Diagnostics::StreamConsumer consumer;
  52. // A diagnostic emitter that has no locations.
  53. Diagnostics::NoLocEmitter emitter;
  54. // Thread pool available for use when concurrency is needed.
  55. llvm::ThreadPoolInterface* thread_pool;
  56. // For CARBON_VLOG.
  57. llvm::raw_pwrite_stream* vlog_stream = nullptr;
  58. // Cached runtimes.
  59. Runtimes::Cache runtimes_cache;
  60. // Prebuilt runtimes.
  61. std::optional<Runtimes> prebuilt_runtimes;
  62. };
  63. } // namespace Carbon
  64. #endif // CARBON_TOOLCHAIN_DRIVER_DRIVER_ENV_H_