driver.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/codegen_options.h"
  10. #include "toolchain/driver/compile_subcommand.h"
  11. #include "toolchain/driver/driver_env.h"
  12. #include "toolchain/driver/driver_subcommand.h"
  13. #include "toolchain/driver/link_subcommand.h"
  14. namespace Carbon {
  15. // Command line interface driver.
  16. //
  17. // Provides simple API to parse and run command lines for Carbon. It is
  18. // generally expected to be used to implement command line tools for working
  19. // with the language.
  20. class Driver {
  21. public:
  22. // Constructs a driver with any error or informational output directed to a
  23. // specified stream.
  24. Driver(llvm::vfs::FileSystem& fs, const InstallPaths* installation,
  25. llvm::raw_pwrite_stream& output_stream,
  26. llvm::raw_pwrite_stream& error_stream)
  27. : driver_env_{.fs = fs,
  28. .installation = installation,
  29. .output_stream = output_stream,
  30. .error_stream = error_stream} {}
  31. // Parses the given arguments into both a subcommand to select the operation
  32. // to perform and any arguments to that subcommand.
  33. //
  34. // Returns true if the operation succeeds. If the operation fails, returns
  35. // false and any information about the failure is printed to the registered
  36. // error stream (stderr by default).
  37. auto RunCommand(llvm::ArrayRef<llvm::StringRef> args) -> DriverResult;
  38. private:
  39. DriverEnv driver_env_;
  40. };
  41. } // namespace Carbon
  42. #endif // CARBON_TOOLCHAIN_DRIVER_DRIVER_H_