Add initial support for objc codegen for methods, ivars, and the
etoile runtime, patch by David Chisnall!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48969 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index b5d9db9..8374f2b 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -34,10 +34,16 @@
   : Context(C), Features(LO), TheModule(M), TheTargetData(TD), Diags(diags),
     Types(C, M, TD), MemCpyFn(0), MemSetFn(0), CFConstantStringClassRef(0) {
   //TODO: Make this selectable at runtime
-  Runtime = CreateObjCRuntime(M);
+  Runtime = CreateObjCRuntime(M,
+      getTypes().ConvertType(getContext().IntTy),
+      getTypes().ConvertType(getContext().LongTy));
 }
 
 CodeGenModule::~CodeGenModule() {
+  llvm::Function *ObjCInitFunction = Runtime->ModuleInitFunction();
+  if (ObjCInitFunction) {
+    AddGlobalCtor(ObjCInitFunction);
+  }
   EmitGlobalCtors();
   delete Runtime;
 }
@@ -70,7 +76,10 @@
   GlobalCtors.push_back(Ctor);
 }
 
+/// EmitGlobalCtors - Generates the array of contsturctor functions to be
+/// called on module load, if any have been registered with AddGlobalCtor.
 void CodeGenModule::EmitGlobalCtors() {
+  if (GlobalCtors.empty()) return;
   // Get the type of @llvm.global_ctors
   std::vector<const llvm::Type*> CtorFields;
   CtorFields.push_back(llvm::IntegerType::get(32));
@@ -114,6 +123,8 @@
 
 }
 
+
+
 /// 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!
@@ -263,6 +274,12 @@
 }
 
 
+void CodeGenModule::EmitObjCMethod(const ObjCMethodDecl *OMD) {
+  // If this is not a prototype, emit the body.
+  if (OMD->getBody())
+    CodeGenFunction(*this).GenerateObjCMethod(OMD);
+}
+
 void CodeGenModule::EmitFunction(const FunctionDecl *FD) {
   // If this is not a prototype, emit the body.
   if (FD->getBody())