[cfe-commits] r144723 - in /cfe/trunk: include/clang/Frontend/FrontendActions.h lib/Frontend/CompilerInstance.cpp lib/Frontend/FrontendActions.cpp lib/FrontendTool/ExecuteCompilerInvocation.cpp

Douglas Gregor dgregor at apple.com
Tue Nov 15 14:58:25 PST 2011


Author: dgregor
Date: Tue Nov 15 16:58:25 2011
New Revision: 144723

URL: http://llvm.org/viewvc/llvm-project?rev=144723&view=rev
Log:
Revert r144703. It was a dumb idea anyway; will add the new bits more
incrementally with a new frontend action.

Modified:
    cfe/trunk/include/clang/Frontend/FrontendActions.h
    cfe/trunk/lib/Frontend/CompilerInstance.cpp
    cfe/trunk/lib/Frontend/FrontendActions.cpp
    cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Frontend/FrontendActions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendActions.h?rev=144723&r1=144722&r2=144723&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendActions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendActions.h Tue Nov 15 16:58:25 2011
@@ -67,40 +67,22 @@
 };
 
 class GeneratePCHAction : public ASTFrontendAction {
+  bool MakeModule;
+  
 protected:
   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
                                          StringRef InFile);
 
   virtual TranslationUnitKind getTranslationUnitKind() { 
-    return TU_Prefix;
+    return MakeModule? TU_Module : TU_Prefix;
   }
 
   virtual bool hasASTFileSupport() const { return false; }
 
 public:
-  /// \brief Compute the AST consumer arguments that will be used to
-  /// create the PCHGenerator instance returned by CreateASTConsumer.
-  ///
-  /// \returns true if an error occurred, false otherwise.
-  static bool ComputeASTConsumerArguments(CompilerInstance &CI,
-                                          StringRef InFile,
-                                          std::string &Sysroot,
-                                          std::string &OutputFile,
-                                          raw_ostream *&OS);
-};
-
-class GenerateModuleAction : public ASTFrontendAction {
-protected:
-  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
-                                         StringRef InFile);
-  
-  virtual TranslationUnitKind getTranslationUnitKind() { 
-    return TU_Module;
-  }
+  /// \brief Create a new action
+  explicit GeneratePCHAction(bool MakeModule) : MakeModule(MakeModule) { }
   
-  virtual bool hasASTFileSupport() const { return false; }
-  
-public:
   /// \brief Compute the AST consumer arguments that will be used to
   /// create the PCHGenerator instance returned by CreateASTConsumer.
   ///

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=144723&r1=144722&r2=144723&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Tue Nov 15 16:58:25 2011
@@ -647,14 +647,13 @@
     llvm::EnableStatistics();
 
   for (unsigned i = 0, e = getFrontendOpts().Inputs.size(); i != e; ++i) {
-    InputKind InKind = getFrontendOpts().Inputs[i].first;
-    std::string InFile = getFrontendOpts().Inputs[i].second;
-    
+    const std::string &InFile = getFrontendOpts().Inputs[i].second;
+
     // Reset the ID tables if we are reusing the SourceManager.
     if (hasSourceManager())
       getSourceManager().clearIDTables();
 
-    if (Act.BeginSourceFile(*this, InFile, InKind)) {
+    if (Act.BeginSourceFile(*this, InFile, getFrontendOpts().Inputs[i].first)) {
       Act.Execute();
       Act.EndSourceFile();
     }
@@ -699,7 +698,7 @@
 namespace {
   struct CompileModuleData {
     CompilerInstance &Instance;
-    GenerateModuleAction &CreateModuleAction;
+    GeneratePCHAction &CreateModuleAction;
   };
 }
 
@@ -1024,7 +1023,7 @@
                              /*ShouldCloneClient=*/true);
 
   // Construct a module-generating action.
-  GenerateModuleAction CreateModuleAction;
+  GeneratePCHAction CreateModuleAction(true);
 
   // Execute the action to actually build the module in-place. Use a separate
   // thread so that we get a stack large enough.

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=144723&r1=144722&r2=144723&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Tue Nov 15 16:58:25 2011
@@ -85,7 +85,7 @@
 
   if (!CI.getFrontendOpts().RelocatablePCH)
     Sysroot.clear();
-  return new PCHGenerator(CI.getPreprocessor(), OutputFile, /*Module=*/false, 
+  return new PCHGenerator(CI.getPreprocessor(), OutputFile, MakeModule, 
                           Sysroot, OS);
 }
 
@@ -113,44 +113,6 @@
   return false;
 }
 
-ASTConsumer *GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI,
-                                                     StringRef InFile) {
-  std::string Sysroot;
-  std::string OutputFile;
-  raw_ostream *OS = 0;
-  if (ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile, OS))
-    return 0;
-  
-  if (!CI.getFrontendOpts().RelocatablePCH)
-    Sysroot.clear();
-  return new PCHGenerator(CI.getPreprocessor(), OutputFile, /*Module=*/true, 
-                          Sysroot, OS);
-}
-
-bool GenerateModuleAction::ComputeASTConsumerArguments(CompilerInstance &CI,
-                                                       StringRef InFile,
-                                                       std::string &Sysroot,
-                                                       std::string &OutputFile,
-                                                       raw_ostream *&OS) {
-  Sysroot = CI.getHeaderSearchOpts().Sysroot;
-  if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) {
-    CI.getDiagnostics().Report(diag::err_relocatable_without_isysroot);
-    return true;
-  }
-  
-  // We use createOutputFile here because this is exposed via libclang, and we
-  // must disable the RemoveFileOnSignal behavior.
-  // We use a temporary to avoid race conditions.
-  OS = CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true,
-                           /*RemoveFileOnSignal=*/false, InFile,
-                           /*Extension=*/"", /*useTemporary=*/true);
-  if (!OS)
-    return true;
-  
-  OutputFile = CI.getFrontendOpts().OutputFile;
-  return false;
-}
-
 ASTConsumer *SyntaxOnlyAction::CreateASTConsumer(CompilerInstance &CI,
                                                  StringRef InFile) {
   return new ASTConsumer();

Modified: cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp?rev=144723&r1=144722&r2=144723&view=diff
==============================================================================
--- cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp (original)
+++ cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp Tue Nov 15 16:58:25 2011
@@ -49,8 +49,8 @@
   case EmitCodeGenOnly:        return new EmitCodeGenOnlyAction();
   case EmitObj:                return new EmitObjAction();
   case FixIt:                  return new FixItAction();
-  case GenerateModule:         return new GenerateModuleAction();
-  case GeneratePCH:            return new GeneratePCHAction();
+  case GenerateModule:         return new GeneratePCHAction(true);
+  case GeneratePCH:            return new GeneratePCHAction(false);
   case GeneratePTH:            return new GeneratePTHAction();
   case InitOnly:               return new InitOnlyAction();
   case ParseSyntaxOnly:        return new SyntaxOnlyAction();





More information about the cfe-commits mailing list