[cfe-commits] r149224 - in /cfe/trunk: include/clang/Basic/Module.h include/clang/Lex/HeaderSearch.h include/clang/Lex/ModuleMap.h lib/Basic/Module.cpp lib/Frontend/ASTUnit.cpp lib/Frontend/CompilerInstance.cpp lib/Frontend/FrontendActions.cpp lib/Lex/HeaderSearch.cpp lib/Lex/ModuleMap.cpp lib/Lex/Preprocessor.cpp lib/Serialization/ASTReader.cpp unittests/Basic/SourceManagerTest.cpp unittests/Lex/LexerTest.cpp
Douglas Gregor
dgregor at apple.com
Sun Jan 29 22:01:30 PST 2012
Author: dgregor
Date: Mon Jan 30 00:01:29 2012
New Revision: 149224
URL: http://llvm.org/viewvc/llvm-project?rev=149224&view=rev
Log:
Thread a TargetInfo through to the module map; we'll need it for
target-specific module requirements.
Modified:
cfe/trunk/include/clang/Basic/Module.h
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/include/clang/Lex/ModuleMap.h
cfe/trunk/lib/Basic/Module.cpp
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Lex/HeaderSearch.cpp
cfe/trunk/lib/Lex/ModuleMap.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/unittests/Basic/SourceManagerTest.cpp
cfe/trunk/unittests/Lex/LexerTest.cpp
Modified: cfe/trunk/include/clang/Basic/Module.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=149224&r1=149223&r2=149224&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Module.h (original)
+++ cfe/trunk/include/clang/Basic/Module.h Mon Jan 30 00:01:29 2012
@@ -33,6 +33,7 @@
class DirectoryEntry;
class FileEntry;
class LangOptions;
+class TargetInfo;
/// \brief Describes the name of a module.
typedef llvm::SmallVector<std::pair<std::string, SourceLocation>, 2>
@@ -178,10 +179,14 @@
/// \param LangOpts The language options used for the current
/// translation unit.
///
+ /// \param Target The target options used for the current translation unit.
+ ///
/// \param Feature If this module is unavailable, this parameter
/// will be set to one of the features that is required for use of
/// this module (but is not available).
- bool isAvailable(const LangOptions &LangOpts, StringRef &Feature) const;
+ bool isAvailable(const LangOptions &LangOpts,
+ const TargetInfo &Target,
+ StringRef &Feature) const;
/// \brief Determine whether this module is a submodule.
bool isSubModule() const { return Parent != 0; }
@@ -246,7 +251,11 @@
///
/// \param LangOpts The set of language options that will be used to
/// evaluate the availability of this feature.
- void addRequirement(StringRef Feature, const LangOptions &LangOpts);
+ ///
+ /// \param Target The target options that will be used to evaluate the
+ /// availability of this feature.
+ void addRequirement(StringRef Feature, const LangOptions &LangOpts,
+ const TargetInfo &Target);
/// \brief Find the submodule with the given name.
///
Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=149224&r1=149223&r2=149224&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Mon Jan 30 00:01:29 2012
@@ -189,7 +189,7 @@
public:
HeaderSearch(FileManager &FM, DiagnosticsEngine &Diags,
- const LangOptions &LangOpts);
+ const LangOptions &LangOpts, const TargetInfo *Target);
~HeaderSearch();
FileManager &getFileMgr() const { return FileMgr; }
@@ -243,6 +243,10 @@
ExternalSource = ES;
}
+ /// \brief Set the target information for the header search, if not
+ /// already known.
+ void setTarget(const TargetInfo &Target);
+
/// LookupFile - Given a "foo" or <foo> reference, look up the indicated file,
/// return null on failure.
///
Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=149224&r1=149223&r2=149224&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Mon Jan 30 00:01:29 2012
@@ -39,7 +39,8 @@
SourceManager *SourceMgr;
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags;
const LangOptions &LangOpts;
-
+ const TargetInfo *Target;
+
/// \brief Language options used to parse the module map itself.
///
/// These are always simple C language options.
@@ -89,13 +90,18 @@
/// diagnostics.
///
/// \param LangOpts Language options for this translation unit.
+ ///
+ /// \param Target The target for this translation unit.
ModuleMap(FileManager &FileMgr, const DiagnosticConsumer &DC,
- const LangOptions &LangOpts);
+ const LangOptions &LangOpts, const TargetInfo *Target);
/// \brief Destroy the module map.
///
~ModuleMap();
-
+
+ /// \brief Set the target information.
+ void setTarget(const TargetInfo &Target);
+
/// \brief Retrieve the module that owns the given header file, if any.
///
/// \param File The header file that is likely to be included.
Modified: cfe/trunk/lib/Basic/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Module.cpp?rev=149224&r1=149223&r2=149224&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Module.cpp (original)
+++ cfe/trunk/lib/Basic/Module.cpp Mon Jan 30 00:01:29 2012
@@ -47,7 +47,8 @@
/// \brief Determine whether a translation unit built using the current
/// language options has the given feature.
-static bool hasFeature(StringRef Feature, const LangOptions &LangOpts) {
+static bool hasFeature(StringRef Feature, const LangOptions &LangOpts,
+ const TargetInfo &Target) {
return llvm::StringSwitch<bool>(Feature)
.Case("blocks", LangOpts.Blocks)
.Case("cplusplus", LangOpts.CPlusPlus)
@@ -58,13 +59,14 @@
}
bool
-Module::isAvailable(const LangOptions &LangOpts, StringRef &Feature) const {
+Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target,
+ StringRef &Feature) const {
if (IsAvailable)
return true;
for (const Module *Current = this; Current; Current = Current->Parent) {
for (unsigned I = 0, N = Current->Requires.size(); I != N; ++I) {
- if (!hasFeature(Current->Requires[I], LangOpts)) {
+ if (!hasFeature(Current->Requires[I], LangOpts, Target)) {
Feature = Current->Requires[I];
return false;
}
@@ -121,11 +123,12 @@
return Umbrella.dyn_cast<const DirectoryEntry *>();
}
-void Module::addRequirement(StringRef Feature, const LangOptions &LangOpts) {
+void Module::addRequirement(StringRef Feature, const LangOptions &LangOpts,
+ const TargetInfo &Target) {
Requires.push_back(Feature);
// If this feature is currently available, we're done.
- if (hasFeature(Feature, LangOpts))
+ if (hasFeature(Feature, LangOpts, Target))
return;
if (!IsAvailable)
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=149224&r1=149223&r2=149224&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Jan 30 00:01:29 2012
@@ -673,7 +673,8 @@
AST->getFileManager());
AST->HeaderInfo.reset(new HeaderSearch(AST->getFileManager(),
AST->getDiagnostics(),
- AST->ASTFileLangOpts));
+ AST->ASTFileLangOpts,
+ /*Target=*/0));
for (unsigned I = 0; I != NumRemappedFiles; ++I) {
FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second;
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=149224&r1=149223&r2=149224&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Mon Jan 30 00:01:29 2012
@@ -242,7 +242,8 @@
// Create the Preprocessor.
HeaderSearch *HeaderInfo = new HeaderSearch(getFileManager(),
getDiagnostics(),
- getLangOpts());
+ getLangOpts(),
+ &getTarget());
PP = new Preprocessor(getDiagnostics(), getLangOpts(), &getTarget(),
getSourceManager(), *HeaderInfo, *this, PTHMgr,
/*OwnsHeaderSearch=*/true);
@@ -1045,7 +1046,7 @@
// Check whether this module is available.
StringRef Feature;
- if (!Module->isAvailable(getLangOpts(), Feature)) {
+ if (!Module->isAvailable(getLangOpts(), getTarget(), Feature)) {
getDiagnostics().Report(ImportLoc, diag::err_module_unavailable)
<< Module->getFullModuleName()
<< Feature
Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=149224&r1=149223&r2=149224&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Mon Jan 30 00:01:29 2012
@@ -237,7 +237,7 @@
// Check whether we can build this module at all.
StringRef Feature;
- if (!Module->isAvailable(CI.getLangOpts(), Feature)) {
+ if (!Module->isAvailable(CI.getLangOpts(), CI.getTarget(), Feature)) {
CI.getDiagnostics().Report(diag::err_module_unavailable)
<< Module->getFullModuleName()
<< Feature;
Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=149224&r1=149223&r2=149224&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Mon Jan 30 00:01:29 2012
@@ -39,9 +39,10 @@
ExternalHeaderFileInfoSource::~ExternalHeaderFileInfoSource() {}
HeaderSearch::HeaderSearch(FileManager &FM, DiagnosticsEngine &Diags,
- const LangOptions &LangOpts)
+ const LangOptions &LangOpts,
+ const TargetInfo *Target)
: FileMgr(FM), Diags(Diags), FrameworkMap(64),
- ModMap(FileMgr, *Diags.getClient(), LangOpts)
+ ModMap(FileMgr, *Diags.getClient(), LangOpts, Target)
{
AngledDirIdx = 0;
SystemDirIdx = 0;
@@ -365,6 +366,10 @@
return FE;
}
+void HeaderSearch::setTarget(const TargetInfo &Target) {
+ ModMap.setTarget(Target);
+}
+
//===----------------------------------------------------------------------===//
// Header File Location.
Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=149224&r1=149223&r2=149224&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Mon Jan 30 00:01:29 2012
@@ -70,8 +70,8 @@
}
ModuleMap::ModuleMap(FileManager &FileMgr, const DiagnosticConsumer &DC,
- const LangOptions &LangOpts)
- : LangOpts(LangOpts)
+ const LangOptions &LangOpts, const TargetInfo *Target)
+ : LangOpts(LangOpts), Target(Target)
{
llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(new DiagnosticIDs);
Diags = llvm::IntrusiveRefCntPtr<DiagnosticsEngine>(
@@ -90,6 +90,12 @@
delete SourceMgr;
}
+void ModuleMap::setTarget(const TargetInfo &Target) {
+ assert((!this->Target || this->Target == &Target) &&
+ "Improper target override");
+ this->Target = &Target;
+}
+
Module *ModuleMap::findModuleForHeader(const FileEntry *File) {
llvm::DenseMap<const FileEntry *, Module *>::iterator Known
= Headers.find(File);
@@ -992,7 +998,7 @@
consumeToken();
// Add this feature.
- ActiveModule->addRequirement(Feature, Map.LangOpts);
+ ActiveModule->addRequirement(Feature, Map.LangOpts, *Map.Target);
if (!Tok.is(MMToken::Comma))
break;
@@ -1360,6 +1366,7 @@
}
bool ModuleMap::parseModuleMapFile(const FileEntry *File) {
+ assert(Target != 0 && "Missing target information");
FileID ID = SourceMgr->createFileID(File, SourceLocation(), SrcMgr::C_User);
const llvm::MemoryBuffer *Buffer = SourceMgr->getBuffer(ID);
if (!Buffer)
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=149224&r1=149223&r2=149224&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Mon Jan 30 00:01:29 2012
@@ -167,7 +167,9 @@
Ident__exception_info = Ident__exception_code = Ident__abnormal_termination = 0;
Ident___exception_info = Ident___exception_code = Ident___abnormal_termination = 0;
Ident_GetExceptionInfo = Ident_GetExceptionCode = Ident_AbnormalTermination = 0;
- }
+ }
+
+ HeaderInfo.setTarget(Target);
}
void Preprocessor::setPTHManager(PTHManager* pm) {
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=149224&r1=149223&r2=149224&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon Jan 30 00:01:29 2012
@@ -3307,7 +3307,8 @@
break;
CurrentModule->addRequirement(StringRef(BlobStart, BlobLen),
- Context.getLangOptions());
+ Context.getLangOptions(),
+ Context.getTargetInfo());
break;
}
}
Modified: cfe/trunk/unittests/Basic/SourceManagerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/SourceManagerTest.cpp?rev=149224&r1=149223&r2=149224&view=diff
==============================================================================
--- cfe/trunk/unittests/Basic/SourceManagerTest.cpp (original)
+++ cfe/trunk/unittests/Basic/SourceManagerTest.cpp Mon Jan 30 00:01:29 2012
@@ -63,7 +63,7 @@
FileID mainFileID = SourceMgr.createMainFileIDForMemBuffer(buf);
VoidModuleLoader ModLoader;
- HeaderSearch HeaderInfo(FileMgr, Diags, LangOpts);
+ HeaderSearch HeaderInfo(FileMgr, Diags, LangOpts, &*Target);
Preprocessor PP(Diags, LangOpts,
Target.getPtr(),
SourceMgr, HeaderInfo, ModLoader,
@@ -130,7 +130,7 @@
SourceMgr.overrideFileContents(headerFile, headerBuf);
VoidModuleLoader ModLoader;
- HeaderSearch HeaderInfo(FileMgr, Diags, LangOpts);
+ HeaderSearch HeaderInfo(FileMgr, Diags, LangOpts, &*Target);
Preprocessor PP(Diags, LangOpts,
Target.getPtr(),
SourceMgr, HeaderInfo, ModLoader,
Modified: cfe/trunk/unittests/Lex/LexerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/LexerTest.cpp?rev=149224&r1=149223&r2=149224&view=diff
==============================================================================
--- cfe/trunk/unittests/Lex/LexerTest.cpp (original)
+++ cfe/trunk/unittests/Lex/LexerTest.cpp Mon Jan 30 00:01:29 2012
@@ -69,7 +69,7 @@
SourceMgr.createMainFileIDForMemBuffer(buf);
VoidModuleLoader ModLoader;
- HeaderSearch HeaderInfo(FileMgr, Diags, LangOpts);
+ HeaderSearch HeaderInfo(FileMgr, Diags, LangOpts, &*Target);
Preprocessor PP(Diags, LangOpts,
Target.getPtr(),
SourceMgr, HeaderInfo, ModLoader,
More information about the cfe-commits
mailing list