driver.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. bool enable_leaking = false)
  26. : driver_env_(std::move(fs), installation, input_stream, output_stream,
  27. error_stream, fuzzing, enable_leaking) {}
  28. // Parses the given arguments into both a subcommand to select the operation
  29. // to perform and any arguments to that subcommand.
  30. //
  31. // Returns true if the operation succeeds. If the operation fails, returns
  32. // false and any information about the failure is printed to the registered
  33. // error stream (stderr by default).
  34. auto RunCommand(llvm::ArrayRef<llvm::StringRef> args) -> DriverResult;
  35. private:
  36. DriverEnv driver_env_;
  37. };
  38. } // namespace Carbon
  39. #endif // CARBON_TOOLCHAIN_DRIVER_DRIVER_H_