changeset 1149:5ebe8224988b

Fixed problems introduced by previous commits that prevented Tango from compiling.
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Fri, 27 Mar 2009 23:17:04 +0100
parents 3d1b16dabd25
children 2a687353c84d
files gen/classes.cpp gen/declarations.cpp gen/functions.cpp gen/main.cpp gen/structs.cpp gen/tocall.cpp gen/toir.cpp ir/irstruct.h
diffstat 8 files changed, 63 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/gen/classes.cpp	Fri Mar 27 21:50:32 2009 +0100
+++ b/gen/classes.cpp	Fri Mar 27 23:17:04 2009 +0100
@@ -145,6 +145,19 @@
     IrStruct* irstruct = new IrStruct(cd);
     cd->ir.irStruct = irstruct;
 
+    // create the type
+    const LLType* t = LLArrayType::get(getVoidPtrType(), cd->vtbl.dim);
+    assert(!ts->ir.type);
+    ts->ir.type = new LLPATypeHolder(getPtrToType(t));
+
+    // ... and ClassInfo
+    std::string varname("_D");
+    varname.append(cd->mangle());
+    varname.append("11__InterfaceZ");
+
+    // create global
+    irstruct->classInfo = new llvm::GlobalVariable(irstruct->classInfoOpaque.get(), false, DtoLinkage(cd), NULL, varname, gIR->module);
+
     // handle base interfaces
     if (cd->baseclasses.dim)
     {
@@ -168,11 +181,6 @@
         }
     }
 
-    // create the type
-    const LLType* t = LLArrayType::get(getVoidPtrType(), cd->vtbl.dim);
-    assert(!ts->ir.type);
-    ts->ir.type = new LLPATypeHolder(getPtrToType(t));
-
     // request declaration
     DtoDeclareInterface(cd);
 
@@ -238,10 +246,18 @@
     irstruct->vtbl = new llvm::GlobalVariable(irstruct->vtblInitTy.get(), true, _linkage, NULL, varname, gIR->module);
 
     // ... and initZ
-    std::string initname("_D");
-    initname.append(cd->mangle());
-    initname.append("6__initZ");
-    irstruct->init = new llvm::GlobalVariable(irstruct->initOpaque.get(), true, _linkage, NULL, initname, gIR->module);
+    varname = "_D";
+    varname.append(cd->mangle());
+    varname.append("6__initZ");
+    irstruct->init = new llvm::GlobalVariable(irstruct->initOpaque.get(), true, _linkage, NULL, varname, gIR->module);
+
+    // ... and ClassInfo
+    varname = "_D";
+    varname.append(cd->mangle());
+    varname.append("7__ClassZ");
+
+    // create global
+    irstruct->classInfo = new llvm::GlobalVariable(irstruct->classInfoOpaque.get(), false, _linkage, NULL, varname, gIR->module);
 
     // push state
     gIR->structs.push_back(irstruct);
@@ -778,6 +794,15 @@
     // refine __initZ global type to the one of the initializer
     llvm::cast<llvm::OpaqueType>(irstruct->initOpaque.get())->refineAbstractTypeTo(irstruct->constInit->getType());
 
+    // build initializers for static member variables
+    size_t n = irstruct->staticVars.size();
+    for (size_t i = 0; i < n; ++i)
+    {
+        DtoConstInitGlobal(irstruct->staticVars[i]);
+    }
+    // This is all we use it for. Clear the memory!
+    irstruct->staticVars.clear();
+
 //     if (Logger::enabled())
 //     {
 //         Logger::cout() << "class " << cd->toChars() << std::endl;
@@ -1333,17 +1358,6 @@
     // resovle ClassInfo
     ClassDeclaration* cinfo = ClassDeclaration::classinfo;
     DtoResolveClass(cinfo);
-
-    // do the mangle
-    std::string gname("_D");
-    gname.append(cd->mangle());
-    if (!cd->isInterfaceDeclaration())
-        gname.append("7__ClassZ");
-    else
-        gname.append("11__InterfaceZ");
-
-    // create global
-    irstruct->classInfo = new llvm::GlobalVariable(irstruct->classInfoOpaque.get(), false, DtoLinkage(cd), NULL, gname, gIR->module);
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
--- a/gen/declarations.cpp	Fri Mar 27 21:50:32 2009 +0100
+++ b/gen/declarations.cpp	Fri Mar 27 23:17:04 2009 +0100
@@ -84,6 +84,9 @@
         return;
     }
 
+    if (AggregateDeclaration* ad = isMember())
+        ad->codegen(p);
+
     // global variable or magic
 #if DMDV2
     // taken from dmd2/structs
@@ -135,7 +138,12 @@
         if (nakedUse)
             gIR->usedArray.push_back(DtoBitCast(gvar, getVoidPtrType()));
 
-        DtoConstInitGlobal(this);
+        // don't initialize static struct members yet, they might be of the struct type
+        // which doesn't have a static initializer yet.
+        if (AggregateDeclaration* ad = isMember())
+            ad->ir.irStruct->staticVars.push_back(this);
+        else
+            DtoConstInitGlobal(this);
     }
     else
     {
--- a/gen/functions.cpp	Fri Mar 27 21:50:32 2009 +0100
+++ b/gen/functions.cpp	Fri Mar 27 23:17:04 2009 +0100
@@ -303,16 +303,6 @@
         return; // ignore declaration completely
     }
 
-    // is imported and we don't have access?
-    if (fdecl->getModule() != gIR->dmodule)
-    {
-        if (fdecl->prot() == PROTprivate)
-        {
-            Logger::println("Ignoring private imported function %s", fdecl->toPrettyChars());
-            return;
-        }
-    }
-
     //printf("resolve function: %s\n", fdecl->toPrettyChars());
 
     if (fdecl->parent)
--- a/gen/main.cpp	Fri Mar 27 21:50:32 2009 +0100
+++ b/gen/main.cpp	Fri Mar 27 23:17:04 2009 +0100
@@ -4,11 +4,12 @@
 // which uses the llvm license
 
 #include "gen/llvm.h"
+#include "llvm/LinkAllVMCore.h"
 #include "llvm/Linker.h"
+#include "llvm/System/Signals.h"
 #include "llvm/Target/SubtargetFeature.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetMachineRegistry.h"
-#include "llvm/LinkAllVMCore.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -117,6 +118,9 @@
 
 int main(int argc, char** argv)
 {
+    // stack trace on signals
+    llvm::sys::PrintStackTraceOnErrorSignal();
+
     Array files;
     char *p, *ext;
     Module *m;
--- a/gen/structs.cpp	Fri Mar 27 21:50:32 2009 +0100
+++ b/gen/structs.cpp	Fri Mar 27 23:17:04 2009 +0100
@@ -97,16 +97,7 @@
     TypeStruct* ts = (TypeStruct*)si->ad->type;
 
     // force constant initialization of the symbol
-    si->ad->codegen(Type::sir);;
-
-    // get formal type
-    const llvm::StructType* structtype = isaStruct(ts->ir.type->get());
-
-#if 0
-    // log it
-    if (Logger::enabled())
-        Logger::cout() << "llvm struct type: " << *structtype << '\n';
-#endif
+    si->ad->codegen(Type::sir);
 
     // sanity check
     assert(si->value.dim > 0);
@@ -241,7 +232,7 @@
     }
 
     // there might still be padding after the last one, make sure that is defaulted/zeroed as well
-    size_t structsize = getTypePaddedSize(structtype);
+    size_t structsize = si->ad->structsize;
 
     // if there is space before the next explicit initializer
     // FIXME: this should be handled in the loop above as well
@@ -645,6 +636,15 @@
     // refine __initZ global type to the one of the initializer
     llvm::cast<llvm::OpaqueType>(irstruct->initOpaque.get())->refineAbstractTypeTo(irstruct->constInit->getType());
 
+    // build initializers for static member variables
+    size_t n = irstruct->staticVars.size();
+    for (size_t i = 0; i < n; ++i)
+    {
+        DtoConstInitGlobal(irstruct->staticVars[i]);
+    }
+    // This is all we use it for. Clear the memory!
+    irstruct->staticVars.clear(); 
+
     gIR->structs.pop_back();
 
     // emit typeinfo
--- a/gen/tocall.cpp	Fri Mar 27 21:50:32 2009 +0100
+++ b/gen/tocall.cpp	Fri Mar 27 23:17:04 2009 +0100
@@ -326,7 +326,7 @@
             {
                 ctxarg = gIR->ir->CreateExtractValue(fnval->getRVal(), 0, ".ptr");
             }
-            assert(ctxarg->getType() == argiter->get());
+            ctxarg = DtoBitCast(ctxarg, argiter->get());
             ++argiter;
             args.push_back(ctxarg);
         }
--- a/gen/toir.cpp	Fri Mar 27 21:50:32 2009 +0100
+++ b/gen/toir.cpp	Fri Mar 27 23:17:04 2009 +0100
@@ -969,6 +969,7 @@
         // global variable
         if (VarDeclaration* vd = vexp->var->isVarDeclaration())
         {
+            vd->codegen(Type::sir);
             LLConstant* llc = llvm::dyn_cast<LLConstant>(vd->ir.getIrValue());
             assert(llc);
             return llc;
--- a/ir/irstruct.h	Fri Mar 27 21:50:32 2009 +0100
+++ b/ir/irstruct.h	Fri Mar 27 23:17:04 2009 +0100
@@ -150,6 +150,8 @@
 
     // composite type debug description
     llvm::DICompositeType diCompositeType;
+
+    std::vector<VarDeclaration*> staticVars;
 };
 
 //////////////////////////////////////////////////////////////////////////////