mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-17 05:13:14 +01:00
[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
This commit is contained in:
@@ -85,6 +85,9 @@ void DtoResolveClass(ClassDeclaration* cd)
|
||||
std::vector<const llvm::Type*> 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 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
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 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
||||
cd->llvmConstVtbl = llvm::cast<llvm::ConstantStruct>(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 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||
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 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||
|
||||
// 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 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||
// 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 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||
}
|
||||
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 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||
|
||||
// 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 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||
|
||||
// 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 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
|
||||
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);
|
||||
|
||||
|
||||
@@ -389,8 +389,11 @@ void ClassDeclaration::offsetToIndex(Type* t, unsigned os, std::vector<unsigned>
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -355,9 +355,13 @@ void TypeInfoTypedefDeclaration::llvmDefine()
|
||||
const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
|
||||
Logger::cout() << "got stype: " << *stype << '\n';
|
||||
|
||||
// vtbl
|
||||
std::vector<llvm::Constant*> 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 @@ void TypeInfoTypedefDeclaration::llvmDefine()
|
||||
assert(sd->basetype->vtinfo->llvmValue);
|
||||
assert(llvm::isa<llvm::Constant>(sd->basetype->vtinfo->llvmValue));
|
||||
llvm::Constant* castbase = llvm::cast<llvm::Constant>(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 @@ void TypeInfoEnumDeclaration::llvmDefine()
|
||||
|
||||
const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
|
||||
|
||||
// vtbl
|
||||
std::vector<llvm::Constant*> 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 @@ void TypeInfoEnumDeclaration::llvmDefine()
|
||||
|
||||
assert(llvm::isa<llvm::Constant>(sd->memtype->vtinfo->llvmValue));
|
||||
llvm::Constant* castbase = llvm::cast<llvm::Constant>(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 @@ static llvm::Constant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclar
|
||||
|
||||
const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
|
||||
|
||||
// vtbl
|
||||
std::vector<llvm::Constant*> 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 @@ static llvm::Constant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclar
|
||||
DtoForceDeclareDsymbol(basetype->vtinfo);
|
||||
assert(llvm::isa<llvm::Constant>(basetype->vtinfo->llvmValue));
|
||||
llvm::Constant* castbase = llvm::cast<llvm::Constant>(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 @@ void TypeInfoStaticArrayDeclaration::llvmDefine()
|
||||
// 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 @@ void TypeInfoStaticArrayDeclaration::llvmDefine()
|
||||
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 @@ void TypeInfoAssociativeArrayDeclaration::llvmDefine()
|
||||
// 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 @@ void TypeInfoAssociativeArrayDeclaration::llvmDefine()
|
||||
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 @@ void TypeInfoAssociativeArrayDeclaration::llvmDefine()
|
||||
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 @@ void TypeInfoStructDeclaration::llvmDefine()
|
||||
|
||||
const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get());
|
||||
|
||||
// vtbl
|
||||
std::vector<llvm::Constant*> 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 @@ void TypeInfoStructDeclaration::llvmDefine()
|
||||
#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 @@ void TypeInfoStructDeclaration::llvmDefine()
|
||||
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 @@ void TypeInfoStructDeclaration::llvmDefine()
|
||||
}
|
||||
|
||||
//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 @@ void TypeInfoClassDeclaration::llvmDefine()
|
||||
// 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 @@ void TypeInfoInterfaceDeclaration::llvmDefine()
|
||||
// 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 @@ void TypeInfoTupleDeclaration::llvmDefine()
|
||||
// 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;
|
||||
|
||||
Reference in New Issue
Block a user