driver_env.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/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. // Whether to build runtimes on-demand. Only used when `prebuilt_runtimes` is
  51. // empty.
  52. bool build_runtimes_on_demand = false;
  53. // A diagnostic consumer, to be able to connect output.
  54. Diagnostics::StreamConsumer consumer;
  55. // A diagnostic emitter that has no locations.
  56. Diagnostics::NoLocEmitter emitter;
  57. // Thread pool available for use when concurrency is needed.
  58. llvm::ThreadPoolInterface* thread_pool;
  59. // For CARBON_VLOG.
  60. llvm::raw_pwrite_stream* vlog_stream = nullptr;
  61. // Cached runtimes.
  62. Runtimes::Cache runtimes_cache;
  63. // Prebuilt runtimes.
  64. std::optional<Runtimes> prebuilt_runtimes;
  65. };
  66. } // namespace Carbon
  67. #endif // CARBON_TOOLCHAIN_DRIVER_DRIVER_ENV_H_