diff --git a/dmd/mtype.c b/dmd/mtype.c index f778f11e46..e74f6b6cce 100644 --- a/dmd/mtype.c +++ b/dmd/mtype.c @@ -4502,9 +4502,24 @@ L1: e->type = t; // do this so we don't get redundant dereference } else - { /* For class objects, the classinfo reference is the first - * entry in the vtbl[] - */ + { + /* For class objects, the classinfo reference is the first + * entry in the vtbl[] + */ +#if IN_LLVM + + e = e->castTo(sc, t->pointerTo()->pointerTo()); + e = new PtrExp(e->loc, e); + e->type = t->pointerTo(); + e = new PtrExp(e->loc, e); + e->type = t; + if (sym->isInterfaceDeclaration()) + { + assert(0 && "No interfaces yet!"); + } + +#else + e = new PtrExp(e->loc, e); e->type = t->pointerTo(); if (sym->isInterfaceDeclaration()) @@ -4526,6 +4541,8 @@ L1: e->type = t->pointerTo(); } e = new PtrExp(e->loc, e, t); + +#endif } return e; } diff --git a/gen/classes.cpp b/gen/classes.cpp index 99e6b9a510..e30102210b 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -46,6 +46,10 @@ void DtoResolveClass(ClassDeclaration* cd) if (cd->baseClass) { DtoResolveClass(cd->baseClass); } + // resolve typeinfo + //DtoResolveClass(ClassDeclaration::typeinfo); + // resolve classinfo + //DtoResolveClass(ClassDeclaration::classinfo); Logger::println("DtoResolveClass(%s)", cd->toPrettyChars()); LOG_SCOPE; @@ -89,7 +93,10 @@ void DtoResolveClass(ClassDeclaration* cd) llvm::cast(spa.get())->refineAbstractTypeTo(structtype); structtype = isaStruct(spa.get()); - ts->llvmType = new llvm::PATypeHolder(structtype); + if (!ts->llvmType) + ts->llvmType = new llvm::PATypeHolder(structtype); + else + *ts->llvmType = structtype; bool needs_definition = false; if (cd->parent->isModule()) { @@ -118,7 +125,17 @@ void DtoResolveClass(ClassDeclaration* cd) sinits_ty.push_back(fpty); } else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { - const llvm::Type* cty = llvm::PointerType::get(llvm::Type::Int8Ty); + //Logger::println("*** ClassDeclaration in vtable: %s", cd->toChars()); + const llvm::Type* cinfoty; + if (cd != ClassDeclaration::classinfo) { + cd = ClassDeclaration::classinfo; + DtoResolveClass(cd); + cinfoty = cd->type->llvmType->get(); + } + else { + cinfoty = ts->llvmType->get(); + } + const llvm::Type* cty = llvm::PointerType::get(cd->type->llvmType->get()); sinits_ty.push_back(cty); } else @@ -192,6 +209,9 @@ void DtoDeclareClass(ClassDeclaration* cd) gIR->constInitList.push_back(cd); if (needs_definition) gIR->defineList.push_back(cd); + + // classinfo + DtoDeclareClassInfo(cd); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -236,7 +256,7 @@ void DtoConstInitClass(ClassDeclaration* cd) const llvm::StructType* structtype = isaStruct(ts->llvmType->get()); // generate initializer - Logger::cout() << cd->toPrettyChars() << " | " << *structtype << '\n'; + /*Logger::cout() << cd->toPrettyChars() << " | " << *structtype << '\n'; for(size_t i=0; igetNumElements(); ++i) { Logger::cout() << "s#" << i << " = " << *structtype->getElementType(i) << '\n'; @@ -244,7 +264,7 @@ void DtoConstInitClass(ClassDeclaration* cd) for(size_t i=0; i