diff gen/structs.cpp @ 102:027b8d8b71ec trunk

[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up. Basically it tries to do the following in order: Resolve types, Declare symbols, Create constant initializers, Apply initializers, Generate functions bodies. ClassInfo is now has the most useful(biased?) members working. Probably other stuf...
author lindquist
date Sun, 18 Nov 2007 06:52:57 +0100
parents 5071469303d4
children 27b9f749d9fe
line wrap: on
line diff
--- a/gen/structs.cpp	Fri Nov 16 10:01:24 2007 +0100
+++ b/gen/structs.cpp	Sun Nov 18 06:52:57 2007 +0100
@@ -96,6 +96,7 @@
         inits.push_back(DUnionIdx(vd->llvmFieldIndex, vd->llvmFieldIndexOffset, v));
     }
 
+    DtoConstInitStruct((StructDeclaration*)si->ad);
     return si->ad->llvmUnion->getConst(inits);
 }
 
@@ -165,12 +166,12 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-void DtoDeclareStruct(StructDeclaration* sd)
+void DtoResolveStruct(StructDeclaration* sd)
 {
-    if (sd->llvmTouched) return;
-    sd->llvmTouched = true;
+    if (sd->llvmResolved) return;
+    sd->llvmResolved = true;
 
-    Logger::println("DtoDeclareStruct(%s)", sd->toChars());
+    Logger::println("DtoResolveStruct(%s)", sd->toChars());
     LOG_SCOPE;
 
     TypeStruct* ts = (TypeStruct*)DtoDType(sd->type);
@@ -280,6 +281,23 @@
         gIR->module->addTypeName(sd->mangle(),structtype);
     }
 
+    gIR->structs.pop_back();
+
+    gIR->declareList.push_back(sd);
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+void DtoDeclareStruct(StructDeclaration* sd)
+{
+    if (sd->llvmDeclared) return;
+    sd->llvmDeclared = true;
+
+    Logger::println("DtoDeclareStruct(%s)", sd->toChars());
+    LOG_SCOPE;
+
+    TypeStruct* ts = (TypeStruct*)DtoDType(sd->type);
+
     std::string initname("_D");
     initname.append(sd->mangle());
     initname.append("6__initZ");
@@ -288,28 +306,22 @@
     llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType->get(), true, _linkage, NULL, initname, gIR->module);
     ts->llvmInit = initvar;
 
-    gIR->structs.pop_back();
-
-    gIR->constInitQueue.push_back(sd);
+    gIR->constInitList.push_back(sd);
     if (sd->getModule() == gIR->dmodule)
-        gIR->defineQueue.push_back(sd);
-
-    // declare typeinfo
-    if (sd->getModule() == gIR->dmodule && sd->llvmInternal != LLVMnotypeinfo)
-        sd->type->getTypeInfo(NULL);
+        gIR->defineList.push_back(sd);
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
 void DtoConstInitStruct(StructDeclaration* sd)
 {
-    IRStruct* irstruct = sd->llvmIRStruct;
-    if (irstruct->constinited) return;
-    irstruct->constinited = true;
+    if (sd->llvmInitialized) return;
+    sd->llvmInitialized = true;
 
     Logger::println("DtoConstInitStruct(%s)", sd->toChars());
     LOG_SCOPE;
 
+    IRStruct* irstruct = sd->llvmIRStruct;
     gIR->structs.push_back(irstruct);
 
     // make sure each offset knows its default initializer
@@ -365,17 +377,18 @@
     }
 
     gIR->structs.pop_back();
+
+    // emit typeinfo
+    if (sd->getModule() == gIR->dmodule && sd->llvmInternal != LLVMnotypeinfo)
+        sd->type->getTypeInfo(NULL);
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
 void DtoDefineStruct(StructDeclaration* sd)
 {
-    IRStruct* irstruct = sd->llvmIRStruct;
-    if (irstruct->defined) return;
-    irstruct->defined = true;
-
-    DtoConstInitStruct(sd);
+    if (sd->llvmDefined) return;
+    sd->llvmDefined = true;
 
     Logger::println("DtoDefineStruct(%s)", sd->toChars());
     LOG_SCOPE;