diff --git a/gen/classes.cpp b/gen/classes.cpp index cd5f99b8..080b8b6e 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -39,7 +39,7 @@ static void LLVM_AddBaseClassInterfaces(ClassDeclaration* target, BaseClasses* b if (target->ir.irStruct->interfaceMap.find(bc->base) == target->ir.irStruct->interfaceMap.end()) { Logger::println("adding interface '%s'", bc->base->toPrettyChars()); - IrInterface* iri = new IrInterface(bc, NULL); + IrInterface* iri = new IrInterface(bc); // add to map target->ir.irStruct->interfaceMap.insert(std::make_pair(bc->base, iri)); @@ -242,16 +242,14 @@ void DtoResolveClass(ClassDeclaration* cd) // set vtbl type TypeClass* itc = (TypeClass*)id->type; - const LLType* ivtblTy = getPtrToType(itc->ir.vtblType->get()); - fieldtypes.push_back(ivtblTy); + const LLType* ivtblTy = itc->ir.vtblType->get(); + assert(ivtblTy); + Logger::cout() << "interface vtbl type: " << *ivtblTy << '\n'; + fieldtypes.push_back(getPtrToType(ivtblTy)); // fix the interface vtable type - #if OPAQUE_VTBLS - iri->vtblTy = isaArray(itc->ir.vtblType->get()); - #else - iri->vtblTy = isaStruct(itc->ir.vtblType->get()); - #endif - assert(iri->vtblTy); + assert(iri->vtblTy == NULL); + iri->vtblTy = new llvm::PATypeHolder(ivtblTy); // set index iri->index = interIdx++; @@ -421,7 +419,7 @@ void DtoDeclareClass(ClassDeclaration* cd) nam.append("6__vtblZ"); assert(iri->vtblTy); - iri->vtbl = new llvm::GlobalVariable(iri->vtblTy, true, _linkage, 0, nam, gIR->module); + iri->vtbl = new llvm::GlobalVariable(iri->vtblTy->get(), true, _linkage, 0, nam, gIR->module); LLConstant* idxs[2] = {DtoConstUint(0), DtoConstUint(idx)}; iri->info = llvm::ConstantExpr::getGetElementPtr(irstruct->interfaceInfos, idxs, 2); idx++; diff --git a/ir/irstruct.cpp b/ir/irstruct.cpp index de8c16b5..3d000090 100644 --- a/ir/irstruct.cpp +++ b/ir/irstruct.cpp @@ -4,15 +4,11 @@ #include "ir/irstruct.h" #include "gen/irstate.h" -#if OPAQUE_VTBLS -IrInterface::IrInterface(BaseClass* b, const llvm::ArrayType* vt) -#else -IrInterface::IrInterface(BaseClass* b, const llvm::StructType* vt) -#endif +IrInterface::IrInterface(BaseClass* b) { base = b; decl = b->base; - vtblTy = vt; + vtblTy = NULL; vtblInit = NULL; vtbl = NULL; infoTy = NULL; @@ -24,6 +20,7 @@ IrInterface::IrInterface(BaseClass* b, const llvm::StructType* vt) IrInterface::~IrInterface() { + delete vtblTy; } ////////////////////////////////////////////////////////////////////////////// diff --git a/ir/irstruct.h b/ir/irstruct.h index addbabe4..a3e40d8a 100644 --- a/ir/irstruct.h +++ b/ir/irstruct.h @@ -11,13 +11,8 @@ struct IrInterface : IrBase BaseClass* base; ClassDeclaration* decl; -#if OPAQUE_VTBLS - const LLArrayType* vtblTy; - LLConstantArray* vtblInit; -#else - const LLStructType* vtblTy; - LLConstantStruct* vtblInit; -#endif + llvm::PATypeHolder* vtblTy; + LLConstant* vtblInit; LLGlobalVariable* vtbl; const LLStructType* infoTy; @@ -26,11 +21,7 @@ struct IrInterface : IrBase int index; -#if OPAQUE_VTBLS - IrInterface(BaseClass* b, const LLArrayType* vt); -#else - IrInterface(BaseClass* b, const LLStructType* vt); -#endif + IrInterface(BaseClass* b); ~IrInterface(); };