diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-08-31 06:26:43 +0000 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-08-31 06:26:43 +0000 |
commit | d30446fd773e9571a287bb2c3e5d06ab86f7e18b (patch) | |
tree | 33333cfa1ff0bf4559655240ddc861f4c9ee9147 /clang/lib/Serialization/ASTReader.cpp | |
parent | b8198f02e689b2234c09c1171539ecfa3a0f59b2 (diff) | |
download | bcm5719-llvm-d30446fd773e9571a287bb2c3e5d06ab86f7e18b.tar.gz bcm5719-llvm-d30446fd773e9571a287bb2c3e5d06ab86f7e18b.zip |
[modules] Add ability to specify module name to module file mapping (reapply)
Extend the -fmodule-file option to support the [<name>=]<file> value format.
If the name is omitted, then the old semantics is preserved (the module file
is loaded whether needed or not). If the name is specified, then the mapping
is treated as just another prebuilt module search mechanism, similar to
-fprebuilt-module-path, and the module file is only loaded if actually used
(e.g., via import). With one exception: this mapping also overrides module
file references embedded in other modules (which can be useful if module files
are moved/renamed as often happens during remote compilation).
This override semantics requires some extra work: we now store the module name
in addition to the file name in the serialized AST representation.
Reviewed By: rsmith
Differential Revision: https://reviews.llvm.org/D35020
llvm-svn: 312220
Diffstat (limited to 'clang/lib/Serialization/ASTReader.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 55136e3a3ce..2db46a65709 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2485,7 +2485,23 @@ ASTReader::ReadControlBlock(ModuleFile &F, {{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++], (uint32_t)Record[Idx++], (uint32_t)Record[Idx++], (uint32_t)Record[Idx++]}}}; - auto ImportedFile = ReadPath(F, Record, Idx); + + std::string ImportedName = ReadString(Record, Idx); + std::string ImportedFile; + + // For prebuilt and explicit modules first consult the file map for + // an override. Note that here we don't search prebuilt module + // directories, only the explicit name to file mappings. Also, we will + // still verify the size/signature making sure it is essentially the + // same file but perhaps in a different location. + if (ImportedKind == MK_PrebuiltModule || ImportedKind == MK_ExplicitModule) + ImportedFile = PP.getHeaderSearchInfo().getPrebuiltModuleFileName( + ImportedName, /*FileMapOnly*/ true); + + if (ImportedFile.empty()) + ImportedFile = ReadPath(F, Record, Idx); + else + SkipPath(Record, Idx); // If our client can't cope with us being out of date, we can't cope with // our dependency being missing. @@ -3420,12 +3436,18 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const { RemapBuilder TypeRemap(F.TypeRemap); while (Data < DataEnd) { - // FIXME: Looking up dependency modules by filename is horrible. + // FIXME: Looking up dependency modules by filename is horrible. Let's + // start fixing this with prebuilt and explicit modules and see how it + // goes... using namespace llvm::support; + ModuleKind Kind = static_cast<ModuleKind>( + endian::readNext<uint8_t, little, unaligned>(Data)); uint16_t Len = endian::readNext<uint16_t, little, unaligned>(Data); StringRef Name = StringRef((const char*)Data, Len); Data += Len; - ModuleFile *OM = ModuleMgr.lookup(Name); + ModuleFile *OM = (Kind == MK_PrebuiltModule || Kind == MK_ExplicitModule + ? ModuleMgr.lookupByModuleName(Name) + : ModuleMgr.lookupByFileName(Name)); if (!OM) { std::string Msg = "SourceLocation remap refers to unknown module, cannot find "; @@ -4756,6 +4778,7 @@ bool ASTReader::readASTFileControlBlock( while (Idx < N) { // Read information about the AST file. Idx += 5; // ImportLoc, Size, ModTime, Signature + SkipString(Record, Idx); // Module name; FIXME: pass to listener? std::string Filename = ReadString(Record, Idx); ResolveImportedPath(Filename, ModuleDir); Listener.visitImport(Filename); @@ -10346,7 +10369,8 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), PCHContainerRdr(PCHContainerRdr), Diags(PP.getDiagnostics()), PP(PP), ContextObj(Context), - ModuleMgr(PP.getFileManager(), PP.getPCMCache(), PCHContainerRdr), + ModuleMgr(PP.getFileManager(), PP.getPCMCache(), PCHContainerRdr, + PP.getHeaderSearchInfo()), PCMCache(PP.getPCMCache()), DummyIdResolver(PP), ReadTimer(std::move(ReadTimer)), isysroot(isysroot), DisableValidation(DisableValidation), |