llvm_subcommand.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_LLVM_SUBCOMMAND_H_
  5. #define CARBON_TOOLCHAIN_DRIVER_LLVM_SUBCOMMAND_H_
  6. #include "common/command_line.h"
  7. #include "llvm/ADT/SmallVector.h"
  8. #include "llvm/ADT/StringRef.h"
  9. #include "toolchain/base/llvm_tools.h"
  10. #include "toolchain/driver/driver_env.h"
  11. #include "toolchain/driver/driver_subcommand.h"
  12. namespace Carbon {
  13. // Options for the LLVM subcommand.
  14. //
  15. // See the implementation of `Build` for documentation on members.
  16. struct LLVMOptions {
  17. // Build the LLVM subcommand options using `b`.
  18. //
  19. // When this top-level subcommand is selected (potentially through a nested
  20. // sub-subcommand), the `selected_subcommand` will be set to point to
  21. // `subcommand` to reflect that.
  22. auto Build(CommandLine::CommandBuilder& b, DriverSubcommand* subcommand,
  23. DriverSubcommand** selected_subcommand) -> void;
  24. LLVMTool subcommand_tool;
  25. llvm::SmallVector<llvm::StringRef> args;
  26. };
  27. // Implement the LLVM subcommand of the driver.
  28. //
  29. // This provides access to the full collection of LLVM command line tools.
  30. class LLVMSubcommand : public DriverSubcommand {
  31. public:
  32. explicit LLVMSubcommand();
  33. // The LLVM subcommand uses a custom subcommand structure, so `BuildOptions`
  34. // is a no-op and we override the more complex layer.
  35. auto BuildOptions(CommandLine::CommandBuilder& /*b*/) -> void override {
  36. CARBON_FATAL("Unused.");
  37. }
  38. auto BuildOptionsAndSetAction(CommandLine::CommandBuilder& b,
  39. DriverSubcommand** selected_subcommand)
  40. -> void override {
  41. options_.Build(b, this, selected_subcommand);
  42. }
  43. auto Run(DriverEnv& driver_env) -> DriverResult override;
  44. private:
  45. LLVMOptions options_;
  46. };
  47. } // namespace Carbon
  48. #endif // CARBON_TOOLCHAIN_DRIVER_LLVM_SUBCOMMAND_H_