[cfe-commits] r79366 - /cfe/trunk/lib/CodeGen/CGCXX.cpp

Mike Stump mrs at apple.com
Tue Aug 18 13:50:28 PDT 2009


Author: mrs
Date: Tue Aug 18 15:50:28 2009
New Revision: 79366

URL: http://llvm.org/viewvc/llvm-project?rev=79366&view=rev
Log:
Split out vtable bulding code into a builder.

Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=79366&r1=79365&r2=79366&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Aug 18 15:50:28 2009
@@ -703,22 +703,31 @@
   return Rtti;
 }
 
-void CodeGenFunction::GenerateVcalls(std::vector<llvm::Constant *> &methods,
-                                     const CXXRecordDecl *RD,
-                                     llvm::Type *Ptr8Ty) {
-  typedef CXXRecordDecl::method_iterator meth_iter;
-  llvm::Constant *m;
-
-  // FIXME: audit order
-  for (meth_iter mi = RD->method_begin(),
-         me = RD->method_end(); mi != me; ++mi) {
-    if (mi->isVirtual()) {
-      // FIXME: vcall: offset for virtual base for this function
-      m = llvm::Constant::getNullValue(Ptr8Ty);
-      methods.push_back(m);
+class ABIBuilder {
+  std::vector<llvm::Constant *> &methods;
+  llvm::Type *Ptr8Ty;
+  llvm::LLVMContext &VMContext;
+public:
+  ABIBuilder(llvm::Module &M, std::vector<llvm::Constant *> &meth)
+    : methods(meth), VMContext(M.getContext()) {
+    Ptr8Ty = llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext), 0);
+  }
+  void GenerateVcalls(const CXXRecordDecl *RD) {
+    typedef CXXRecordDecl::method_iterator meth_iter;
+    llvm::Constant *m;
+
+    // FIXME: audit order
+    for (meth_iter mi = RD->method_begin(),
+           me = RD->method_end(); mi != me; ++mi) {
+      if (mi->isVirtual()) {
+        // FIXME: vcall: offset for virtual base for this function
+        m = llvm::Constant::getNullValue(Ptr8Ty);
+        methods.push_back(m);
+      }
     }
   }
-}
+  
+};
 
 void CodeGenFunction::GenerateMethods(std::vector<llvm::Constant *> &methods,
                                       const CXXRecordDecl *RD,
@@ -807,8 +816,9 @@
   }
   
   if (forPrimary || ForVirtualBase) {
+    ABIBuilder b(CGM.getModule(), methods);
     // then comes the the vcall offsets for all our functions...
-    GenerateVcalls(methods, RD, Ptr8Ty);
+    b.GenerateVcalls(RD);
   }
 
   bool Top = true;
@@ -822,10 +832,6 @@
                           PrimaryBaseWasVirtual, IndirectPrimary);
   }
 
-  // then come the vcall offsets for all our virtual bases.
-  if (!1 && ForVirtualBase)
-    GenerateVcalls(methods, RD, Ptr8Ty);
-
   if (Top) {
     int64_t BaseOffset;
     if (ForVirtualBase) {





More information about the cfe-commits mailing list