driver_env.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. : fs(std::move(fs)),
  20. installation(installation),
  21. input_stream(input_stream),
  22. output_stream(output_stream),
  23. error_stream(error_stream),
  24. fuzzing(fuzzing),
  25. consumer(error_stream),
  26. emitter(&consumer) {}
  27. // The filesystem for source code.
  28. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs;
  29. // Helper to locate the toolchain installation's files.
  30. const InstallPaths* installation;
  31. // Standard input; stdin. May be null, to prevent accidental use.
  32. FILE* input_stream;
  33. // Standard output; stdout.
  34. llvm::raw_pwrite_stream* output_stream;
  35. // Error output; stderr.
  36. llvm::raw_pwrite_stream* error_stream;
  37. // Tracks when the driver is being fuzzed. This allows specific commands to
  38. // error rather than perform operations that aren't well behaved during
  39. // fuzzing.
  40. bool fuzzing;
  41. // A diagnostic consumer, to be able to connect output.
  42. StreamDiagnosticConsumer consumer;
  43. // A diagnostic emitter that has no locations.
  44. NoLocDiagnosticEmitter emitter;
  45. // For CARBON_VLOG.
  46. llvm::raw_pwrite_stream* vlog_stream = nullptr;
  47. };
  48. } // namespace Carbon
  49. #endif // CARBON_TOOLCHAIN_DRIVER_DRIVER_ENV_H_