llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-backend-sparc Author: Naveen Seth Hanig (naveen-seth) <details> <summary>Changes</summary> This PR removes the `clangDriver` dependency from `clangFrontend`. The goal of this change is to remove dependencies on the Driver. This is part of a larger effort to support driver-managed builds for compilations using C++ named modules and/or Clang modules. This is required to eventually allow linking `clangDependencyScanning` against the Driver without creating cyclic dependencies, which would cause build failures with dynamic linking enabled. This change is motivated by the following review comment: https://github.com/llvm/llvm-project/pull/152770#discussion_r2430756918 --- Patch is 259.20 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/165277.diff 148 Files Affected: - (modified) clang-tools-extra/clangd/CMakeLists.txt (+1) - (modified) clang-tools-extra/clangd/CompileCommands.cpp (+15-16) - (modified) clang-tools-extra/clangd/Compiler.cpp (+1) - (modified) clang-tools-extra/modularize/CMakeLists.txt (+1) - (modified) clang-tools-extra/modularize/CoverageChecker.cpp (+3-3) - (modified) clang-tools-extra/modularize/Modularize.cpp (+2-2) - (modified) clang-tools-extra/modularize/ModularizeUtilities.cpp (+3-3) - (modified) clang-tools-extra/pp-trace/CMakeLists.txt (+1) - (modified) clang-tools-extra/pp-trace/PPTrace.cpp (+1-1) - (modified) clang/docs/CMakeLists.txt (+1-1) - (modified) clang/docs/InternalsManual.rst (+4-4) - (modified) clang/include/clang/CMakeLists.txt (+1-1) - (added) clang/include/clang/Driver/CreateASTUnitFromArgs.h (+80) - (added) clang/include/clang/Driver/CreateInvocationFromArgs.h (+76) - (modified) clang/include/clang/Driver/Driver.h (+11-1) - (modified) clang/include/clang/Frontend/ASTUnit.h (+65-81) - (modified) clang/include/clang/Frontend/ChainedDiagnosticConsumer.h (+1-1) - (modified) clang/include/clang/Frontend/CompilerInvocation.h (-10) - (added) clang/include/clang/Frontend/StandaloneDiagnostic.h (+86) - (modified) clang/include/clang/Frontend/Utils.h (+1-46) - (renamed) clang/include/clang/Options/CMakeLists.txt () - (renamed) clang/include/clang/Options/ClangOptionDocs.td () - (renamed) clang/include/clang/Options/OptionUtils.h (+3-3) - (renamed) clang/include/clang/Options/Options.h (+9-11) - (renamed) clang/include/clang/Options/Options.td () - (modified) clang/lib/CMakeLists.txt (+1) - (modified) clang/lib/CrossTU/CMakeLists.txt (+1) - (modified) clang/lib/CrossTU/CrossTranslationUnit.cpp (+2-1) - (modified) clang/lib/Driver/CMakeLists.txt (+5-2) - (modified) clang/lib/Driver/Compilation.cpp (+1-1) - (added) clang/lib/Driver/CreateASTUnitFromArgs.cpp (+168) - (renamed) clang/lib/Driver/CreateInvocationFromArgs.cpp (+13-11) - (modified) clang/lib/Driver/Driver.cpp (+8-2) - (modified) clang/lib/Driver/SanitizerArgs.cpp (+1-1) - (modified) clang/lib/Driver/ToolChain.cpp (+3-3) - (modified) clang/lib/Driver/ToolChains/AIX.cpp (+3-3) - (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+9-12) - (modified) clang/lib/Driver/ToolChains/AMDGPU.h (+1-1) - (modified) clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/AVR.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/Arch/AArch64.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/Arch/ARM.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/Arch/CSKY.cpp (+3-3) - (modified) clang/lib/Driver/ToolChains/Arch/LoongArch.cpp (+2-3) - (modified) clang/lib/Driver/ToolChains/Arch/M68k.cpp (+8-8) - (modified) clang/lib/Driver/ToolChains/Arch/Mips.cpp (+2-3) - (modified) clang/lib/Driver/ToolChains/Arch/PPC.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/Arch/RISCV.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/Arch/Sparc.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/Arch/SystemZ.cpp (+5-5) - (modified) clang/lib/Driver/ToolChains/Arch/VE.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/Arch/X86.cpp (+9-9) - (modified) clang/lib/Driver/ToolChains/BareMetal.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/CSKYToolChain.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+6-7) - (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+11-13) - (modified) clang/lib/Driver/ToolChains/CrossWindows.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/Cuda.cpp (+4-4) - (modified) clang/lib/Driver/ToolChains/Cygwin.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+3-3) - (modified) clang/lib/Driver/ToolChains/DragonFly.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/FreeBSD.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/Fuchsia.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+4-6) - (modified) clang/lib/Driver/ToolChains/HIPAMD.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/HIPSPV.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/HIPUtility.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/Hexagon.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/Hurd.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/Linux.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/MSP430.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/MSVC.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/Managarm.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/MinGW.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/MipsLinux.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/NetBSD.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/OHOS.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/OpenBSD.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/PPCFreeBSD.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/PPCLinux.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/PS4CPU.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/SPIRV.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/SYCL.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/Solaris.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/UEFI.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/VEToolchain.cpp (+3-3) - (modified) clang/lib/Driver/ToolChains/WebAssembly.cpp (+3-3) - (modified) clang/lib/Driver/ToolChains/XCore.cpp (+3-3) - (modified) clang/lib/Driver/ToolChains/ZOS.cpp (+1-1) - (modified) clang/lib/Driver/XRayArgs.cpp (+1-1) - (modified) clang/lib/Frontend/ASTUnit.cpp (+49-295) - (modified) clang/lib/Frontend/CMakeLists.txt (+2-2) - (modified) clang/lib/Frontend/CompilerInvocation.cpp (+27-34) - (added) clang/lib/Frontend/StandaloneDiagnostic.cpp (+102) - (modified) clang/lib/FrontendTool/CMakeLists.txt (+1) - (modified) clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp (+3-3) - (modified) clang/lib/Interpreter/Interpreter.cpp (+3-3) - (modified) clang/lib/Interpreter/InterpreterUtils.h (+1-1) - (added) clang/lib/Options/CMakeLists.txt (+18) - (renamed) clang/lib/Options/DriverOptions.cpp (+9-10) - (renamed) clang/lib/Options/OptionUtils.cpp (+1-1) - (modified) clang/lib/Tooling/CMakeLists.txt (+1) - (modified) clang/lib/Tooling/InterpolatingCompilationDatabase.cpp (+6-6) - (modified) clang/lib/Tooling/Tooling.cpp (+7-8) - (modified) clang/tools/c-index-test/CMakeLists.txt (+1) - (modified) clang/tools/c-index-test/core_main.cpp (+1) - (modified) clang/tools/clang-check/CMakeLists.txt (+1) - (modified) clang/tools/clang-check/ClangCheck.cpp (+2-2) - (modified) clang/tools/clang-installapi/CMakeLists.txt (+1) - (modified) clang/tools/clang-installapi/ClangInstallAPI.cpp (+2-2) - (modified) clang/tools/clang-installapi/Options.cpp (+27-28) - (modified) clang/tools/diagtool/CMakeLists.txt (+1) - (modified) clang/tools/diagtool/ShowEnabledWarnings.cpp (+1) - (modified) clang/tools/driver/CMakeLists.txt (+1) - (modified) clang/tools/driver/cc1_main.cpp (+3-2) - (modified) clang/tools/driver/cc1as_main.cpp (+3-5) - (modified) clang/tools/driver/driver.cpp (+1-1) - (modified) clang/tools/libclang/CIndex.cpp (+2-1) - (modified) clang/tools/libclang/Indexing.cpp (+1) - (modified) clang/unittests/Driver/DXCModeTest.cpp (+3-2) - (modified) clang/unittests/Driver/ToolChainTest.cpp (+1) - (modified) clang/unittests/Frontend/ASTUnitTest.cpp (+4-2) - (modified) clang/unittests/Frontend/CompilerInstanceTest.cpp (+1) - (modified) clang/unittests/Frontend/UtilsTest.cpp (+1) - (modified) clang/unittests/Sema/CMakeLists.txt (+1) - (modified) clang/unittests/Sema/SemaNoloadLookupTest.cpp (+1) - (modified) clang/unittests/Serialization/ForceCheckFileInputTest.cpp (+1) - (modified) clang/unittests/Serialization/LoadSpecLazilyTest.cpp (+1) - (modified) clang/unittests/Serialization/ModuleCacheTest.cpp (+1) - (modified) clang/unittests/Serialization/NoCommentsTest.cpp (+1) - (modified) clang/unittests/Serialization/PreambleInNamedModulesTest.cpp (+1) - (modified) clang/unittests/Serialization/VarDeclConstantInitTest.cpp (+1) - (modified) clang/unittests/Tooling/Syntax/TokensTest.cpp (+1) - (modified) clang/unittests/Tooling/Syntax/TreeTestBase.cpp (+1) - (modified) clang/www/OpenProjects.html (+1-1) - (modified) flang/docs/CMakeLists.txt (+1-1) - (modified) flang/docs/FlangDriver.md (+4-4) - (modified) flang/lib/Frontend/CMakeLists.txt (+1) - (modified) flang/lib/Frontend/CompilerInvocation.cpp (+255-290) - (modified) flang/lib/FrontendTool/CMakeLists.txt (+1) - (modified) flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp (+3-3) - (modified) flang/tools/flang-driver/CMakeLists.txt (+1) - (modified) flang/tools/flang-driver/driver.cpp (+2-2) - (modified) lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (+2-2) - (modified) llvm/include/llvm/MC/MCAsmInfo.h (+1-1) - (modified) llvm/include/llvm/Option/Arg.h (+1-1) - (modified) utils/bazel/llvm-project-overlay/clang/BUILD.bazel (+2-2) ``````````diff diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index fb3f05329be21..d7ec853af862f 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -165,6 +165,7 @@ clang_target_link_libraries(clangDaemon clangBasic clangDependencyScanning clangDriver + clangOptions clangFormat clangFrontend clangIndex diff --git a/clang-tools-extra/clangd/CompileCommands.cpp b/clang-tools-extra/clangd/CompileCommands.cpp index c1be93730129a..611a403bed33d 100644 --- a/clang-tools-extra/clangd/CompileCommands.cpp +++ b/clang-tools-extra/clangd/CompileCommands.cpp @@ -11,8 +11,8 @@ #include "support/Logger.h" #include "support/Trace.h" #include "clang/Driver/Driver.h" -#include "clang/Driver/Options.h" #include "clang/Frontend/CompilerInvocation.h" +#include "clang/Options/Options.h" #include "clang/Tooling/CompilationDatabase.h" #include "clang/Tooling/Tooling.h" #include "llvm/ADT/ArrayRef.h" @@ -132,8 +132,8 @@ std::optional<std::string> detectSysroot() { std::string detectStandardResourceDir() { static int StaticForMainAddr; // Just an address in this process. - return CompilerInvocation::GetResourcesPath("clangd", - (void *)&StaticForMainAddr); + return driver::Driver::GetResourcesPathForInvocation( + "clangd", (void *)&StaticForMainAddr); } // The path passed to argv[0] is important: @@ -206,7 +206,7 @@ void CommandMangler::operator()(tooling::CompileCommand &Command, if (Cmd.empty()) return; - auto &OptTable = clang::driver::getDriverOptTable(); + auto &OptTable = getDriverOptTable(); // OriginalArgs needs to outlive ArgList. llvm::SmallVector<const char *, 16> OriginalArgs; OriginalArgs.reserve(Cmd.size()); @@ -222,8 +222,8 @@ void CommandMangler::operator()(tooling::CompileCommand &Command, llvm::opt::InputArgList ArgList; ArgList = OptTable.ParseArgs( llvm::ArrayRef(OriginalArgs).drop_front(), IgnoredCount, IgnoredCount, - llvm::opt::Visibility(IsCLMode ? driver::options::CLOption - : driver::options::ClangOption)); + llvm::opt::Visibility(IsCLMode ? options::CLOption + : options::ClangOption)); llvm::SmallVector<unsigned, 1> IndicesToDrop; // Having multiple architecture options (e.g. when building fat binaries) @@ -232,7 +232,7 @@ void CommandMangler::operator()(tooling::CompileCommand &Command, // As there are no signals to figure out which one user actually wants. They // can explicitly specify one through `CompileFlags.Add` if need be. unsigned ArchOptCount = 0; - for (auto *Input : ArgList.filtered(driver::options::OPT_arch)) { + for (auto *Input : ArgList.filtered(options::OPT_arch)) { ++ArchOptCount; for (auto I = 0U; I <= Input->getNumValues(); ++I) IndicesToDrop.push_back(Input->getIndex() + I); @@ -262,13 +262,12 @@ void CommandMangler::operator()(tooling::CompileCommand &Command, // explicitly at the end of the flags. This ensures modifications done in the // following steps apply in more cases (like setting -x, which only affects // inputs that come after it). - for (auto *Input : ArgList.filtered(driver::options::OPT_INPUT)) { + for (auto *Input : ArgList.filtered(options::OPT_INPUT)) { SawInput(Input->getValue(0)); IndicesToDrop.push_back(Input->getIndex()); } // Anything after `--` is also treated as input, drop them as well. - if (auto *DashDash = - ArgList.getLastArgNoClaim(driver::options::OPT__DASH_DASH)) { + if (auto *DashDash = ArgList.getLastArgNoClaim(options::OPT__DASH_DASH)) { auto DashDashIndex = DashDash->getIndex() + 1; // +1 accounts for Cmd[0] // Another +1 so we don't treat the `--` itself as an input. for (unsigned I = DashDashIndex + 1; I < Cmd.size(); ++I) @@ -424,11 +423,11 @@ DriverMode getDriverMode(const std::vector<std::string> &Args) { // Returns the set of DriverModes where an option may be used. unsigned char getModes(const llvm::opt::Option &Opt) { unsigned char Result = DM_None; - if (Opt.hasVisibilityFlag(driver::options::ClangOption)) + if (Opt.hasVisibilityFlag(options::ClangOption)) Result |= DM_GCC; - if (Opt.hasVisibilityFlag(driver::options::CC1Option)) + if (Opt.hasVisibilityFlag(options::CC1Option)) Result |= DM_CC1; - if (Opt.hasVisibilityFlag(driver::options::CLOption)) + if (Opt.hasVisibilityFlag(options::CLOption)) Result |= DM_CL; return Result; } @@ -442,8 +441,8 @@ llvm::ArrayRef<ArgStripper::Rule> ArgStripper::rulesFor(llvm::StringRef Arg) { using TableTy = llvm::StringMap<llvm::SmallVector<Rule, 4>, llvm::BumpPtrAllocator>; static TableTy *Table = [] { - auto &DriverTable = driver::getDriverOptTable(); - using DriverID = clang::driver::options::ID; + auto &DriverTable = getDriverOptTable(); + using DriverID = clang::options::ID; // Collect sets of aliases, so we can treat -foo and -foo= as synonyms. // Conceptually a double-linked list: PrevAlias[I] -> I -> NextAlias[I]. @@ -468,7 +467,7 @@ llvm::ArrayRef<ArgStripper::Rule> ArgStripper::rulesFor(llvm::StringRef Arg) { FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, \ METAVAR, VALUES, SUBCOMMANDIDS_OFFSET) \ {DriverID::OPT_##ID, DriverID::OPT_##ALIAS, ALIASARGS}, -#include "clang/Driver/Options.inc" +#include "clang/Options/Options.inc" #undef OPTION }; for (auto &E : AliasTable) diff --git a/clang-tools-extra/clangd/Compiler.cpp b/clang-tools-extra/clangd/Compiler.cpp index 6ebc2eac25745..9ea7df139382a 100644 --- a/clang-tools-extra/clangd/Compiler.cpp +++ b/clang-tools-extra/clangd/Compiler.cpp @@ -9,6 +9,7 @@ #include "Compiler.h" #include "support/Logger.h" #include "clang/Basic/TargetInfo.h" +#include "clang/Driver/CreateInvocationFromArgs.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Serialization/PCHContainerOperations.h" diff --git a/clang-tools-extra/modularize/CMakeLists.txt b/clang-tools-extra/modularize/CMakeLists.txt index eb5383c3ad44e..a775b790a3147 100644 --- a/clang-tools-extra/modularize/CMakeLists.txt +++ b/clang-tools-extra/modularize/CMakeLists.txt @@ -20,6 +20,7 @@ clang_target_link_libraries(modularize clangAST clangBasic clangDriver + clangOptions clangFrontend clangLex clangSerialization diff --git a/clang-tools-extra/modularize/CoverageChecker.cpp b/clang-tools-extra/modularize/CoverageChecker.cpp index 1345a6ef8f489..d80d78c64c6e2 100644 --- a/clang-tools-extra/modularize/CoverageChecker.cpp +++ b/clang-tools-extra/modularize/CoverageChecker.cpp @@ -50,18 +50,18 @@ // //===----------------------------------------------------------------------===// +#include "CoverageChecker.h" #include "ModularizeUtilities.h" #include "clang/AST/ASTConsumer.h" -#include "CoverageChecker.h" #include "clang/AST/ASTContext.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/Basic/SourceManager.h" -#include "clang/Driver/Options.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendAction.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Options/Options.h" #include "clang/Tooling/CompilationDatabase.h" #include "clang/Tooling/Tooling.h" #include "llvm/Option/Option.h" @@ -73,7 +73,7 @@ using namespace Modularize; using namespace clang; using namespace clang::driver; -using namespace clang::driver::options; +using namespace clang::options; using namespace clang::tooling; namespace cl = llvm::cl; namespace sys = llvm::sys; diff --git a/clang-tools-extra/modularize/Modularize.cpp b/clang-tools-extra/modularize/Modularize.cpp index 376ad0c7875bf..33966b44f719a 100644 --- a/clang-tools-extra/modularize/Modularize.cpp +++ b/clang-tools-extra/modularize/Modularize.cpp @@ -231,11 +231,11 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/Basic/SourceManager.h" -#include "clang/Driver/Options.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendAction.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Options/Options.h" #include "clang/Tooling/CompilationDatabase.h" #include "clang/Tooling/Tooling.h" #include "llvm/Option/Arg.h" @@ -254,7 +254,7 @@ using namespace clang; using namespace clang::driver; -using namespace clang::driver::options; +using namespace clang::options; using namespace clang::tooling; using namespace llvm; using namespace llvm::opt; diff --git a/clang-tools-extra/modularize/ModularizeUtilities.cpp b/clang-tools-extra/modularize/ModularizeUtilities.cpp index 4dd84feac5df4..6978a6b2fe1b7 100644 --- a/clang-tools-extra/modularize/ModularizeUtilities.cpp +++ b/clang-tools-extra/modularize/ModularizeUtilities.cpp @@ -12,17 +12,17 @@ // //===----------------------------------------------------------------------===// +#include "ModularizeUtilities.h" +#include "CoverageChecker.h" #include "clang/Basic/SourceManager.h" -#include "clang/Driver/Options.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendActions.h" -#include "CoverageChecker.h" +#include "clang/Options/Options.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" -#include "ModularizeUtilities.h" using namespace clang; using namespace llvm; diff --git a/clang-tools-extra/pp-trace/CMakeLists.txt b/clang-tools-extra/pp-trace/CMakeLists.txt index 1323adbc35269..da36582ee0234 100644 --- a/clang-tools-extra/pp-trace/CMakeLists.txt +++ b/clang-tools-extra/pp-trace/CMakeLists.txt @@ -14,6 +14,7 @@ clang_target_link_libraries(pp-trace PRIVATE clangAST clangBasic + clangOptions clangFrontend clangLex clangSerialization diff --git a/clang-tools-extra/pp-trace/PPTrace.cpp b/clang-tools-extra/pp-trace/PPTrace.cpp index 0b078c49a55b7..ba5a06a26830d 100644 --- a/clang-tools-extra/pp-trace/PPTrace.cpp +++ b/clang-tools-extra/pp-trace/PPTrace.cpp @@ -28,11 +28,11 @@ #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/Basic/SourceManager.h" -#include "clang/Driver/Options.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendAction.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Options/Options.h" #include "clang/Tooling/Execution.h" #include "clang/Tooling/Tooling.h" #include "llvm/Option/Arg.h" diff --git a/clang/docs/CMakeLists.txt b/clang/docs/CMakeLists.txt index 1f06c040c96cb..9469a832adb62 100644 --- a/clang/docs/CMakeLists.txt +++ b/clang/docs/CMakeLists.txt @@ -132,7 +132,7 @@ if (LLVM_ENABLE_SPHINX) # Generated files gen_rst_file_from_td(AttributeReference.rst -gen-attr-docs ../include/clang/Basic/Attr.td "${docs_targets}") gen_rst_file_from_td(DiagnosticsReference.rst -gen-diag-docs ../include/clang/Basic/Diagnostic.td "${docs_targets}") - gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs ../include/clang/Driver/ClangOptionDocs.td "${docs_targets}") + gen_rst_file_from_td(ClangCommandLineReference.rst -gen-opt-docs ../include/clang/Options/ClangOptionDocs.td "${docs_targets}") # Another generated file from a different source set(docs_tools_dir ${CMAKE_CURRENT_SOURCE_DIR}/tools) diff --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst index eff46ab46e1ca..a849d05eb7ae9 100644 --- a/clang/docs/InternalsManual.rst +++ b/clang/docs/InternalsManual.rst @@ -667,7 +667,7 @@ Command Line Interface ---------------------- The command line interface of the Clang ``-cc1`` frontend is defined alongside -the driver options in ``clang/Driver/Options.td``. The information making up an +the driver options in ``clang/Options/Options.td``. The information making up an option definition includes its prefix and name (for example ``-std=``), form and position of the option value, help text, aliases and more. Each option may belong to a certain group and can be marked with zero or more flags. Options @@ -712,7 +712,7 @@ variable for the option value: } Next, declare the command line interface of the option in the tablegen file -``clang/include/clang/Driver/Options.td``. This is done by instantiating the +``clang/include/clang/Options/Options.td``. This is done by instantiating the ``Option`` class (defined in ``llvm/include/llvm/Option/OptParser.td``). The instance is typically created through one of the helper classes that encode the acceptable ways to specify the option value on the command line: @@ -906,7 +906,7 @@ command line: SHOULD_PARSE, KEYPATH, DEFAULT_VALUE, \ IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, \ MERGER, TABLE_INDEX) - #include "clang/Driver/Options.inc" + #include "clang/Options/Options.inc" #undef LANG_OPTION_WITH_MARSHALLING // ... @@ -925,7 +925,7 @@ command line: GENERATE_OPTION_WITH_MARSHALLING( \ Args, SA, KIND, FLAGS, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \ IMPLIED_CHECK, IMPLIED_VALUE, DENORMALIZER, EXTRACTOR, TABLE_INDEX) - #include "clang/Driver/Options.inc" + #include "clang/Options/Options.inc" #undef LANG_OPTION_WITH_MARSHALLING // ... diff --git a/clang/include/clang/CMakeLists.txt b/clang/include/clang/CMakeLists.txt index 47ac70cd21690..77a44e4c48de5 100644 --- a/clang/include/clang/CMakeLists.txt +++ b/clang/include/clang/CMakeLists.txt @@ -3,7 +3,7 @@ add_subdirectory(Basic) if(CLANG_ENABLE_CIR) add_subdirectory(CIR) endif() -add_subdirectory(Driver) +add_subdirectory(Options) add_subdirectory(Parse) add_subdirectory(Sema) add_subdirectory(Serialization) diff --git a/clang/include/clang/Driver/CreateASTUnitFromArgs.h b/clang/include/clang/Driver/CreateASTUnitFromArgs.h new file mode 100644 index 0000000000000..30575cc04ca7c --- /dev/null +++ b/clang/include/clang/Driver/CreateASTUnitFromArgs.h @@ -0,0 +1,80 @@ +//===-- CreateInvocationFromArgs.h - Create an ASTUnit from Args-*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Utility for creating an ASTUnit from a vector of command line arguments. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_DRIVER_CREATEASTUNITFROMARGS_H +#define LLVM_CLANG_DRIVER_CREATEASTUNITFROMARGS_H + +#include "clang/Frontend/ASTUnit.h" + +namespace clang { + +/// Create an ASTUnit from a vector of command line arguments, which must +/// specify exactly one source file. +/// +/// \param ArgBegin - The beginning of the argument vector. +/// +/// \param ArgEnd - The end of the argument vector. +/// +/// \param PCHContainerOps - The PCHContainerOperations to use for loading and +/// creating modules. +/// +/// \param Diags - The diagnostics engine to use for reporting errors; its +/// lifetime is expected to extend past that of the returned ASTUnit. +/// +/// \param ResourceFilesPath - The path to the compiler resource files. +/// +/// \param StorePreamblesInMemory - Whether to store PCH in memory. If false, +/// PCH are stored in temporary files. +/// +/// \param PreambleStoragePath - The path to a directory, in which to create +/// temporary PCH files. If empty, the default system temporary directory is +/// used. This parameter is ignored if \p StorePreamblesInMemory is true. +/// +/// \param ModuleFormat - If provided, uses the specific module format. +/// +/// \param ErrAST - If non-null and parsing failed without any AST to return +/// (e.g. because the PCH could not be loaded), this accepts the ASTUnit +/// mainly to allow the caller to see the diagnostics. +/// +/// \param VFS - A llvm::vfs::FileSystem to be used for all file accesses. +/// Note that preamble is saved to a temporary directory on a RealFileSystem, +/// so in order for it to be loaded correctly, VFS should have access to +/// it(i.e., be an overlay over RealFileSystem). RealFileSystem will be used +/// if \p VFS is nullptr. +/// +// FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we +// shouldn't need to specify them at construction time. +std::unique_ptr<ASTUnit> CreateASTUnitFromCommandLine( + const char **ArgBegin, const char **ArgEnd, + std::shared_ptr<PCHContainerOperations> PCHContainerOps, + std::shared_ptr<DiagnosticOptions> DiagOpts, + IntrusiveRefCntPtr<DiagnosticsEngine> Diags, StringRef ResourceFilesPath, + bool StorePreamblesInMemory = false, + StringRef PreambleStoragePath = StringRef(), bool OnlyLocalDecls = false, + CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None, + ArrayRef<ASTUnit::RemappedFile> RemappedFiles = {}, + bool RemappedFilesKeepOriginalName = true, + unsigned PrecompilePreambleAfterNParses = 0, + TranslationUnitKind TUKind = TU_Complete, + bool CacheCodeCompletionResults = false, + bool IncludeBriefCommentsInCodeCompletion = false, + bool AllowPCHWithCompilerErrors = false, + SkipFunctionBodiesScope SkipFunctionBodies = SkipFunctionBodiesScope::None, + bool SingleFileParse = false, bool UserFilesAreVolatile = false, + bool ForSerialization = false, bool RetainExcludedConditionalBlocks = false, + std::optional<StringRef> ModuleFormat = std::nullopt, + std::unique_ptr<ASTUnit> *ErrAST = nullptr, + IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr); + +} // namespace clang + +#endif // LLVM_CLANG_DRIVER_CREATEASTUNITFROMARGS_H diff --git a/clang/include/clang/Driver/CreateInvocationFromArgs.h b/clang/include/clang/Driver/CreateInvocationFromArgs.h new file mode 100644 index 0000000000000..0e0f67373ce87 --- /dev/null +++ b/clang/include/clang/Driver/CreateInvocationFromArgs.h @@ -0,0 +1,76 @@ +//===--- CreateInvocationFromArgs.h - CompilerInvocation from Args --------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Utility for creating a CompilerInvocation from command-line arguments, for +// tools to use in preparation to parse a file. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_DRIVER_CREATEINVOCATIONFROMARGS_H +#define LLVM_CLANG_DRIVER_CREATEINVOCATIONFROMARGS_H + +#include "clang/Basic/Diagnostic.h" +#include "clang/Basic/LLVM.h" +#include "llvm/Support/VirtualFileSystem.h" +#include <memory> +#include <string> +#include <vector> + +namespace clang { + +class CompilerInvocation; +class DiagnosticsEngine; + +/// Optional inputs to createInvocation. +struct CreateInvocationOptions { + /// Receives diagnostics encountered while parsing command-line flags. + /// If not provided, these are printed to stderr. + IntrusiveRefCntPtr<DiagnosticsEngine> Diags = nullptr; + /// Used e.g. to probe for system headers locations. + /// If not provided, the real filesystem is used. + /// FIXME: the driver does perform some non-virtualized IO. + IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr; + /// Whether to attempt to produce a non-null (possibly incorrect) invocation + /// if any errors were encountered. + /// By default, always return null on errors. + bool RecoverOnError = false; + /// Allow the driver to probe the filesystem for PCH files. + /// This is used to replace -include with -include-pch in the cc1 args. + /// FIXME: ProbePrecompiled=true is a poor, historical default. + /// It misbehaves if the PCH file is from GCC, has the wrong version, etc. + bool ProbePrecompiled = false; + /// If set, the target is popula... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/165277 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
