mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-11 08:48:12 +00:00
Infer the submodule ID for a given declaration based on the location
of that declaration, and encode the submodule ID in each declaration stored in an AST file. llvm-svn: 145555
This commit is contained in:
parent
947ccc7396
commit
a28bcddef6
@ -95,6 +95,9 @@ private:
|
||||
/// \brief The ASTContext we're writing.
|
||||
ASTContext *Context;
|
||||
|
||||
/// \brief The preprocessor we're writing.
|
||||
Preprocessor *PP;
|
||||
|
||||
/// \brief The reader of existing AST files, if we're chaining.
|
||||
ASTReader *Chain;
|
||||
|
||||
@ -385,6 +388,11 @@ private:
|
||||
void WriteHeaderSearch(const HeaderSearch &HS, StringRef isysroot);
|
||||
void WritePreprocessorDetail(PreprocessingRecord &PPRec);
|
||||
void WriteSubmodules(Module *WritingModule);
|
||||
|
||||
/// \brief Infer the submodule ID that contains an entity at the given
|
||||
/// source location.
|
||||
serialization::SubmoduleID inferSubmoduleIDFromLocation(SourceLocation Loc);
|
||||
|
||||
void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag);
|
||||
void WriteCXXBaseSpecifiersOffsets();
|
||||
void WriteType(QualType T);
|
||||
|
@ -253,6 +253,10 @@ void ASTDeclReader::VisitDecl(Decl *D) {
|
||||
D->setAccess((AccessSpecifier)Record[Idx++]);
|
||||
D->FromASTFile = true;
|
||||
D->ModulePrivate = Record[Idx++];
|
||||
|
||||
unsigned SubmoduleID = Record[Idx++];
|
||||
// FIXME: Actual use the submodule ID to determine visibility.
|
||||
(void)SubmoduleID;
|
||||
}
|
||||
|
||||
void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
|
||||
|
@ -1943,6 +1943,38 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
|
||||
Stream.ExitBlock();
|
||||
}
|
||||
|
||||
serialization::SubmoduleID
|
||||
ASTWriter::inferSubmoduleIDFromLocation(SourceLocation Loc) {
|
||||
if (Loc.isInvalid() || SubmoduleIDs.empty())
|
||||
return 0; // No submodule
|
||||
|
||||
// Use the expansion location to determine which module we're in.
|
||||
SourceManager &SrcMgr = PP->getSourceManager();
|
||||
SourceLocation ExpansionLoc = SrcMgr.getExpansionLoc(Loc);
|
||||
if (!ExpansionLoc.isFileID())
|
||||
return 0;
|
||||
|
||||
|
||||
FileID ExpansionFileID = SrcMgr.getFileID(ExpansionLoc);
|
||||
const FileEntry *ExpansionFile = SrcMgr.getFileEntryForID(ExpansionFileID);
|
||||
if (!ExpansionFile)
|
||||
return 0;
|
||||
|
||||
// Find the module that owns this header.
|
||||
ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap();
|
||||
Module *OwningMod = ModMap.findModuleForHeader(ExpansionFile);
|
||||
if (!OwningMod)
|
||||
return 0;
|
||||
|
||||
// Check whether we known about this submodule.
|
||||
llvm::DenseMap<Module *, unsigned>::iterator Known
|
||||
= SubmoduleIDs.find(OwningMod);
|
||||
if (Known == SubmoduleIDs.end())
|
||||
return 0;
|
||||
|
||||
return Known->second;
|
||||
}
|
||||
|
||||
void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag) {
|
||||
RecordData Record;
|
||||
for (DiagnosticsEngine::DiagStatePointsTy::const_iterator
|
||||
@ -2862,7 +2894,7 @@ void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) {
|
||||
}
|
||||
|
||||
ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream)
|
||||
: Stream(Stream), Context(0), Chain(0), WritingAST(false),
|
||||
: Stream(Stream), Context(0), PP(0), Chain(0), WritingAST(false),
|
||||
FirstDeclID(NUM_PREDEF_DECL_IDS), NextDeclID(FirstDeclID),
|
||||
FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID),
|
||||
FirstIdentID(NUM_PREDEF_IDENT_IDS), NextIdentID(FirstIdentID),
|
||||
@ -2903,8 +2935,10 @@ void ASTWriter::WriteAST(Sema &SemaRef, MemorizeStatCalls *StatCalls,
|
||||
WriteBlockInfoBlock();
|
||||
|
||||
Context = &SemaRef.Context;
|
||||
PP = &SemaRef.PP;
|
||||
WriteASTCore(SemaRef, StatCalls, isysroot, OutputFile, WritingModule);
|
||||
Context = 0;
|
||||
PP = 0;
|
||||
|
||||
WritingAST = false;
|
||||
}
|
||||
@ -3124,6 +3158,10 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
|
||||
AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes);
|
||||
AddTypeRef(Context.getucontext_tType(), SpecialTypes);
|
||||
|
||||
// If we're emitting a module, write out the submodule information.
|
||||
if (WritingModule)
|
||||
WriteSubmodules(WritingModule);
|
||||
|
||||
// Keep writing types and declarations until all types and
|
||||
// declarations have been written.
|
||||
Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE);
|
||||
@ -3188,8 +3226,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
|
||||
Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record,
|
||||
Buffer.data(), Buffer.size());
|
||||
}
|
||||
if (WritingModule)
|
||||
WriteSubmodules(WritingModule);
|
||||
WritePreprocessor(PP, WritingModule != 0);
|
||||
WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot);
|
||||
WriteSelectors(SemaRef);
|
||||
|
@ -157,6 +157,7 @@ void ASTDeclWriter::VisitDecl(Decl *D) {
|
||||
Record.push_back(D->TopLevelDeclInObjCContainer);
|
||||
Record.push_back(D->getAccess());
|
||||
Record.push_back(D->ModulePrivate);
|
||||
Record.push_back(Writer.inferSubmoduleIDFromLocation(D->getLocation()));
|
||||
}
|
||||
|
||||
void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
|
||||
@ -1287,6 +1288,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
||||
// NamedDecl
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
||||
@ -1318,6 +1320,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
||||
// NamedDecl
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
||||
@ -1354,6 +1357,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
||||
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
||||
// NamedDecl
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
||||
@ -1400,6 +1404,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
||||
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
||||
// NamedDecl
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
||||
@ -1440,6 +1445,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
||||
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
||||
// NamedDecl
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
||||
@ -1487,6 +1493,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
||||
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
||||
// NamedDecl
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
||||
@ -1514,6 +1521,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
|
||||
Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
|
||||
// NamedDecl
|
||||
Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
|
||||
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
|
||||
|
Loading…
Reference in New Issue
Block a user