From 3708a148421fd0449081b9a91fba28f51f1dfb12 Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Mon, 22 Aug 2022 15:42:52 -0700 Subject: [clang] Pull some utility functions into CompilerInvocation NFC Move copying compiler arguments to a vector and modifying common module-related options into CompilerInvocation in preparation for using some of them in more places and to avoid duplicating this code accidentally in the future. Differential Revision: https://reviews.llvm.org/D132419 --- clang/lib/Frontend/CompilerInvocation.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 9731d40..7e6d0cd 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4672,6 +4672,37 @@ void CompilerInvocation::generateCC1CommandLine( GenerateDependencyOutputArgs(DependencyOutputOpts, Args, SA); } +std::vector CompilerInvocation::getCC1CommandLine() const { + // Set up string allocator. + llvm::BumpPtrAllocator Alloc; + llvm::StringSaver Strings(Alloc); + auto SA = [&Strings](const Twine &Arg) { return Strings.save(Arg).data(); }; + + // Synthesize full command line from the CompilerInvocation, including "-cc1". + SmallVector Args{"-cc1"}; + generateCC1CommandLine(Args, SA); + + // Convert arguments to the return type. + return std::vector{Args.begin(), Args.end()}; +} + +void CompilerInvocation::resetNonModularOptions() { + getLangOpts()->resetNonModularOptions(); + getPreprocessorOpts().resetNonModularOptions(); +} + +void CompilerInvocation::clearImplicitModuleBuildOptions() { + getLangOpts()->ImplicitModules = false; + getHeaderSearchOpts().ImplicitModuleMaps = false; + getHeaderSearchOpts().ModuleCachePath.clear(); + getHeaderSearchOpts().ModulesValidateOncePerBuildSession = false; + getHeaderSearchOpts().BuildSessionTimestamp = 0; + // The specific values we canonicalize to for pruning don't affect behaviour, + /// so use the default values so they may be dropped from the command-line. + getHeaderSearchOpts().ModuleCachePruneInterval = 7 * 24 * 60 * 60; + getHeaderSearchOpts().ModuleCachePruneAfter = 31 * 24 * 60 * 60; +} + IntrusiveRefCntPtr clang::createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags) { -- cgit v1.1