[cfe-commits] r86880 - in /cfe/trunk: include/clang/Frontend/CompilerInvocation.h include/clang/Frontend/DependencyOutputOptions.h include/clang/Frontend/PreprocessorOutputOptions.h include/clang/Frontend/Utils.h lib/Frontend/DependencyFile.cpp tools/clang-cc/Options.cpp tools/clang-cc/Options.h tools/clang-cc/clang-cc.cpp

Daniel Dunbar daniel at zuster.org
Wed Nov 11 13:43:13 PST 2009


Author: ddunbar
Date: Wed Nov 11 15:43:12 2009
New Revision: 86880

URL: http://llvm.org/viewvc/llvm-project?rev=86880&view=rev
Log:
Add DependencyOutputOptions to wrap -M... options, and propogate to
CompilerInvocation and clang-cc.

Added:
    cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h
Modified:
    cfe/trunk/include/clang/Frontend/CompilerInvocation.h
    cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h
    cfe/trunk/include/clang/Frontend/Utils.h
    cfe/trunk/lib/Frontend/DependencyFile.cpp
    cfe/trunk/tools/clang-cc/Options.cpp
    cfe/trunk/tools/clang-cc/Options.h
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Frontend/CompilerInvocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInvocation.h?rev=86880&r1=86879&r2=86880&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInvocation.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInvocation.h Wed Nov 11 15:43:12 2009
@@ -12,6 +12,7 @@
 
 #include "clang/Basic/LangOptions.h"
 #include "clang/Frontend/CompileOptions.h"
+#include "clang/Frontend/DependencyOutputOptions.h"
 #include "clang/Frontend/DiagnosticOptions.h"
 #include "clang/Frontend/HeaderSearchOptions.h"
 #include "clang/Frontend/PreprocessorOptions.h"
@@ -31,6 +32,9 @@
   /// Options controlling IRgen and the backend.
   CompileOptions CompileOpts;
 
+  /// Options controlling dependency output.
+  DependencyOutputOptions DependencyOutputOpts;
+
   /// Options controlling the diagnostic engine.
   DiagnosticOptions DiagOpts;
 
@@ -68,6 +72,13 @@
     return CompileOpts;
   }
 
+  DependencyOutputOptions &getDependencyOutputOpts() {
+    return DependencyOutputOpts;
+  }
+  const DependencyOutputOptions &getDependencyOutputOpts() const {
+    return DependencyOutputOpts;
+  }
+
   DiagnosticOptions &getDiagnosticOpts() { return DiagOpts; }
   const DiagnosticOptions &getDiagnosticOpts() const { return DiagOpts; }
 

Added: cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h?rev=86880&view=auto

==============================================================================
--- cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h (added)
+++ cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h Wed Nov 11 15:43:12 2009
@@ -0,0 +1,42 @@
+//===--- DependencyOutputOptions.h ------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_FRONTEND_DEPENDENCYOUTPUTOPTIONS_H
+#define LLVM_CLANG_FRONTEND_DEPENDENCYOUTPUTOPTIONS_H
+
+#include <vector>
+
+namespace clang {
+
+/// DependencyOutputOptions - Options for controlling the compiler dependency
+/// file generation.
+class DependencyOutputOptions {
+public:
+  unsigned IncludeSystemHeaders : 1; ///< Include system header dependencies.
+  unsigned UsePhonyTargets : 1;      ///< Include phony targets for each
+                                     /// dependency, which can avoid some 'make'
+                                     /// problems.
+
+  /// The file to write depencency output to.
+  std::string OutputFile;
+
+  /// A list of names to use as the targets in the dependency file; this list
+  /// must contain at least one entry.
+  std::vector<std::string> Targets;
+
+public:
+  DependencyOutputOptions() {
+    IncludeSystemHeaders = 0;
+    UsePhonyTargets = 0;
+  }
+};
+
+}  // end namespace clang
+
+#endif

Modified: cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h?rev=86880&r1=86879&r2=86880&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h Wed Nov 11 15:43:12 2009
@@ -10,9 +10,6 @@
 #ifndef LLVM_CLANG_FRONTEND_PREPROCESSOROUTPUTOPTIONS_H
 #define LLVM_CLANG_FRONTEND_PREPROCESSOROUTPUTOPTIONS_H
 
-#include <string>
-#include <vector>
-
 namespace clang {
 
 /// PreprocessorOutputOptions - Options for controlling the C preprocessor
@@ -22,8 +19,8 @@
   unsigned ShowCPP : 1;           ///< Print normal preprocessed output.
   unsigned ShowMacros : 1;        ///< Print macro definitions.
   unsigned ShowLineMarkers : 1;   ///< Show #line markers.
-  unsigned ShowComments : 1;      /// Show comments.
-  unsigned ShowMacroComments : 1; /// Show comments, even in macros.
+  unsigned ShowComments : 1;      ///< Show comments.
+  unsigned ShowMacroComments : 1; ///< Show comments, even in macros.
 
 public:
   PreprocessorOutputOptions() {

Modified: cfe/trunk/include/clang/Frontend/Utils.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/Utils.h?rev=86880&r1=86879&r2=86880&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/Utils.h (original)
+++ cfe/trunk/include/clang/Frontend/Utils.h Wed Nov 11 15:43:12 2009
@@ -26,6 +26,7 @@
 namespace clang {
 class ASTConsumer;
 class Decl;
+class DependencyOutputOptions;
 class Diagnostic;
 class HeaderSearch;
 class HeaderSearchOptions;
@@ -77,9 +78,8 @@
 
 /// AttachDependencyFileGen - Create a dependency file generator, and attach
 /// it to the given preprocessor.  This takes ownership of the output stream.
-void AttachDependencyFileGen(Preprocessor *PP, llvm::raw_ostream *OS,
-                             std::vector<std::string> &Targets,
-                             bool IncludeSystemHeaders, bool PhonyTarget);
+void AttachDependencyFileGen(Preprocessor *PP,
+                             const DependencyOutputOptions &Opts);
 
 /// CacheTokens - Cache tokens for use with PCH. Note that this requires
 /// a seekable stream.

Modified: cfe/trunk/lib/Frontend/DependencyFile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DependencyFile.cpp?rev=86880&r1=86879&r2=86880&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/DependencyFile.cpp (original)
+++ cfe/trunk/lib/Frontend/DependencyFile.cpp Wed Nov 11 15:43:12 2009
@@ -12,12 +12,14 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Frontend/Utils.h"
-#include "clang/Basic/SourceManager.h"
 #include "clang/Basic/FileManager.h"
-#include "clang/Lex/Preprocessor.h"
-#include "clang/Lex/PPCallbacks.h"
-#include "clang/Lex/DirectoryLookup.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Frontend/DependencyOutputOptions.h"
+#include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Lex/DirectoryLookup.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
@@ -42,11 +44,10 @@
 public:
   DependencyFileCallback(const Preprocessor *_PP,
                          llvm::raw_ostream *_OS,
-                         const std::vector<std::string> &_Targets,
-                         bool _IncludeSystemHeaders,
-                         bool _PhonyTarget)
-    : PP(_PP), Targets(_Targets), OS(_OS),
-      IncludeSystemHeaders(_IncludeSystemHeaders), PhonyTarget(_PhonyTarget) {}
+                         const DependencyOutputOptions &Opts)
+    : PP(_PP), Targets(Opts.Targets), OS(_OS),
+      IncludeSystemHeaders(Opts.IncludeSystemHeaders),
+      PhonyTarget(Opts.UsePhonyTargets) {}
 
   ~DependencyFileCallback() {
     OutputDependencyFile();
@@ -59,18 +60,23 @@
 };
 }
 
+void clang::AttachDependencyFileGen(Preprocessor *PP,
+                                    const DependencyOutputOptions &Opts) {
+  if (Opts.Targets.empty()) {
+    PP->getDiagnostics().Report(diag::err_fe_dependency_file_requires_MT);
+    return;
+  }
 
+  std::string Err;
+  llvm::raw_ostream *OS(new llvm::raw_fd_ostream(Opts.OutputFile.c_str(), Err));
+  if (!Err.empty()) {
+    PP->getDiagnostics().Report(diag::err_fe_error_opening)
+      << Opts.OutputFile << Err;
+    return;
+  }
 
-void clang::AttachDependencyFileGen(Preprocessor *PP, llvm::raw_ostream *OS,
-                                    std::vector<std::string> &Targets,
-                                    bool IncludeSystemHeaders,
-                                    bool PhonyTarget) {
-  assert(!Targets.empty() && "Target required for dependency generation");
-
-  DependencyFileCallback *PPDep =
-    new DependencyFileCallback(PP, OS, Targets, IncludeSystemHeaders,
-                               PhonyTarget);
-  PP->setPPCallbacks(PPDep);
+  assert(!PP->getPPCallbacks() && "Preprocessor callbacks already registered!");
+  PP->setPPCallbacks(new DependencyFileCallback(PP, OS, Opts));
 }
 
 /// FileMatchesDepCriteria - Determine whether the given Filename should be

Modified: cfe/trunk/tools/clang-cc/Options.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/Options.cpp?rev=86880&r1=86879&r2=86880&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/Options.cpp (original)
+++ cfe/trunk/tools/clang-cc/Options.cpp Wed Nov 11 15:43:12 2009
@@ -16,6 +16,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Frontend/AnalysisConsumer.h"
 #include "clang/Frontend/CompileOptions.h"
+#include "clang/Frontend/DependencyOutputOptions.h"
 #include "clang/Frontend/DiagnosticOptions.h"
 #include "clang/Frontend/HeaderSearchOptions.h"
 #include "clang/Frontend/PCHReader.h"
@@ -190,6 +191,31 @@
 }
 
 //===----------------------------------------------------------------------===//
+// Dependency Output Options
+//===----------------------------------------------------------------------===//
+
+namespace dependencyoutputoptions {
+
+static llvm::cl::opt<std::string>
+DependencyFile("dependency-file",
+               llvm::cl::desc("Filename (or -) to write dependency output to"));
+
+static llvm::cl::opt<bool>
+DependenciesIncludeSystemHeaders("sys-header-deps",
+                 llvm::cl::desc("Include system headers in dependency output"));
+
+static llvm::cl::list<std::string>
+DependencyTargets("MT",
+         llvm::cl::desc("Specify target for dependency"));
+
+static llvm::cl::opt<bool>
+PhonyDependencyTarget("MP",
+            llvm::cl::desc("Create phony target for each dependency "
+                           "(other than main file)"));
+
+}
+
+//===----------------------------------------------------------------------===//
 // Diagnostic Options
 //===----------------------------------------------------------------------===//
 
@@ -616,6 +642,16 @@
 #endif
 }
 
+void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) {
+  using namespace dependencyoutputoptions;
+
+  Opts.OutputFile = DependencyFile;
+  Opts.Targets.insert(Opts.Targets.begin(), DependencyTargets.begin(),
+                      DependencyTargets.end());
+  Opts.IncludeSystemHeaders = DependenciesIncludeSystemHeaders;
+  Opts.UsePhonyTargets = PhonyDependencyTarget;
+}
+
 void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) {
   using namespace diagnosticoptions;
 

Modified: cfe/trunk/tools/clang-cc/Options.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/Options.h?rev=86880&r1=86879&r2=86880&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/Options.h (original)
+++ cfe/trunk/tools/clang-cc/Options.h Wed Nov 11 15:43:12 2009
@@ -16,6 +16,7 @@
 
 class AnalyzerOptions;
 class CompileOptions;
+class DependencyOutputOptions;
 class DiagnosticOptions;
 class HeaderSearchOptions;
 class LangOptions;
@@ -40,6 +41,8 @@
 
 void InitializeAnalyzerOptions(AnalyzerOptions &Opts);
 
+void InitializeDependencyOutputOptions(DependencyOutputOptions &Opts);
+
 void InitializeDiagnosticOptions(DiagnosticOptions &Opts);
 
 void InitializeCompileOptions(CompileOptions &Opts,

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=86880&r1=86879&r2=86880&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Wed Nov 11 15:43:12 2009
@@ -32,6 +32,7 @@
 #include "clang/Frontend/ChainedDiagnosticClient.h"
 #include "clang/Frontend/CommandLineSourceLoc.h"
 #include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/DependencyOutputOptions.h"
 #include "clang/Frontend/FixItRewriter.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/PCHReader.h"
@@ -455,27 +456,6 @@
 static llvm::cl::opt<bool> OptNoWarnings("w");
 
 //===----------------------------------------------------------------------===//
-// Dependency file options
-//===----------------------------------------------------------------------===//
-
-static llvm::cl::opt<std::string>
-DependencyFile("dependency-file",
-               llvm::cl::desc("Filename (or -) to write dependency output to"));
-
-static llvm::cl::opt<bool>
-DependenciesIncludeSystemHeaders("sys-header-deps",
-                 llvm::cl::desc("Include system headers in dependency output"));
-
-static llvm::cl::list<std::string>
-DependencyTargets("MT",
-         llvm::cl::desc("Specify target for dependency"));
-
-static llvm::cl::opt<bool>
-PhonyDependencyTarget("MP",
-            llvm::cl::desc("Create phony target for each dependency "
-                           "(other than main file)"));
-
-//===----------------------------------------------------------------------===//
 // -dump-build-information Stuff
 //===----------------------------------------------------------------------===//
 
@@ -646,8 +626,7 @@
 ///
 static void ProcessInputFile(const CompilerInvocation &CompOpts,
                              Preprocessor &PP, const std::string &InFile,
-                             ProgActions PA,
-                             llvm::LLVMContext& Context) {
+                             ProgActions PA, llvm::LLVMContext& Context) {
   llvm::OwningPtr<llvm::raw_ostream> OS;
   llvm::OwningPtr<ASTConsumer> Consumer;
   bool ClearSourceMgr = false;
@@ -1085,6 +1064,9 @@
     InitializeLangOptions(Opts.getLangOpts(), LK, Target,
                           Opts.getCompileOpts());
 
+  // Initialize the dependency output options (-M...).
+  InitializeDependencyOutputOptions(Opts.getDependencyOutputOpts());
+
   // Initialize the header search options.
   InitializeHeaderSearchOptions(Opts.getHeaderSearchOpts(),
                                 GetBuiltinIncludePath(Argv0),
@@ -1229,23 +1211,8 @@
                             HeaderInfo));
 
     // Handle generating dependencies, if requested.
-    if (!DependencyFile.empty()) {
-      if (DependencyTargets.empty()) {
-        Diags.Report(diag::err_fe_dependency_file_requires_MT);
-        continue;
-      }
-      std::string ErrStr;
-      llvm::raw_ostream *DependencyOS =
-          new llvm::raw_fd_ostream(DependencyFile.c_str(), ErrStr);
-      if (!ErrStr.empty()) {
-        Diags.Report(diag::err_fe_error_opening) << DependencyFile << ErrStr;
-        continue;
-      }
-
-      AttachDependencyFileGen(PP.get(), DependencyOS, DependencyTargets,
-                              DependenciesIncludeSystemHeaders,
-                              PhonyDependencyTarget);
-    }
+    if (!CompOpts.getDependencyOutputOpts().OutputFile.empty())
+      AttachDependencyFileGen(PP.get(), CompOpts.getDependencyOutputOpts());
 
     if (CompOpts.getPreprocessorOpts().getImplicitPCHInclude().empty()) {
       if (InitializeSourceManager(*PP.get(), InFile))





More information about the cfe-commits mailing list