diff gen/structs.cpp @ 1148:3d1b16dabd25

Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Fri, 27 Mar 2009 21:50:32 +0100
parents dbe4af57b240
children 5ebe8224988b
line wrap: on
line diff
--- a/gen/structs.cpp	Fri Mar 27 17:54:27 2009 +0100
+++ b/gen/structs.cpp	Fri Mar 27 21:50:32 2009 +0100
@@ -97,7 +97,7 @@
     TypeStruct* ts = (TypeStruct*)si->ad->type;
 
     // force constant initialization of the symbol
-    DtoForceConstInitDsymbol(si->ad);
+    si->ad->codegen(Type::sir);;
 
     // get formal type
     const llvm::StructType* structtype = isaStruct(ts->ir.type->get());
@@ -517,6 +517,15 @@
     // create the type
     ts->ir.type = new LLPATypeHolder(llvm::OpaqueType::get());
 
+    // create symbols we're going to need
+    // avoids chicken egg problems
+    std::string initname("_D");
+    initname.append(sd->mangle());
+    initname.append("6__initZ");
+
+    llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(sd);
+    sd->ir.irStruct->init = new llvm::GlobalVariable(sd->ir.irStruct->initOpaque.get(), true, _linkage, NULL, initname, gIR->module);
+
     // handle forward declaration structs (opaques)
     // didn't even know D had those ...
     if (sd->sizeok != 1)
@@ -579,13 +588,15 @@
 
     gIR->structs.pop_back();
 
-    gIR->declareList.push_back(sd);
+    DtoDeclareStruct(sd);
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
 void DtoDeclareStruct(StructDeclaration* sd)
 {
+    DtoResolveStruct(sd);
+
     if (sd->ir.declared) return;
     sd->ir.declared = true;
 
@@ -594,23 +605,17 @@
 
     TypeStruct* ts = (TypeStruct*)sd->type->toBasetype();
 
-    std::string initname("_D");
-    initname.append(sd->mangle());
-    initname.append("6__initZ");
-
-    llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(sd);
-    llvm::GlobalVariable* initvar = new llvm::GlobalVariable(sd->ir.irStruct->initOpaque.get(), true, _linkage, NULL, initname, gIR->module);
-    sd->ir.irStruct->init = initvar;
-
-    gIR->constInitList.push_back(sd);
+    DtoConstInitStruct(sd);
     if (mustDefineSymbol(sd))
-        gIR->defineList.push_back(sd);
+        DtoDefineStruct(sd);
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
 void DtoConstInitStruct(StructDeclaration* sd)
 {
+    DtoDeclareStruct(sd);
+
     if (sd->ir.initialized) return;
     sd->ir.initialized = true;
 
@@ -651,6 +656,8 @@
 
 void DtoDefineStruct(StructDeclaration* sd)
 {
+    DtoConstInitStruct(sd);
+
     if (sd->ir.defined) return;
     sd->ir.defined = true;