mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
This adds support for most of the remaining LLVM command line tools using a generic, generated wrapper. The subcommand interface for these is (much) less interesting than our other subcommands, but it gives us a uniform and consistent layer. Note that I structured these as nested sub-sub-commands below an `llvm` subcommand because of an expectation that we will want to add more, and ones that don't use this generic layer. Some concrete future work: - Add the `opt` and `llc` tools as subcommands for easier debugging and experimentation with LLVM IR output from Carbon's toolchain. - Potentially sink `lld` below the `llvm` layer given that it has significantly less user visibility than commands like `clang`. Unfortunately, the current driver subcommand APIs make nested subcommands awkward. I've added a somewhat rough hack here to let the LLVM tools go in, but there are some TODOs that I want to address in a follow-up that works to adjust the structure of this code to be more conducive to nesting like this. Depends on #5048 -- only the last commit should be reviewed here. --------- Co-authored-by: Geoff Romer <gromer@google.com>
60 lines
1.9 KiB
C++
60 lines
1.9 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef CARBON_TOOLCHAIN_DRIVER_LLVM_SUBCOMMAND_H_
|
|
#define CARBON_TOOLCHAIN_DRIVER_LLVM_SUBCOMMAND_H_
|
|
|
|
#include "common/command_line.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "toolchain/base/llvm_tools.h"
|
|
#include "toolchain/driver/driver_env.h"
|
|
#include "toolchain/driver/driver_subcommand.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// Options for the LLVM subcommand.
|
|
//
|
|
// See the implementation of `Build` for documentation on members.
|
|
struct LLVMOptions {
|
|
// Build the LLVM subcommand options using `b`.
|
|
//
|
|
// When this top-level subcommand is selected (potentially through a nested
|
|
// sub-subcommand), the `selected_subcommand` will be set to point to
|
|
// `subcommand` to reflect that.
|
|
auto Build(CommandLine::CommandBuilder& b, DriverSubcommand* subcommand,
|
|
DriverSubcommand** selected_subcommand) -> void;
|
|
|
|
LLVMTool subcommand_tool;
|
|
llvm::SmallVector<llvm::StringRef> args;
|
|
};
|
|
|
|
// Implement the LLVM subcommand of the driver.
|
|
//
|
|
// This provides access to the full collection of LLVM command line tools.
|
|
class LLVMSubcommand : public DriverSubcommand {
|
|
public:
|
|
explicit LLVMSubcommand();
|
|
|
|
// The LLVM subcommand uses a custom subcommand structure, so `BuildOptions`
|
|
// is a no-op and we override the more complex layer.
|
|
auto BuildOptions(CommandLine::CommandBuilder& /*b*/) -> void override {
|
|
CARBON_FATAL("Unused.");
|
|
}
|
|
auto BuildOptionsAndSetAction(CommandLine::CommandBuilder& b,
|
|
DriverSubcommand** selected_subcommand)
|
|
-> void override {
|
|
options_.Build(b, this, selected_subcommand);
|
|
}
|
|
|
|
auto Run(DriverEnv& driver_env) -> DriverResult override;
|
|
|
|
private:
|
|
LLVMOptions options_;
|
|
};
|
|
|
|
} // namespace Carbon
|
|
|
|
#endif // CARBON_TOOLCHAIN_DRIVER_LLVM_SUBCOMMAND_H_
|