[cfe-commits] r136987 - in /cfe/trunk: include/clang/Frontend/PreprocessorOptions.h lib/Frontend/CompilerInvocation.cpp lib/Frontend/FrontendAction.cpp

Jonathan D. Turner jonathan.d.turner at gmail.com
Fri Aug 5 15:17:03 PDT 2011


Author: jonturner
Date: Fri Aug  5 17:17:03 2011
New Revision: 136987

URL: http://llvm.org/viewvc/llvm-project?rev=136987&view=rev
Log:
Wire up -import-module to run ReadAST for each module loaded.


Modified:
    cfe/trunk/include/clang/Frontend/PreprocessorOptions.h
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Frontend/FrontendAction.cpp

Modified: cfe/trunk/include/clang/Frontend/PreprocessorOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PreprocessorOptions.h?rev=136987&r1=136986&r2=136987&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PreprocessorOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/PreprocessorOptions.h Fri Aug  5 17:17:03 2011
@@ -41,6 +41,7 @@
 public:
   std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
   std::vector<std::string> Includes;
+  std::vector<std::string> Modules;
   std::vector<std::string> MacroIncludes;
 
   unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=136987&r1=136986&r2=136987&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Aug  5 17:17:03 2011
@@ -775,6 +775,10 @@
     Res.push_back("-include");
     Res.push_back(Opts.Includes[i]);
   }
+  for (unsigned i = 0, e = Opts.Modules.size(); i != e; ++i) {
+    Res.push_back("-import_module");
+    Res.push_back(Opts.Modules[i]);
+  }
   for (unsigned i = 0, e = Opts.MacroIncludes.size(); i != e; ++i) {
     Res.push_back("-imacros");
     Res.push_back(Opts.MacroIncludes[i]);
@@ -1807,6 +1811,12 @@
     Opts.ChainedIncludes.push_back(A->getValue(Args));
   }
 
+  for (arg_iterator it = Args.filtered_begin(OPT_import_module),
+      ie = Args.filtered_end(); it != ie; ++it) {
+    const Arg *A = *it;
+    Opts.Modules.push_back(A->getValue(Args));
+  }
+
   // Include 'altivec.h' if -faltivec option present
   if (Args.hasArg(OPT_faltivec))
     Opts.Includes.push_back("altivec.h");

Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=136987&r1=136986&r2=136987&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Fri Aug  5 17:17:03 2011
@@ -20,6 +20,7 @@
 #include "clang/Frontend/MultiplexConsumer.h"
 #include "clang/Parse/ParseAST.h"
 #include "clang/Serialization/ASTDeserializationListener.h"
+#include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ChainedIncludesSource.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Timer.h"
@@ -239,6 +240,30 @@
                                 DeserialListener);
       if (!CI.getASTContext().getExternalSource())
         goto failure;
+    } else if (!CI.getPreprocessorOpts().Modules.empty()) {
+      // Use PCH.
+      assert(hasPCHSupport() && "This action does not have PCH support!");
+      ASTDeserializationListener *DeserialListener =
+          Consumer->GetASTDeserializationListener();
+      if (CI.getPreprocessorOpts().DumpDeserializedPCHDecls)
+        DeserialListener = new DeserializedDeclsDumper(DeserialListener);
+      if (!CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn.empty())
+        DeserialListener = new DeserializedDeclsChecker(CI.getASTContext(),
+                         CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn,
+                                                        DeserialListener);
+
+      CI.createPCHExternalASTSource(CI.getPreprocessorOpts().Modules[0],
+                                    true, true, DeserialListener);
+
+      for (unsigned I = 1, E = CI.getPreprocessorOpts().Modules.size(); I != E;
+          ++I) {
+
+        ASTReader *ModMgr = CI.getModuleManager();
+        ModMgr->ReadAST(CI.getPreprocessorOpts().Modules[I],
+            serialization::MK_Module);
+      }
+      if (!CI.getASTContext().getExternalSource())
+        goto failure;
     }
 
     CI.setASTConsumer(Consumer.take());
@@ -246,7 +271,7 @@
       goto failure;
   }
 
-  // Initialize builtin info as long as we aren't using an external AST
+  // Initialize built-in info as long as we aren't using an external AST
   // source.
   if (!CI.hasASTContext() || !CI.getASTContext().getExternalSource()) {
     Preprocessor &PP = CI.getPreprocessor();





More information about the cfe-commits mailing list