From be3bfbff5d3509f64eb67b21b29a37fa2957c005 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Fri, 27 Mar 2009 23:17:04 +0100 Subject: [PATCH] Fixed problems introduced by previous commits that prevented Tango from compiling. --- gen/classes.cpp | 54 ++++++++++++++++++++++++++++---------------- gen/declarations.cpp | 10 +++++++- gen/functions.cpp | 10 -------- gen/main.cpp | 6 ++++- gen/structs.cpp | 22 +++++++++--------- gen/tocall.cpp | 2 +- gen/toir.cpp | 1 + ir/irstruct.h | 2 ++ 8 files changed, 63 insertions(+), 44 deletions(-) diff --git a/gen/classes.cpp b/gen/classes.cpp index 602a9a6a..376dbdaf 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -145,6 +145,19 @@ static void DtoResolveInterface(InterfaceDeclaration* cd) 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 @@ static void DtoResolveInterface(InterfaceDeclaration* cd) } } - // 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 @@ void DtoResolveClass(ClassDeclaration* cd) 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 @@ void DtoConstInitClass(ClassDeclaration* cd) // refine __initZ global type to the one of the initializer llvm::cast(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 @@ void DtoDeclareClassInfo(ClassDeclaration* cd) // 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); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/declarations.cpp b/gen/declarations.cpp index 3749c4c6..617b50e3 100644 --- a/gen/declarations.cpp +++ b/gen/declarations.cpp @@ -84,6 +84,9 @@ void VarDeclaration::codegen(Ir* p) return; } + if (AggregateDeclaration* ad = isMember()) + ad->codegen(p); + // global variable or magic #if DMDV2 // taken from dmd2/structs @@ -135,7 +138,12 @@ void VarDeclaration::codegen(Ir* p) 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 { diff --git a/gen/functions.cpp b/gen/functions.cpp index 08229495..9c6395d4 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -303,16 +303,6 @@ void DtoResolveFunction(FuncDeclaration* fdecl) 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) diff --git a/gen/main.cpp b/gen/main.cpp index 98c16f7e..f5bd31f3 100644 --- a/gen/main.cpp +++ b/gen/main.cpp @@ -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 #include @@ -117,6 +118,9 @@ static void initFromString(char*& dest, const cl::opt& src) { int main(int argc, char** argv) { + // stack trace on signals + llvm::sys::PrintStackTraceOnErrorSignal(); + Array files; char *p, *ext; Module *m; diff --git a/gen/structs.cpp b/gen/structs.cpp index 91df1599..b8fdc9d5 100644 --- a/gen/structs.cpp +++ b/gen/structs.cpp @@ -97,16 +97,7 @@ LLConstant* DtoConstStructInitializer(StructInitializer* si) 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 @@ Lpadding: } // 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 @@ void DtoConstInitStruct(StructDeclaration* sd) // refine __initZ global type to the one of the initializer llvm::cast(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 diff --git a/gen/tocall.cpp b/gen/tocall.cpp index f783efcc..f13c044f 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -326,7 +326,7 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* { ctxarg = gIR->ir->CreateExtractValue(fnval->getRVal(), 0, ".ptr"); } - assert(ctxarg->getType() == argiter->get()); + ctxarg = DtoBitCast(ctxarg, argiter->get()); ++argiter; args.push_back(ctxarg); } diff --git a/gen/toir.cpp b/gen/toir.cpp index c2adefe4..3e4ad2d2 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -969,6 +969,7 @@ LLConstant* AddrExp::toConstElem(IRState* p) // global variable if (VarDeclaration* vd = vexp->var->isVarDeclaration()) { + vd->codegen(Type::sir); LLConstant* llc = llvm::dyn_cast(vd->ir.getIrValue()); assert(llc); return llc; diff --git a/ir/irstruct.h b/ir/irstruct.h index 7730076b..1744a56b 100644 --- a/ir/irstruct.h +++ b/ir/irstruct.h @@ -150,6 +150,8 @@ struct IrStruct : IrBase // composite type debug description llvm::DICompositeType diCompositeType; + + std::vector staticVars; }; //////////////////////////////////////////////////////////////////////////////