driver.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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_H_
  5. #define CARBON_TOOLCHAIN_DRIVER_DRIVER_H_
  6. #include "common/command_line.h"
  7. #include "llvm/ADT/ArrayRef.h"
  8. #include "llvm/ADT/StringRef.h"
  9. #include "toolchain/driver/driver_env.h"
  10. #include "toolchain/driver/driver_subcommand.h"
  11. namespace Carbon {
  12. // Command line interface driver.
  13. //
  14. // Provides simple API to parse and run command lines for Carbon. It is
  15. // generally expected to be used to implement command line tools for working
  16. // with the language.
  17. class Driver {
  18. public:
  19. // Constructs a driver with the provided environment. `input_stream` is
  20. // optional; other parameters are required.
  21. explicit Driver(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
  22. const InstallPaths* installation, FILE* input_stream,
  23. llvm::raw_pwrite_stream* output_stream,
  24. llvm::raw_pwrite_stream* error_stream, bool fuzzing = false)
  25. : driver_env_(std::move(fs), installation, input_stream, output_stream,
  26. error_stream, fuzzing) {}
  27. // Parses the given arguments into both a subcommand to select the operation
  28. // to perform and any arguments to that subcommand.
  29. //
  30. // Returns true if the operation succeeds. If the operation fails, returns
  31. // false and any information about the failure is printed to the registered
  32. // error stream (stderr by default).
  33. auto RunCommand(llvm::ArrayRef<llvm::StringRef> args) -> DriverResult;
  34. private:
  35. DriverEnv driver_env_;
  36. };
  37. } // namespace Carbon
  38. #endif // CARBON_TOOLCHAIN_DRIVER_DRIVER_H_