diff --git a/toolchain/driver/BUILD b/toolchain/driver/BUILD index 911c1b4249f3..90ce5082466a 100644 --- a/toolchain/driver/BUILD +++ b/toolchain/driver/BUILD @@ -127,26 +127,64 @@ cc_library( ) cc_library( - name = "compile_driver", - srcs = [ - "compile_driver.cpp", - "compile_options.cpp", + name = "driver_env", + hdrs = ["driver_env.h"], + deps = [ + ":runtimes_cache", + "//common:ostream", + "//toolchain/base:install_paths", + "//toolchain/diagnostics:emitter", + "@llvm-project//llvm:Support", ], - hdrs = [ - "compile_driver.h", - "compile_options.h", - "driver_env.h", +) + +cc_library( + name = "driver_subcommand", + srcs = ["driver_subcommand.cpp"], + hdrs = ["driver_subcommand.h"], + deps = [ + ":driver_env", + "//common:command_line", + "//common:ostream", + "//toolchain/base:install_paths", + "@llvm-project//llvm:Support", ], +) + +cc_library( + name = "compile_options", + srcs = ["compile_options.cpp"], + hdrs = ["compile_options.h"], deps = [ ":codegen_options", - ":runtimes_cache", - "//common:check", + ":driver_env", "//common:command_line", "//common:error", "//common:ostream", + "//toolchain/base:clang_invocation", + "//toolchain/check", + "//toolchain/diagnostics:emitter", + "//toolchain/lower:options", + "//toolchain/parse", + "@llvm-project//llvm:MC", + "@llvm-project//llvm:Passes", + "@llvm-project//llvm:Support", + "@llvm-project//llvm:TargetParser", + ], +) + +cc_library( + name = "compile_driver", + srcs = ["compile_driver.cpp"], + hdrs = ["compile_driver.h"], + deps = [ + ":codegen_options", + ":compile_options", + ":driver_env", + ":runtimes_cache", + "//common:error", + "//common:ostream", "//common:pretty_stack_trace_function", - "//common:raw_string_ostream", - "//common:version", "//common:vlog", "//toolchain/base:clang_invocation", "//toolchain/base:install_paths", @@ -162,17 +200,224 @@ cc_library( "//toolchain/lower:options", "//toolchain/parse", "//toolchain/parse:tree", - "//toolchain/sem_ir:file", "//toolchain/sem_ir:typed_insts", "//toolchain/source:source_buffer", - "@llvm-project//clang:codegen", - "@llvm-project//clang:frontend", - "@llvm-project//clang:lex", "@llvm-project//llvm:Core", "@llvm-project//llvm:MC", "@llvm-project//llvm:Passes", "@llvm-project//llvm:Support", "@llvm-project//llvm:Target", + ], +) + +cc_library( + name = "compile_subcommand", + srcs = ["compile_subcommand.cpp"], + hdrs = ["compile_subcommand.h"], + deps = [ + ":compile_driver", + ":compile_options", + ":driver_env", + ":driver_subcommand", + "//common:command_line", + "//toolchain/diagnostics:emitter", + "//toolchain/diagnostics:format_providers", + "@llvm-project//llvm:Support", + ], +) + +cc_library( + name = "format_subcommand", + srcs = ["format_subcommand.cpp"], + hdrs = ["format_subcommand.h"], + deps = [ + ":driver_env", + ":driver_subcommand", + "//common:command_line", + "//common:error", + "//common:ostream", + "//common:raw_string_ostream", + "//toolchain/base:install_paths", + "//toolchain/base:shared_value_stores", + "//toolchain/diagnostics:emitter", + "//toolchain/format", + "//toolchain/lex", + "//toolchain/source:source_buffer", + "@llvm-project//llvm:Support", + ], +) + +cc_library( + name = "language_server_subcommand", + srcs = ["language_server_subcommand.cpp"], + hdrs = ["language_server_subcommand.h"], + deps = [ + ":codegen_options", + ":driver_env", + ":driver_subcommand", + "//common:command_line", + "//toolchain/diagnostics:emitter", + "//toolchain/language_server", + "@llvm-project//llvm:Support", + ], +) + +cc_library( + name = "carbon_runtimes", + srcs = ["carbon_runtimes.cpp"], + hdrs = ["carbon_runtimes.h"], + deps = [ + ":codegen_options", + ":compile_driver", + ":compile_options", + ":driver_env", + ":runtimes_cache", + "//common:check", + "//common:error", + "//common:ostream", + "//common:string_helpers", + "//common:vlog", + "//toolchain/base:install_paths", + "//toolchain/base:runtimes_build_info", + "@llvm-project//llvm:Support", + "@llvm-project//llvm:TargetParser", + ], +) + +cc_library( + name = "link_subcommand", + srcs = [ + "link_driver.cpp", + "link_options.cpp", + "link_subcommand.cpp", + ], + hdrs = [ + "link_driver.h", + "link_options.h", + "link_subcommand.h", + ], + deps = [ + ":carbon_runtimes", + ":clang_runner", + ":codegen_options", + ":driver_env", + ":driver_subcommand", + "//common:check", + "//common:command_line", + "//common:error", + "//common:filesystem", + "//common:ostream", + "//common:vlog", + "//toolchain/base:install_paths", + "//toolchain/base:runtimes_build_info", + "@llvm-project//llvm:Support", + "@llvm-project//llvm:TargetParser", + ], +) + +cc_library( + name = "build_subcommand", + srcs = ["build_subcommand.cpp"], + hdrs = ["build_subcommand.h"], + deps = [ + ":codegen_options", + ":compile_driver", + ":compile_options", + ":driver_env", + ":driver_subcommand", + ":link_subcommand", + "//common:command_line", + "//common:error", + "//common:filesystem", + "//common:hashing", + "//common:ostream", + "@llvm-project//llvm:Support", + ], +) + +cc_library( + name = "build_runtimes_subcommand", + srcs = ["build_runtimes_subcommand.cpp"], + hdrs = ["build_runtimes_subcommand.h"], + deps = [ + ":carbon_runtimes", + ":clang_runner", + ":codegen_options", + ":driver_env", + ":driver_subcommand", + ":runtimes_cache", + "//common:command_line", + "//common:error", + "//toolchain/diagnostics:emitter", + "@llvm-project//llvm:Support", + "@llvm-project//llvm:TargetParser", + ], +) + +cc_library( + name = "config_subcommand", + srcs = ["config_subcommand.cpp"], + hdrs = ["config_subcommand.h"], + deps = [ + ":clang_runner", + ":codegen_options", + ":driver_env", + ":driver_subcommand", + "//common:check", + "//common:command_line", + "//common:filesystem", + "//common:ostream", + "//common:version", + "//toolchain/base:clang_invocation", + "//toolchain/base:install_paths", + "//toolchain/diagnostics:emitter", + "@llvm-project//clang:frontend", + "@llvm-project//clang:lex", + "@llvm-project//llvm:Support", + "@llvm-project//llvm:TargetParser", + ], +) + +cc_library( + name = "clang_subcommand", + srcs = ["clang_subcommand.cpp"], + hdrs = ["clang_subcommand.h"], + deps = [ + ":clang_runner", + ":driver_env", + ":driver_subcommand", + "//common:command_line", + "@llvm-project//llvm:Support", + "@llvm-project//llvm:TargetParser", + ], +) + +cc_library( + name = "lld_subcommand", + srcs = ["lld_subcommand.cpp"], + hdrs = ["lld_subcommand.h"], + deps = [ + ":driver_env", + ":driver_subcommand", + ":lld_runner", + "//common:command_line", + "@llvm-project//llvm:Support", + "@llvm-project//llvm:TargetParser", + ], +) + +cc_library( + name = "llvm_subcommand", + srcs = ["llvm_subcommand.cpp"], + hdrs = ["llvm_subcommand.h"], + deps = [ + ":driver_env", + ":driver_subcommand", + ":llvm_runner", + "//common:check", + "//common:command_line", + "//toolchain/base:llvm_tools", + "@llvm-project//llvm:Support", "@llvm-project//llvm:TargetParser", ], ) @@ -180,90 +425,36 @@ cc_library( cc_library( name = "driver", srcs = [ - "build_runtimes_subcommand.cpp", - "build_runtimes_subcommand.h", - "build_subcommand.cpp", - "build_subcommand.h", - "carbon_runtimes.cpp", - "carbon_runtimes.h", - "clang_subcommand.cpp", - "clang_subcommand.h", - "compile_subcommand.cpp", - "compile_subcommand.h", - "config_subcommand.cpp", - "config_subcommand.h", "driver.cpp", - "driver_subcommand.cpp", - "format_subcommand.cpp", - "format_subcommand.h", - "language_server_subcommand.cpp", - "language_server_subcommand.h", - "link_driver.cpp", - "link_driver.h", - "link_options.cpp", - "link_options.h", - "link_subcommand.cpp", - "link_subcommand.h", - "lld_subcommand.cpp", - "lld_subcommand.h", - "llvm_subcommand.cpp", - "llvm_subcommand.h", ], hdrs = [ "driver.h", - "driver_subcommand.h", ], data = [ "//toolchain/install:all_data_files", ], textual_hdrs = ["flags.def"], deps = [ - ":clang_runner", - ":codegen_options", - ":compile_driver", - ":lld_runner", - ":llvm_runner", + ":build_runtimes_subcommand", + ":build_subcommand", + ":clang_subcommand", + ":compile_subcommand", + ":config_subcommand", + ":driver_env", + ":driver_subcommand", + ":format_subcommand", + ":language_server_subcommand", + ":link_subcommand", + ":lld_subcommand", + ":llvm_subcommand", ":runtimes_cache", "//common:check", "//common:command_line", "//common:error", - "//common:filesystem", - "//common:hashing", "//common:ostream", "//common:pretty_stack_trace_function", - "//common:raw_string_ostream", "//common:version", - "//common:vlog", - "//toolchain/base:clang_invocation", - "//toolchain/base:install_paths", - "//toolchain/base:llvm_tools", - "//toolchain/base:runtimes_build_info", - "//toolchain/base:shared_value_stores", - "//toolchain/base:timings", - "//toolchain/check", - "//toolchain/codegen", - "//toolchain/diagnostics:emitter", - "//toolchain/diagnostics:format_providers", - "//toolchain/diagnostics:sorting_consumer", - "//toolchain/format", - "//toolchain/language_server", - "//toolchain/lex", - "//toolchain/lower", - "//toolchain/lower:options", - "//toolchain/parse", - "//toolchain/parse:tree", - "//toolchain/sem_ir:file", - "//toolchain/sem_ir:typed_insts", - "//toolchain/source:source_buffer", - "@llvm-project//clang:codegen", - "@llvm-project//clang:frontend", - "@llvm-project//clang:lex", - "@llvm-project//llvm:Core", - "@llvm-project//llvm:MC", - "@llvm-project//llvm:Passes", "@llvm-project//llvm:Support", - "@llvm-project//llvm:Target", - "@llvm-project//llvm:TargetParser", ], ) diff --git a/toolchain/driver/compile_driver.cpp b/toolchain/driver/compile_driver.cpp index 881f3d334b4b..d87eac7eaf36 100644 --- a/toolchain/driver/compile_driver.cpp +++ b/toolchain/driver/compile_driver.cpp @@ -19,11 +19,14 @@ #include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Passes/OptimizationLevel.h" #include "llvm/Passes/PassBuilder.h" #include "llvm/Passes/StandardInstrumentations.h" #include "llvm/Support/SaveAndRestore.h" +#include "llvm/Target/TargetMachine.h" #include "toolchain/base/clang_invocation.h" #include "toolchain/base/timings.h" #include "toolchain/check/check.h" @@ -62,6 +65,8 @@ CompilationUnit::CompilationUnit( } } +CompilationUnit::~CompilationUnit() = default; + auto CompilationUnit::IncludeInDumps() -> bool { return cache_->include_in_dumps().Get(check_ir_id_); } @@ -421,6 +426,8 @@ auto CompilationUnit::LogCall(llvm::StringLiteral logging_label, CompileDriver::CompileDriver(CompileOptions* options) : options_(options) {} +CompileDriver::~CompileDriver() = default; + auto CompileDriver::Initialize( DriverEnv& driver_env, llvm::function_refstd::string> map_input) -> bool { diff --git a/toolchain/driver/compile_driver.h b/toolchain/driver/compile_driver.h index a63e16016d85..8da74ad20a0e 100644 --- a/toolchain/driver/compile_driver.h +++ b/toolchain/driver/compile_driver.h @@ -8,11 +8,16 @@ #include #include "llvm/ADT/SmallVector.h" -#include "llvm/Target/TargetMachine.h" #include "toolchain/diagnostics/sorting_consumer.h" #include "toolchain/driver/compile_options.h" #include "toolchain/driver/driver_env.h" +namespace llvm { +class LLVMContext; +class Module; +class TargetMachine; +} // namespace llvm + namespace Carbon { class MultiUnitCache; @@ -31,6 +36,7 @@ class CompilationUnit { std::string output_filename, const llvm::Target* target, llvm::LLVMContext* llvm_context); + ~CompilationUnit(); // Sets the multi-unit cache and initializes dependent member state. auto SetMultiUnitCache(MultiUnitCache* cache) -> void; @@ -241,6 +247,7 @@ class MultiUnitCache { class CompileDriver { public: explicit CompileDriver(CompileOptions* options); + ~CompileDriver(); // Configure the toolchain to compile all input files and dependencies. // The `map_input` function maps an input file name to an output file name. diff --git a/toolchain/driver/compile_options.cpp b/toolchain/driver/compile_options.cpp index fc57f6e510d7..ca4eef2a1a62 100644 --- a/toolchain/driver/compile_options.cpp +++ b/toolchain/driver/compile_options.cpp @@ -6,6 +6,8 @@ #include +#include "llvm/MC/TargetRegistry.h" +#include "llvm/TargetParser/Triple.h" #include "toolchain/base/clang_invocation.h" namespace Carbon { diff --git a/toolchain/driver/compile_options.h b/toolchain/driver/compile_options.h index a85ce0520404..f8d30c328b77 100644 --- a/toolchain/driver/compile_options.h +++ b/toolchain/driver/compile_options.h @@ -10,15 +10,18 @@ #include "common/ostream.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" -#include "llvm/MC/TargetRegistry.h" #include "llvm/Passes/OptimizationLevel.h" #include "toolchain/check/check.h" #include "toolchain/diagnostics/emitter.h" #include "toolchain/driver/codegen_options.h" #include "toolchain/driver/driver_env.h" -#include "toolchain/lower/lower.h" +#include "toolchain/lower/options.h" #include "toolchain/parse/parse.h" +namespace llvm { +class Target; +} // namespace llvm + namespace Carbon { // Options for Carbon compilation. This struct is shared between the diff --git a/toolchain/driver/driver_subcommand.cpp b/toolchain/driver/driver_subcommand.cpp index 9678f470f018..1dc9f1ba5d4e 100644 --- a/toolchain/driver/driver_subcommand.cpp +++ b/toolchain/driver/driver_subcommand.cpp @@ -4,10 +4,6 @@ #include "toolchain/driver/driver_subcommand.h" -#include "llvm/TargetParser/Host.h" -#include "llvm/TargetParser/Triple.h" -#include "toolchain/driver/lld_runner.h" - namespace Carbon { auto DriverSubcommand::TestAndDiagnoseIfFuzzingExternalLibraries( diff --git a/toolchain/driver/runtimes_cache.cpp b/toolchain/driver/runtimes_cache.cpp index 7e678bf9ff9b..adbfc93cca50 100644 --- a/toolchain/driver/runtimes_cache.cpp +++ b/toolchain/driver/runtimes_cache.cpp @@ -4,6 +4,8 @@ #include "toolchain/driver/runtimes_cache.h" +#include + #include #include #include diff --git a/toolchain/format/BUILD b/toolchain/format/BUILD index 4b2e0cdfd269..5f4ca1631c07 100644 --- a/toolchain/format/BUILD +++ b/toolchain/format/BUILD @@ -21,8 +21,6 @@ cc_library( hdrs = ["format.h"], deps = [ "//common:ostream", - "//toolchain/lex:token_index", - "//toolchain/lex:token_kind", "//toolchain/lex:tokenized_buffer", ], ) diff --git a/toolchain/language_server/BUILD b/toolchain/language_server/BUILD index 454dfb5764bb..60579df93ade 100644 --- a/toolchain/language_server/BUILD +++ b/toolchain/language_server/BUILD @@ -61,6 +61,7 @@ cc_library( "//toolchain/diagnostics:file_diagnostics", "//toolchain/driver:codegen_options", "//toolchain/driver:compile_driver", + "//toolchain/driver:compile_options", "//toolchain/lex", "//toolchain/lex:tokenized_buffer", "//toolchain/parse", diff --git a/toolchain/source/BUILD b/toolchain/source/BUILD index 4e946ae1df71..8ad5b6f938cb 100644 --- a/toolchain/source/BUILD +++ b/toolchain/source/BUILD @@ -11,10 +11,8 @@ cc_library( srcs = ["source_buffer.cpp"], hdrs = ["source_buffer.h"], deps = [ - "//common:error", "//toolchain/diagnostics:emitter", "//toolchain/diagnostics:file_diagnostics", - "//toolchain/diagnostics:format_providers", "@llvm-project//llvm:Support", ], )