[cfe-commits] r168062 - in /cfe/trunk: include/clang/Serialization/ASTBitCodes.h lib/Frontend/FrontendActions.cpp lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Nov 15 10:57:27 PST 2012


Author: akirtzidis
Date: Thu Nov 15 12:57:27 2012
New Revision: 168062

URL: http://llvm.org/viewvc/llvm-project?rev=168062&view=rev
Log:
[modules] Use a memory buffer directly as input for the module includes,
instead of messing with virtual files.

Modified:
    cfe/trunk/include/clang/Serialization/ASTBitCodes.h
    cfe/trunk/lib/Frontend/FrontendActions.cpp
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=168062&r1=168061&r2=168062&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Thu Nov 15 12:57:27 2012
@@ -259,21 +259,25 @@
       /// \brief The directory that the PCH was originally created in.
       ORIGINAL_PCH_DIR = 6,
 
+      /// \brief Record code for file ID of the file or buffer that was used to
+      /// generate the AST file.
+      ORIGINAL_FILE_ID = 7,
+
       /// \brief Offsets into the input-files block where input files
       /// reside.
-      INPUT_FILE_OFFSETS = 7,
+      INPUT_FILE_OFFSETS = 8,
 
       /// \brief Record code for the diagnostic options table.
-      DIAGNOSTIC_OPTIONS = 8,
+      DIAGNOSTIC_OPTIONS = 9,
 
       /// \brief Record code for the filesystem options table.
-      FILE_SYSTEM_OPTIONS = 9,
+      FILE_SYSTEM_OPTIONS = 10,
 
       /// \brief Record code for the headers search options table.
-      HEADER_SEARCH_OPTIONS = 10,
+      HEADER_SEARCH_OPTIONS = 11,
 
       /// \brief Record code for the preprocessor options table.
-      PREPROCESSOR_OPTIONS = 11
+      PREPROCESSOR_OPTIONS = 12
     };
 
     /// \brief Record types that occur within the input-files block

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=168062&r1=168061&r2=168062&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Thu Nov 15 12:57:27 2012
@@ -273,19 +273,11 @@
     CI.getPreprocessor().getHeaderSearchInfo().getModuleMap(),
     Module, HeaderContents);
 
-  StringRef InputName = Module::getModuleInputBufferName();
-
-  // We consistently construct a buffer as input to build the module.
-  // This means the main file for modules will always be a virtual one.
-  // FIXME: Maybe allow using a memory buffer as input directly instead of
-  // messing with virtual files.
-  const FileEntry *HeaderFile = FileMgr.getVirtualFile(InputName, 
-                                                       HeaderContents.size(), 
-                                                       time(0));
-  llvm::MemoryBuffer *HeaderContentsBuf
-    = llvm::MemoryBuffer::getMemBufferCopy(HeaderContents);
-  CI.getSourceManager().overrideFileContents(HeaderFile, HeaderContentsBuf);  
-  setCurrentInput(FrontendInputFile(InputName, getCurrentFileKind(),
+  llvm::MemoryBuffer *InputBuffer =
+      llvm::MemoryBuffer::getMemBufferCopy(HeaderContents,
+                                           Module::getModuleInputBufferName());
+  // Ownership of InputBuffer will be transfered to the SourceManager.
+  setCurrentInput(FrontendInputFile(InputBuffer, getCurrentFileKind(),
                                     Module->IsSystem));
   return true;
 }

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=168062&r1=168061&r2=168062&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Nov 15 12:57:27 2012
@@ -1796,6 +1796,10 @@
       MaybeAddSystemRootToFilename(F, F.OriginalSourceFileName);
       break;
 
+    case ORIGINAL_FILE_ID:
+      F.OriginalSourceFileID = FileID::get(Record[0]);
+      break;
+
     case ORIGINAL_PCH_DIR:
       F.OriginalDir.assign(BlobStart, BlobLen);
       break;

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=168062&r1=168061&r2=168062&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Nov 15 12:57:27 2012
@@ -777,6 +777,7 @@
   RECORD(TARGET_OPTIONS);
   RECORD(ORIGINAL_FILE);
   RECORD(ORIGINAL_PCH_DIR);
+  RECORD(ORIGINAL_FILE_ID);
   RECORD(INPUT_FILE_OFFSETS);
   RECORD(DIAGNOSTIC_OPTIONS);
   RECORD(FILE_SYSTEM_OPTIONS);
@@ -1180,6 +1181,10 @@
     Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr);
   }
 
+  Record.clear();
+  Record.push_back(SM.getMainFileID().getOpaqueValue());
+  Stream.EmitRecord(ORIGINAL_FILE_ID, Record);
+
   // Original PCH directory
   if (!OutputFile.empty() && OutputFile != "-") {
     BitCodeAbbrev *Abbrev = new BitCodeAbbrev();





More information about the cfe-commits mailing list