driver_env.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/VirtualFileSystem.h"
  10. #include "toolchain/diagnostics/diagnostic_emitter.h"
  11. #include "toolchain/install/install_paths.h"
  12. namespace Carbon {
  13. // Driver environment information, encapsulated for easy passing to subcommands.
  14. struct DriverEnv {
  15. explicit DriverEnv(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
  16. const InstallPaths* installation, FILE* input_stream,
  17. llvm::raw_pwrite_stream* output_stream,
  18. llvm::raw_pwrite_stream* error_stream, bool fuzzing,
  19. bool enable_leaking)
  20. : fs(std::move(fs)),
  21. installation(installation),
  22. input_stream(input_stream),
  23. output_stream(output_stream),
  24. error_stream(error_stream),
  25. fuzzing(fuzzing),
  26. enable_leaking(enable_leaking),
  27. consumer(error_stream),
  28. emitter(&consumer) {}
  29. // The filesystem for source code.
  30. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs;
  31. // Helper to locate the toolchain installation's files.
  32. const InstallPaths* installation;
  33. // Standard input; stdin. May be null, to prevent accidental use.
  34. FILE* input_stream;
  35. // Standard output; stdout.
  36. llvm::raw_pwrite_stream* output_stream;
  37. // Error output; stderr.
  38. llvm::raw_pwrite_stream* error_stream;
  39. // Tracks when the driver is being fuzzed. This allows specific commands to
  40. // error rather than perform operations that aren't well behaved during
  41. // fuzzing.
  42. bool fuzzing;
  43. // Tracks whether the driver can leak resources, typically because it is being
  44. // invoked as part of a single command line program execution. Defaults to
  45. // `false` for safe and correct library execution.
  46. bool enable_leaking = false;
  47. // A diagnostic consumer, to be able to connect output.
  48. Diagnostics::StreamConsumer consumer;
  49. // A diagnostic emitter that has no locations.
  50. Diagnostics::NoLocEmitter emitter;
  51. // For CARBON_VLOG.
  52. llvm::raw_pwrite_stream* vlog_stream = nullptr;
  53. };
  54. } // namespace Carbon
  55. #endif // CARBON_TOOLCHAIN_DRIVER_DRIVER_ENV_H_