]> granicus.if.org Git - clang/commitdiff
Add support to module codegen for adding and emitting annotations
authorNate Begeman <natebegeman@mac.com>
Fri, 18 Apr 2008 23:43:57 +0000 (23:43 +0000)
committerNate Begeman <natebegeman@mac.com>
Fri, 18 Apr 2008 23:43:57 +0000 (23:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49944 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/CodeGenModule.h

index cb34fb5a73105e466a38272a76b8cced39406859..a5a51b19c7961ce6bb529e8157a677e02b2ae750 100644 (file)
@@ -44,6 +44,7 @@ CodeGenModule::~CodeGenModule() {
   if (ObjCInitFunction)
     AddGlobalCtor(ObjCInitFunction);
   EmitGlobalCtors();
+  EmitAnnotations();
   delete Runtime;
 }
 
@@ -123,6 +124,22 @@ void CodeGenModule::EmitGlobalCtors() {
 
 
 
+void CodeGenModule::EmitAnnotations() {
+  if (Annotations.empty())
+    return;
+
+  // Create a new global variable for the ConstantStruct in the Module.
+  llvm::Constant *Array =
+  llvm::ConstantArray::get(llvm::ArrayType::get(Annotations[0]->getType(),
+                                                Annotations.size()),
+                           Annotations);
+  llvm::GlobalValue *gv = 
+  new llvm::GlobalVariable(Array->getType(), false,  
+                           llvm::GlobalValue::AppendingLinkage, Array, 
+                           "llvm.global.annotations", &TheModule);
+  gv->setSection("llvm.metadata");
+}
+
 /// ReplaceMapValuesWith - This is a really slow and bad function that
 /// searches for any entries in GlobalDeclMap that point to OldVal, changing
 /// them to point to NewVal.  This is badbadbad, FIXME!
index 3fcb56e3c4fd31959e2af54ec308e14e47ec10d1..e192e9913ee741c950867adc531094900280857d 100644 (file)
@@ -59,6 +59,7 @@ class CodeGenModule {
   llvm::Function *MemSetFn;
   llvm::DenseMap<const Decl*, llvm::Constant*> GlobalDeclMap;
   std::vector<llvm::Constant*> GlobalCtors;
+  std::vector<llvm::Constant*> Annotations;
     
   llvm::StringMap<llvm::Constant*> CFConstantStringMap;
   llvm::StringMap<llvm::Constant*> ConstantStringMap;
@@ -99,6 +100,8 @@ public:
   
   void AddGlobalCtor(llvm::Function * Ctor);
   void EmitGlobalCtors(void);
+  void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); }
+  void EmitAnnotations(void);
 
   void EmitObjCMethod(const ObjCMethodDecl *OMD);
   void EmitFunction(const FunctionDecl *FD);