# HG changeset patch # User lindquist # Date 1195959535 -3600 # Node ID 5ba6d286c9410b143ae71ced1567f61ea6bcbb38 # Parent 5880c12dba835458cf52fb55271667d5ec55cae3 [svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero. diff -r 5880c12dba83 -r 5ba6d286c941 gen/classes.cpp --- a/gen/classes.cpp Sun Nov 25 00:19:13 2007 +0100 +++ b/gen/classes.cpp Sun Nov 25 03:58:55 2007 +0100 @@ -85,6 +85,9 @@ std::vector fieldtypes; fieldtypes.push_back(vtabty); + // add monitor + fieldtypes.push_back(llvm::PointerType::get(llvm::Type::Int8Ty)); + // add interface vtables if (cd->vtblInterfaces) for (size_t i = 0; i < cd->vtblInterfaces->dim; i++) @@ -351,6 +354,9 @@ assert(cd->llvmVtbl != 0); fieldinits.push_back(cd->llvmVtbl); + // then comes monitor + fieldinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); + // next comes interface vtables for (IRStruct::InterfaceIter i=irstruct->interfaces.begin(); i!=irstruct->interfaces.end(); ++i) { @@ -426,8 +432,8 @@ cd->llvmConstVtbl = llvm::cast(cvtblInit); // create interface vtable const initalizers - int idx = 1; - int idxScale = (global.params.is64bit) ? 8 : 4; + int idx = 2; + int idxScale = PTRSIZE; for (IRStruct::InterfaceIter i=irstruct->interfaces.begin(); i!=irstruct->interfaces.end(); ++i) { ClassDeclaration* id = i->first; @@ -921,12 +927,13 @@ inits.push_back(c); // monitor - // TODO no monitors yet + c = cinfo->llvmInitZ->getOperand(1); + inits.push_back(c); // byte[] init const llvm::Type* byteptrty = llvm::PointerType::get(llvm::Type::Int8Ty); if (cd->isInterfaceDeclaration()) { - c = cinfo->llvmInitZ->getOperand(1); + c = cinfo->llvmInitZ->getOperand(2); } else { c = llvm::ConstantExpr::getBitCast(cdty->llvmInit, byteptrty); @@ -950,7 +957,7 @@ // vtbl array if (cd->isInterfaceDeclaration()) { - c = cinfo->llvmInitZ->getOperand(3); + c = cinfo->llvmInitZ->getOperand(4); } else { const llvm::Type* byteptrptrty = llvm::PointerType::get(byteptrty); @@ -965,10 +972,10 @@ // interfaces array IRStruct* irstruct = cd->llvmIRStruct; if (cd->isInterfaceDeclaration() || !irstruct->interfaceInfos) { - c = cinfo->llvmInitZ->getOperand(4); + c = cinfo->llvmInitZ->getOperand(5); } else { - const llvm::Type* t = cinfo->llvmInitZ->getOperand(4)->getType()->getContainedType(1); + const llvm::Type* t = cinfo->llvmInitZ->getOperand(5)->getType()->getContainedType(1); c = llvm::ConstantExpr::getBitCast(irstruct->interfaceInfos, t); size_t iisz = irstruct->interfaceInfosTy->getNumElements(); c = DtoConstSlice(DtoConstSize_t(iisz), c); @@ -984,13 +991,13 @@ } else { // null - c = cinfo->llvmInitZ->getOperand(5); + c = cinfo->llvmInitZ->getOperand(6); inits.push_back(c); } // destructor if (cd->isInterfaceDeclaration()) { - c = cinfo->llvmInitZ->getOperand(6); + c = cinfo->llvmInitZ->getOperand(7); } else { c = build_class_dtor(cd); @@ -999,12 +1006,12 @@ // invariant // TODO - c = cinfo->llvmInitZ->getOperand(7); + c = cinfo->llvmInitZ->getOperand(8); inits.push_back(c); // uint flags if (cd->isInterfaceDeclaration()) { - c = cinfo->llvmInitZ->getOperand(8); + c = cinfo->llvmInitZ->getOperand(9); } else { uint flags = build_classinfo_flags(cd); @@ -1014,15 +1021,15 @@ // allocator // TODO - c = cinfo->llvmInitZ->getOperand(9); + c = cinfo->llvmInitZ->getOperand(10); inits.push_back(c); // offset typeinfo if (cd->isInterfaceDeclaration()) { - c = cinfo->llvmInitZ->getOperand(10); + c = cinfo->llvmInitZ->getOperand(11); } else { - c = build_offti_array(cd, cinfo->llvmInitZ->getOperand(10)); + c = build_offti_array(cd, cinfo->llvmInitZ->getOperand(11)); } inits.push_back(c); @@ -1034,7 +1041,7 @@ c = llvm::ConstantExpr::getBitCast(c, llvm::PointerType::get(llvm::Type::Int8Ty)); // toTy); } else { - c = cinfo->llvmInitZ->getOperand(11); + c = cinfo->llvmInitZ->getOperand(12); } inits.push_back(c); diff -r 5880c12dba83 -r 5ba6d286c941 gen/toobj.cpp --- a/gen/toobj.cpp Sun Nov 25 00:19:13 2007 +0100 +++ b/gen/toobj.cpp Sun Nov 25 03:58:55 2007 +0100 @@ -389,8 +389,11 @@ unsigned idx = 0; unsigned r = LLVM_ClassOffsetToIndex(this, os, idx); assert(r != (unsigned)-1 && "Offset not found in any aggregate field"); - r++; // vtable is 0 + // vtable is 0, monitor is 1 + r += 2; + // interface offset further r += vtblInterfaces->dim; + // the final index was not pushed result.push_back(r); } diff -r 5880c12dba83 -r 5ba6d286c941 gen/typinf.cpp --- a/gen/typinf.cpp Sun Nov 25 00:19:13 2007 +0100 +++ b/gen/typinf.cpp Sun Nov 25 03:58:55 2007 +0100 @@ -355,9 +355,13 @@ const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); Logger::cout() << "got stype: " << *stype << '\n'; + // vtbl std::vector sinits; sinits.push_back(base->llvmVtbl); + // monitor + sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); + assert(tinfo->ty == Ttypedef); TypeTypedef *tc = (TypeTypedef *)tinfo; TypedefDeclaration *sd = tc->sym; @@ -376,13 +380,13 @@ assert(sd->basetype->vtinfo->llvmValue); assert(llvm::isa(sd->basetype->vtinfo->llvmValue)); llvm::Constant* castbase = llvm::cast(sd->basetype->vtinfo->llvmValue); - castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); + castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); // char[] name char *name = sd->toPrettyChars(); sinits.push_back(DtoConstString(name)); - assert(sinits.back()->getType() == stype->getElementType(2)); + assert(sinits.back()->getType() == stype->getElementType(3)); // void[] init const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); @@ -437,9 +441,13 @@ const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); + // vtbl std::vector sinits; sinits.push_back(base->llvmVtbl); + // monitor + sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); + assert(tinfo->ty == Tenum); TypeEnum *tc = (TypeEnum *)tinfo; EnumDeclaration *sd = tc->sym; @@ -457,13 +465,13 @@ assert(llvm::isa(sd->memtype->vtinfo->llvmValue)); llvm::Constant* castbase = llvm::cast(sd->memtype->vtinfo->llvmValue); - castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); + castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); // char[] name char *name = sd->toPrettyChars(); sinits.push_back(DtoConstString(name)); - assert(sinits.back()->getType() == stype->getElementType(2)); + assert(sinits.back()->getType() == stype->getElementType(3)); // void[] init const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); @@ -513,9 +521,13 @@ const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); + // vtbl std::vector sinits; sinits.push_back(base->llvmVtbl); + // monitor + sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); + // TypeInfo base Logger::println("generating base typeinfo"); basetype->getTypeInfo(NULL); @@ -524,7 +536,7 @@ DtoForceDeclareDsymbol(basetype->vtinfo); assert(llvm::isa(basetype->vtinfo->llvmValue)); llvm::Constant* castbase = llvm::cast(basetype->vtinfo->llvmValue); - castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); + castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); // create the symbol @@ -625,6 +637,9 @@ // first is always the vtable sinits.push_back(base->llvmVtbl); + // monitor + sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); + // value typeinfo assert(tinfo->ty == Tsarray); TypeSArray *tc = (TypeSArray *)tinfo; @@ -634,7 +649,7 @@ assert(tc->next->vtinfo); DtoForceDeclareDsymbol(tc->next->vtinfo); llvm::Constant* castbase = isaConstant(tc->next->vtinfo->llvmValue); - castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); + castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); // length @@ -685,6 +700,9 @@ // first is always the vtable sinits.push_back(base->llvmVtbl); + // monitor + sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); + // get type assert(tinfo->ty == Taarray); TypeAArray *tc = (TypeAArray *)tinfo; @@ -696,7 +714,7 @@ assert(tc->next->vtinfo); DtoForceDeclareDsymbol(tc->next->vtinfo); llvm::Constant* castbase = isaConstant(tc->next->vtinfo->llvmValue); - castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(1)); + castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); // key typeinfo @@ -706,7 +724,7 @@ assert(tc->index->vtinfo); DtoForceDeclareDsymbol(tc->index->vtinfo); castbase = isaConstant(tc->index->vtinfo->llvmValue); - castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); + castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(3)); sinits.push_back(castbase); // create the symbol @@ -813,14 +831,18 @@ const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); + // vtbl std::vector sinits; sinits.push_back(base->llvmVtbl); + // monitor + sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); + // char[] name char *name = sd->toPrettyChars(); sinits.push_back(DtoConstString(name)); //Logger::println("************** A"); - assert(sinits.back()->getType() == stype->getElementType(1)); + assert(sinits.back()->getType() == stype->getElementType(2)); // void[] init const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); @@ -882,7 +904,8 @@ #endif //Logger::println("************** B"); - const llvm::PointerType* ptty = isaPointer(stype->getElementType(3)); + const llvm::PointerType* ptty = isaPointer(stype->getElementType(4)); + assert(ptty); s = search_function(sd, Id::tohash); fdx = s ? s->isFuncDeclaration() : NULL; @@ -910,7 +933,7 @@ for (int i = 0; i < 2; i++) { //Logger::println("************** C %d", i); - ptty = isaPointer(stype->getElementType(4+i)); + ptty = isaPointer(stype->getElementType(5+i)); if (fdx) { fd = fdx->overloadExactMatch(tfeqptr); @@ -935,7 +958,7 @@ } //Logger::println("************** D"); - ptty = isaPointer(stype->getElementType(6)); + ptty = isaPointer(stype->getElementType(7)); s = search_function(sd, Id::tostring); fdx = s ? s->isFuncDeclaration() : NULL; if (fdx) @@ -1009,6 +1032,9 @@ // first is always the vtable sinits.push_back(base->llvmVtbl); + // monitor + sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); + // get classinfo assert(tinfo->ty == Tclass); TypeClass *tc = (TypeClass *)tinfo; @@ -1062,6 +1088,9 @@ // first is always the vtable sinits.push_back(base->llvmVtbl); + // monitor + sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); + // get classinfo assert(tinfo->ty == Tclass); TypeClass *tc = (TypeClass *)tinfo; @@ -1115,6 +1144,9 @@ // first is always the vtable sinits.push_back(base->llvmVtbl); + // monitor + sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); + // create elements array assert(tinfo->ty == Ttuple); TypeTuple *tu = (TypeTuple *)tinfo;