diff gen/tollvm.c @ 6:35d93ce68cf4 trunk

[svn r10] Updated for LLVM rev. 20070913 Applied fixes from wilsonk on the forum Some tweaks to work with gc 7.0 Fixed aggregate members of aggregates Fixed cyclic/recursive class declarations Other minor tweaks
author lindquist
date Wed, 26 Sep 2007 19:05:18 +0200
parents e116aa1488e6
children 5e69b77a5c51
line wrap: on
line diff
--- a/gen/tollvm.c	Wed Sep 05 07:16:31 2007 +0200
+++ b/gen/tollvm.c	Wed Sep 26 19:05:18 2007 +0200
@@ -99,15 +99,23 @@
     case Tclass:    {
         if (t->llvmType == 0)
         {
+            // recursive or cyclic declaration
+            if (!gIR->structs.empty())
+            {
+                IRStruct* found = 0;
+                for (IRState::StructVector::iterator i=gIR->structs.begin(); i!=gIR->structs.end(); ++i)
+                {
+                    if (t == i->type)
+                    {
+                        return llvm::PointerType::get(i->recty.get());
+                    }
+                }
+            }
+
+            // forward declaration
             TypeClass* tc = (TypeClass*)t;
             assert(tc->sym);
-            if (!tc->sym->llvmInProgress) {
-                tc->sym->toObjFile();
-            }
-            else {
-                //assert(0 && "circular class referencing");
-                return llvm::OpaqueType::get();
-            }
+            tc->sym->toObjFile();
         }
         return llvm::PointerType::get(t->llvmType);
     }
@@ -122,7 +130,7 @@
             return t->llvmType;
         }
     }
-    
+
     // delegates
     case Tdelegate:
     {
@@ -803,3 +811,11 @@
     }
     return _init;
 }
+
+llvm::Value* LLVM_DtoGEP(llvm::Value* ptr, llvm::Value* i0, llvm::Value* i1, const std::string& var, llvm::BasicBlock* bb)
+{
+    std::vector<llvm::Value*> v(2);
+    v[0] = i0;
+    v[1] = i1;
+    return new llvm::GetElementPtrInst(ptr, v.begin(), v.end(), var, bb);
+}