mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-30 11:15:03 +01:00
Move `--output-last-file-only` and output filename synthesis logic out of the general-purpose compile driver and into the `carbon compile` subcommand, which is the only thing that should be using them. Track on CompilationUnit whether it is being lowered, or whether it exists only to be imported into other units. `carbon compile` now never lowers inputs that it discovered for itself, only inputs that were specified on the command line. In particular, it doesn't lower (and throw away the result of lowering) the prelude any more. This makes the toolchain tests about 10% faster in my crude measurements. Also, we now do not create a clang `CodeGenerator` for input files that we are not lowering, similarly saving compilation time for units that exist only to be imported, not lowered. One minor change: we use the same mechanism to determine whether an input is being lowered and to determine what the output filename is. This means that `--phase=lower` and `--phase=optimize`, which lower but don't produce an output file, still need an output filename to be specified now in some cases. Given those are just debugging tools, I think that's fine. Assisted-by: Gemini via Antigravity
55 lines
1.6 KiB
C++
55 lines
1.6 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_COMPILE_SUBCOMMAND_H_
|
|
#define CARBON_TOOLCHAIN_DRIVER_COMPILE_SUBCOMMAND_H_
|
|
|
|
#include "common/command_line.h"
|
|
#include "toolchain/driver/compile_options.h"
|
|
#include "toolchain/driver/driver_env.h"
|
|
#include "toolchain/driver/driver_subcommand.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// Options for the compile subcommand.
|
|
struct CompileSubcommandOptions {
|
|
auto Build(CommandLine::CommandBuilder& b) -> void {
|
|
compile_options.BuildForCompileSubcommand(b, &codegen_options);
|
|
b.AddFlag(
|
|
{
|
|
.name = "output-last-input-only",
|
|
.help = R"""(
|
|
Only write output for the last input file, ignoring all others.
|
|
|
|
TODO: This is a temporary workaround and should be removed once separate
|
|
compilation is better implemented.
|
|
)""",
|
|
},
|
|
[&](auto& arg_b) { arg_b.Set(&output_last_input_only); });
|
|
}
|
|
|
|
CodegenOptions codegen_options;
|
|
CompileOptions compile_options;
|
|
bool output_last_input_only = false;
|
|
};
|
|
|
|
// Implements the compile subcommand of the driver.
|
|
class CompileSubcommand : public DriverSubcommand {
|
|
public:
|
|
explicit CompileSubcommand();
|
|
|
|
auto BuildOptions(CommandLine::CommandBuilder& b) -> void override {
|
|
options_.Build(b);
|
|
}
|
|
|
|
auto Run(DriverEnv& driver_env) -> DriverResult override;
|
|
|
|
private:
|
|
CompileSubcommandOptions options_;
|
|
};
|
|
|
|
} // namespace Carbon
|
|
|
|
#endif // CARBON_TOOLCHAIN_DRIVER_COMPILE_SUBCOMMAND_H_
|