summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2013-01-14 17:21:00 +0000
committerDouglas Gregor <dgregor@apple.com>2013-01-14 17:21:00 +0000
commit6ddfca91e04e62089d685b31533b9a2d677d9a5e (patch)
treeb803eaa1d88091fd5b65134468b8e922c1deb773 /clang/lib/CodeGen/CodeGenModule.cpp
parent3778f27b2302c69ce1d9d4af70aab60143fd5b54 (diff)
downloadbcm5719-llvm-6ddfca91e04e62089d685b31533b9a2d677d9a5e.tar.gz
bcm5719-llvm-6ddfca91e04e62089d685b31533b9a2d677d9a5e.zip
Implement parsing, AST, (de-)serialization, and placeholder global
metadata for linking against the libraries/frameworks for imported modules. The module map language is extended with a new "link" directive that specifies what library or framework to link against when a module is imported, e.g., link "clangAST" or link framework "MyFramework" Importing the corresponding module (or any of its submodules) will eventually link against the named library/framework. For now, I've added some placeholder global metadata that encodes the imported libraries/frameworks, so that we can test that this information gets through to the IR. The format of the data is still under discussion. llvm-svn: 172437
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp70
1 files changed, 68 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 0257ce23f61..da37e4982d4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -32,6 +32,7 @@
#include "clang/Basic/Builtins.h"
#include "clang/Basic/ConvertUTF.h"
#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/Module.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/CodeGenOptions.h"
@@ -172,7 +173,8 @@ void CodeGenModule::Release() {
EmitCtorList(GlobalDtors, "llvm.global_dtors");
EmitGlobalAnnotations();
EmitLLVMUsed();
-
+ EmitLinkLibraries();
+
SimplifyPersonality();
if (getCodeGenOpts().EmitDeclMetadata)
@@ -714,6 +716,24 @@ void CodeGenModule::EmitLLVMUsed() {
GV->setSection("llvm.metadata");
}
+void CodeGenModule::EmitLinkLibraries() {
+ // If there are no libraries to link against, do nothing.
+ if (LinkLibraries.empty())
+ return;
+
+ // Create metadata for each library we're linking against.
+ llvm::NamedMDNode *Metadata
+ = getModule().getOrInsertNamedMetadata("llvm.link.libraries");
+ for (unsigned I = 0, N = LinkLibraries.size(); I != N; ++I) {
+ llvm::Value *Args[2] = {
+ llvm::MDString::get(getLLVMContext(), LinkLibraries[I].Library),
+ llvm::ConstantInt::get(llvm::Type::getInt1Ty(getLLVMContext()),
+ LinkLibraries[I].IsFramework)
+ };
+ Metadata->addOperand(llvm::MDNode::get(getLLVMContext(), Args));
+ }
+}
+
void CodeGenModule::EmitDeferred() {
// Emit code for any potentially referenced deferred decls. Since a
// previously unused static decl may become used during the generation of code
@@ -2681,7 +2701,6 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
case Decl::TypeAliasTemplate:
case Decl::NamespaceAlias:
case Decl::Block:
- case Decl::Import:
break;
case Decl::CXXConstructor:
// Skip function templates
@@ -2762,6 +2781,53 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
break;
}
+ case Decl::Import: {
+ ImportDecl *Import = cast<ImportDecl>(D);
+
+ // Ignore import declarations that come from imported modules.
+ if (clang::Module *Owner = Import->getOwningModule()) {
+ if (getLangOpts().CurrentModule.empty() ||
+ Owner->getTopLevelModule()->Name == getLangOpts().CurrentModule)
+ break;
+ }
+
+ // Walk from this module up to its top-level module; we'll import all of
+ // these modules and their non-explicit child modules.
+ llvm::SmallVector<clang::Module *, 2> Stack;
+ for (clang::Module *Mod = Import->getImportedModule(); Mod;
+ Mod = Mod->Parent) {
+ if (!ImportedModules.insert(Mod))
+ break;
+
+ Stack.push_back(Mod);
+ }
+
+ // Find all of the non-explicit submodules of the modules we've imported and
+ // import them.
+ while (!Stack.empty()) {
+ clang::Module *Mod = Stack.back();
+ Stack.pop_back();
+
+ // Add the link libraries for this module.
+ LinkLibraries.insert(LinkLibraries.end(),
+ Mod->LinkLibraries.begin(),
+ Mod->LinkLibraries.end());
+
+ // We've imported this module; now import any of its children that haven't
+ // already been imported.
+ for (clang::Module::submodule_iterator Sub = Mod->submodule_begin(),
+ SubEnd = Mod->submodule_end();
+ Sub != SubEnd; ++Sub) {
+ if ((*Sub)->IsExplicit)
+ continue;
+
+ if (ImportedModules.insert(*Sub))
+ Stack.push_back(*Sub);
+ }
+ }
+ break;
+ }
+
default:
// Make sure we handled everything we should, every other kind is a
// non-top-level decl. FIXME: Would be nice to have an isTopLevelDeclKind
OpenPOWER on IntegriCloud