[cfe-commits] r43159 - /cfe/trunk/Driver/RewriteTest.cpp

Fariborz Jahanian fjahanian at apple.com
Thu Oct 18 17:36:46 PDT 2007


Author: fjahanian
Date: Thu Oct 18 19:36:46 2007
New Revision: 43159

URL: http://llvm.org/viewvc/llvm-project?rev=43159&view=rev
Log:
rewrite of metadata for implemented instance methods.

Modified:
    cfe/trunk/Driver/RewriteTest.cpp

Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=43159&r1=43158&r2=43159&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Thu Oct 18 19:36:46 2007
@@ -133,6 +133,7 @@
 void RewriteTest::WriteObjcClassMetaData(ObjcImplementationDecl *IDecl) {
   ObjcInterfaceDecl *CDecl = IDecl->getClassInterface();
   
+  // Build _objc_ivar_list metadata for classes ivars if needed
   if (IDecl->getImplDeclNumIvars() > 0 || 
       CDecl&& CDecl->getIntfDeclNumIvars() > 0) {
     static bool objc_ivar = false;
@@ -178,6 +179,48 @@
     printf("};\n");
   }
   
+  // Build _objc_method_list for class's instance methods if needed
+  if (IDecl->getNumInstanceMethods() > 0) {
+    int NumMethods = IDecl->getNumInstanceMethods();
+    static bool objc_method = false;
+    if (!objc_method) {
+      /* struct _objc_method {
+           SEL _cmd;
+           char *method_types;
+           void *_imp;
+         }
+      */
+      printf("\nstruct _objc_method {\n");
+      printf("\tSEL _cmd;\n");
+      printf("\tchar *method_types;\n");
+      printf("\tvoid *_imp;\n");
+      printf("};\n");
+      objc_method = true;
+    }
+    /* struct _objc_method_list {
+         struct objc_method_list *next_method;
+         int method_count;
+         struct _objc_method method_list[method_count];
+       }
+    */
+    printf("\nstatic struct {\n");
+    printf("\tstruct objc_method_list *next_method;\n");
+    printf("\tint method_count;\n");
+    printf("\tstruct _objc_method method_list[%d];\n", NumMethods);
+    printf("} _OBJC_INSTANCE_METHODS_%s "
+           "__attribute__ ((section (\"__OBJC, __inst_meth\")))= "
+           "{\n\t0, %d\n", IDecl->getName(), NumMethods);
+    ObjcMethodDecl **Methods = IDecl->getInstanceMethods();
+    for (int i = 0; i < NumMethods; i++)
+      // TODO: 1) method selector name may hav to go into their own section
+      // 2) encode method types for use here (which may have to go into 
+      // __meth_var_types section, 3) Need method address as 3rd initializer.
+      printf("\t,(SEL)\"%s\", \"\", 0\n", 
+             Methods[i]->getSelector().getName().c_str());
+    printf("};\n");
+  }
+  
+  
 }
 
 void RewriteTest::WriteObjcMetaData() {





More information about the cfe-commits mailing list