[cfe-commits] r136686 - in /cfe/trunk: include/clang/Serialization/ContinuousRangeMap.h lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp
Douglas Gregor
dgregor at apple.com
Tue Aug 2 03:56:51 PDT 2011
Author: dgregor
Date: Tue Aug 2 05:56:51 2011
New Revision: 136686
URL: http://llvm.org/viewvc/llvm-project?rev=136686&view=rev
Log:
Generalize the module offset map to include mapping information for
all of the kinds of IDs that can be offset. No effectively
functionality change; this is preparation for adding remapping for
IDs.
Modified:
cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
Modified: cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h?rev=136686&r1=136685&r2=136686&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h (original)
+++ cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h Tue Aug 2 05:56:51 2011
@@ -89,6 +89,30 @@
reference back() { return Rep.back(); }
const_reference back() const { return Rep.back(); }
+
+ /// \brief An object that helps properly build a continuous range map
+ /// from a set of values.
+ class Builder {
+ ContinuousRangeMap &Self;
+ SmallVector<std::pair<Int, V>, InitialCapacity> Elements;
+
+ Builder(const Builder&); // DO NOT IMPLEMENT
+ Builder &operator=(const Builder&); // DO NOT IMPLEMENT
+
+ public:
+ explicit Builder(ContinuousRangeMap &Self) : Self(Self) { }
+
+ ~Builder() {
+ std::sort(Elements.begin(), Elements.end(), Compare());
+ for (unsigned I = 0, N = Elements.size(); I != N; ++I)
+ Self.insert(Elements[I]);
+ }
+
+ void insert(const value_type &Val) {
+ Elements.push_back(Val);
+ }
+ };
+ friend class Builder;
};
}
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=136686&r1=136685&r2=136686&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Aug 2 05:56:51 2011
@@ -2275,19 +2275,41 @@
// Additional remapping information.
const unsigned char *Data = (const unsigned char*)BlobStart;
const unsigned char *DataEnd = Data + BlobLen;
+
+ // Continuous range maps we may be updating in our module.
+ ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap);
+
while(Data < DataEnd) {
- uint32_t Offset = io::ReadUnalignedLE32(Data);
uint16_t Len = io::ReadUnalignedLE16(Data);
StringRef Name = StringRef((const char*)Data, Len);
+ Data += Len;
Module *OM = ModuleMgr.lookup(Name);
if (!OM) {
Error("SourceLocation remap refers to unknown module");
return Failure;
}
- // My Offset is mapped to OM->SLocEntryBaseOffset.
- F.SLocRemap.insert(std::make_pair(Offset,
- static_cast<int>(OM->SLocEntryBaseOffset - Offset)));
- Data += Len;
+
+ uint32_t SLocOffset = io::ReadUnalignedLE32(Data);
+ uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data);
+ uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data);
+ uint32_t MacroDefinitionIDOffset = io::ReadUnalignedLE32(Data);
+ uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data);
+ uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data);
+ uint32_t CXXBaseSpecifiersIDOffset = io::ReadUnalignedLE32(Data);
+ uint32_t TypeIDOffset = io::ReadUnalignedLE32(Data);
+
+ // Source location offset is mapped to OM->SLocEntryBaseOffset.
+ SLocRemap.insert(std::make_pair(SLocOffset,
+ static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset)));
+
+ // FIXME: Map other locations
+ (void)IdentifierIDOffset;
+ (void)PreprocessedEntityIDOffset;
+ (void)MacroDefinitionIDOffset;
+ (void)SelectorIDOffset;
+ (void)DeclIDOffset;
+ (void)CXXBaseSpecifiersIDOffset;
+ (void)TypeIDOffset;
}
break;
}
@@ -5434,15 +5456,18 @@
: Kind(Kind), SizeInBits(0), LocalNumSLocEntries(0), SLocEntryBaseID(0),
SLocEntryBaseOffset(0), SLocEntryOffsets(0),
SLocFileOffsets(0), LocalNumIdentifiers(0),
- IdentifierOffsets(0), IdentifierTableData(0),
- IdentifierLookupTable(0), LocalNumMacroDefinitions(0),
- MacroDefinitionOffsets(0), LocalNumHeaderFileInfos(0),
+ IdentifierOffsets(0), BaseIdentifierID(0), IdentifierTableData(0),
+ IdentifierLookupTable(0), BasePreprocessedEntityID(0),
+ LocalNumMacroDefinitions(0), MacroDefinitionOffsets(0),
+ BaseMacroDefinitionID(0), LocalNumHeaderFileInfos(0),
HeaderFileInfoTableData(0), HeaderFileInfoTable(0),
HeaderFileFrameworkStrings(0),
- LocalNumSelectors(0), SelectorOffsets(0),
+ LocalNumSelectors(0), SelectorOffsets(0), BaseSelectorID(0),
SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0),
- DeclOffsets(0), LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0),
- LocalNumTypes(0), TypeOffsets(0), StatCache(0),
+ DeclOffsets(0), BaseDeclID(0),
+ LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0),
+ BaseCXXBaseSpecifiersID(0),
+ LocalNumTypes(0), TypeOffsets(0), BaseTypeID(0), StatCache(0),
NumPreallocatedPreprocessingEntities(0)
{}
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=136686&r1=136685&r2=136686&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Tue Aug 2 05:56:51 2011
@@ -3041,35 +3041,43 @@
// Write the mapping information describing our module dependencies and how
// each of those modules were mapped into our own offset/ID space, so that
// the reader can build the appropriate mapping to its own offset/ID space.
-
- // If we have module dependencies, write the mapping from source locations to
- // their containing modules, so that the reader can build the remapping.
// The map consists solely of a blob with the following format:
- // *(offset:i32 len:i16 name:len*i8)
- // Sorted by offset.
- typedef std::pair<uint32_t, StringRef> ModuleOffset;
- SmallVector<ModuleOffset, 16> Modules;
-
- Chain->ModuleMgr.exportLookup(Modules);
-
+ // *(module-name-len:i16 module-name:len*i8
+ // source-location-offset:i32
+ // identifier-id:i32
+ // preprocessed-entity-id:i32
+ // macro-definition-id:i32
+ // selector-id:i32
+ // declaration-id:i32
+ // c++-base-specifiers-id:i32
+ // type-id:i32)
+ //
llvm::BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP));
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
- unsigned SLocMapAbbrev = Stream.EmitAbbrev(Abbrev);
+ unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(Abbrev);
llvm::SmallString<2048> Buffer;
{
llvm::raw_svector_ostream Out(Buffer);
- for (SmallVector<ModuleOffset, 16>::iterator I = Modules.begin(),
- E = Modules.end();
- I != E; ++I) {
- io::Emit32(Out, I->first);
- io::Emit16(Out, I->second.size());
- Out.write(I->second.data(), I->second.size());
+ for (ModuleManager::ModuleConstIterator M = Chain->ModuleMgr.begin(),
+ MEnd = Chain->ModuleMgr.end();
+ M != MEnd; ++M) {
+ StringRef FileName = (*M)->FileName;
+ io::Emit16(Out, FileName.size());
+ Out.write(FileName.data(), FileName.size());
+ io::Emit32(Out, (*M)->SLocEntryBaseOffset);
+ io::Emit32(Out, (*M)->BaseIdentifierID);
+ io::Emit32(Out, (*M)->BasePreprocessedEntityID);
+ io::Emit32(Out, (*M)->BaseMacroDefinitionID);
+ io::Emit32(Out, (*M)->BaseSelectorID);
+ io::Emit32(Out, (*M)->BaseDeclID);
+ io::Emit32(Out, (*M)->BaseCXXBaseSpecifiersID);
+ io::Emit32(Out, (*M)->BaseTypeID);
}
}
Record.clear();
Record.push_back(MODULE_OFFSET_MAP);
- Stream.EmitRecordWithBlob(SLocMapAbbrev, Record,
+ Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record,
Buffer.data(), Buffer.size());
// The special types are in the chained PCH.
More information about the cfe-commits
mailing list