comparison gen/classes.cpp @ 115:5ba6d286c941 trunk

[svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
author lindquist
date Sun, 25 Nov 2007 03:58:55 +0100
parents 5880c12dba83
children 56a21f3e5d3e
comparison
equal deleted inserted replaced
114:5880c12dba83 115:5ba6d286c941
82 ts->llvmVtblType = new llvm::PATypeHolder(llvm::OpaqueType::get()); 82 ts->llvmVtblType = new llvm::PATypeHolder(llvm::OpaqueType::get());
83 const llvm::Type* vtabty = llvm::PointerType::get(ts->llvmVtblType->get()); 83 const llvm::Type* vtabty = llvm::PointerType::get(ts->llvmVtblType->get());
84 84
85 std::vector<const llvm::Type*> fieldtypes; 85 std::vector<const llvm::Type*> fieldtypes;
86 fieldtypes.push_back(vtabty); 86 fieldtypes.push_back(vtabty);
87
88 // add monitor
89 fieldtypes.push_back(llvm::PointerType::get(llvm::Type::Int8Ty));
87 90
88 // add interface vtables 91 // add interface vtables
89 if (cd->vtblInterfaces) 92 if (cd->vtblInterfaces)
90 for (size_t i = 0; i < cd->vtblInterfaces->dim; i++) 93 for (size_t i = 0; i < cd->vtblInterfaces->dim; i++)
91 { 94 {
349 352
350 // first field is always the vtable 353 // first field is always the vtable
351 assert(cd->llvmVtbl != 0); 354 assert(cd->llvmVtbl != 0);
352 fieldinits.push_back(cd->llvmVtbl); 355 fieldinits.push_back(cd->llvmVtbl);
353 356
357 // then comes monitor
358 fieldinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty)));
359
354 // next comes interface vtables 360 // next comes interface vtables
355 for (IRStruct::InterfaceIter i=irstruct->interfaces.begin(); i!=irstruct->interfaces.end(); ++i) 361 for (IRStruct::InterfaceIter i=irstruct->interfaces.begin(); i!=irstruct->interfaces.end(); ++i)
356 { 362 {
357 IRInterface* iri = i->second; 363 IRInterface* iri = i->second;
358 assert(iri->vtbl); 364 assert(iri->vtbl);
424 430
425 llvm::Constant* cvtblInit = llvm::ConstantStruct::get(svtbl_ty, sinits); 431 llvm::Constant* cvtblInit = llvm::ConstantStruct::get(svtbl_ty, sinits);
426 cd->llvmConstVtbl = llvm::cast<llvm::ConstantStruct>(cvtblInit); 432 cd->llvmConstVtbl = llvm::cast<llvm::ConstantStruct>(cvtblInit);
427 433
428 // create interface vtable const initalizers 434 // create interface vtable const initalizers
429 int idx = 1; 435 int idx = 2;
430 int idxScale = (global.params.is64bit) ? 8 : 4; 436 int idxScale = PTRSIZE;
431 for (IRStruct::InterfaceIter i=irstruct->interfaces.begin(); i!=irstruct->interfaces.end(); ++i) 437 for (IRStruct::InterfaceIter i=irstruct->interfaces.begin(); i!=irstruct->interfaces.end(); ++i)
432 { 438 {
433 ClassDeclaration* id = i->first; 439 ClassDeclaration* id = i->first;
434 assert(id->type->ty == Tclass); 440 assert(id->type->ty == Tclass);
435 TypeClass* its = (TypeClass*)id->type; 441 TypeClass* its = (TypeClass*)id->type;
919 c = cinfo->llvmInitZ->getOperand(0); 925 c = cinfo->llvmInitZ->getOperand(0);
920 assert(c); 926 assert(c);
921 inits.push_back(c); 927 inits.push_back(c);
922 928
923 // monitor 929 // monitor
924 // TODO no monitors yet 930 c = cinfo->llvmInitZ->getOperand(1);
931 inits.push_back(c);
925 932
926 // byte[] init 933 // byte[] init
927 const llvm::Type* byteptrty = llvm::PointerType::get(llvm::Type::Int8Ty); 934 const llvm::Type* byteptrty = llvm::PointerType::get(llvm::Type::Int8Ty);
928 if (cd->isInterfaceDeclaration()) { 935 if (cd->isInterfaceDeclaration()) {
929 c = cinfo->llvmInitZ->getOperand(1); 936 c = cinfo->llvmInitZ->getOperand(2);
930 } 937 }
931 else { 938 else {
932 c = llvm::ConstantExpr::getBitCast(cdty->llvmInit, byteptrty); 939 c = llvm::ConstantExpr::getBitCast(cdty->llvmInit, byteptrty);
933 assert(!cd->llvmInitZ->getType()->isAbstract()); 940 assert(!cd->llvmInitZ->getType()->isAbstract());
934 size_t initsz = gTargetData->getTypeSize(cd->llvmInitZ->getType()); 941 size_t initsz = gTargetData->getTypeSize(cd->llvmInitZ->getType());
948 c = DtoConstString(name); 955 c = DtoConstString(name);
949 inits.push_back(c); 956 inits.push_back(c);
950 957
951 // vtbl array 958 // vtbl array
952 if (cd->isInterfaceDeclaration()) { 959 if (cd->isInterfaceDeclaration()) {
953 c = cinfo->llvmInitZ->getOperand(3); 960 c = cinfo->llvmInitZ->getOperand(4);
954 } 961 }
955 else { 962 else {
956 const llvm::Type* byteptrptrty = llvm::PointerType::get(byteptrty); 963 const llvm::Type* byteptrptrty = llvm::PointerType::get(byteptrty);
957 assert(!cd->llvmVtbl->getType()->isAbstract()); 964 assert(!cd->llvmVtbl->getType()->isAbstract());
958 c = llvm::ConstantExpr::getBitCast(cd->llvmVtbl, byteptrptrty); 965 c = llvm::ConstantExpr::getBitCast(cd->llvmVtbl, byteptrptrty);
963 inits.push_back(c); 970 inits.push_back(c);
964 971
965 // interfaces array 972 // interfaces array
966 IRStruct* irstruct = cd->llvmIRStruct; 973 IRStruct* irstruct = cd->llvmIRStruct;
967 if (cd->isInterfaceDeclaration() || !irstruct->interfaceInfos) { 974 if (cd->isInterfaceDeclaration() || !irstruct->interfaceInfos) {
968 c = cinfo->llvmInitZ->getOperand(4); 975 c = cinfo->llvmInitZ->getOperand(5);
969 } 976 }
970 else { 977 else {
971 const llvm::Type* t = cinfo->llvmInitZ->getOperand(4)->getType()->getContainedType(1); 978 const llvm::Type* t = cinfo->llvmInitZ->getOperand(5)->getType()->getContainedType(1);
972 c = llvm::ConstantExpr::getBitCast(irstruct->interfaceInfos, t); 979 c = llvm::ConstantExpr::getBitCast(irstruct->interfaceInfos, t);
973 size_t iisz = irstruct->interfaceInfosTy->getNumElements(); 980 size_t iisz = irstruct->interfaceInfosTy->getNumElements();
974 c = DtoConstSlice(DtoConstSize_t(iisz), c); 981 c = DtoConstSlice(DtoConstSize_t(iisz), c);
975 } 982 }
976 inits.push_back(c); 983 inits.push_back(c);
982 assert(c); 989 assert(c);
983 inits.push_back(c); 990 inits.push_back(c);
984 } 991 }
985 else { 992 else {
986 // null 993 // null
987 c = cinfo->llvmInitZ->getOperand(5); 994 c = cinfo->llvmInitZ->getOperand(6);
988 inits.push_back(c); 995 inits.push_back(c);
989 } 996 }
990 997
991 // destructor 998 // destructor
992 if (cd->isInterfaceDeclaration()) { 999 if (cd->isInterfaceDeclaration()) {
993 c = cinfo->llvmInitZ->getOperand(6); 1000 c = cinfo->llvmInitZ->getOperand(7);
994 } 1001 }
995 else { 1002 else {
996 c = build_class_dtor(cd); 1003 c = build_class_dtor(cd);
997 } 1004 }
998 inits.push_back(c); 1005 inits.push_back(c);
999 1006
1000 // invariant 1007 // invariant
1001 // TODO 1008 // TODO
1002 c = cinfo->llvmInitZ->getOperand(7); 1009 c = cinfo->llvmInitZ->getOperand(8);
1003 inits.push_back(c); 1010 inits.push_back(c);
1004 1011
1005 // uint flags 1012 // uint flags
1006 if (cd->isInterfaceDeclaration()) { 1013 if (cd->isInterfaceDeclaration()) {
1007 c = cinfo->llvmInitZ->getOperand(8); 1014 c = cinfo->llvmInitZ->getOperand(9);
1008 } 1015 }
1009 else { 1016 else {
1010 uint flags = build_classinfo_flags(cd); 1017 uint flags = build_classinfo_flags(cd);
1011 c = DtoConstUint(flags); 1018 c = DtoConstUint(flags);
1012 } 1019 }
1013 inits.push_back(c); 1020 inits.push_back(c);
1014 1021
1015 // allocator 1022 // allocator
1016 // TODO 1023 // TODO
1017 c = cinfo->llvmInitZ->getOperand(9); 1024 c = cinfo->llvmInitZ->getOperand(10);
1018 inits.push_back(c); 1025 inits.push_back(c);
1019 1026
1020 // offset typeinfo 1027 // offset typeinfo
1021 if (cd->isInterfaceDeclaration()) { 1028 if (cd->isInterfaceDeclaration()) {
1022 c = cinfo->llvmInitZ->getOperand(10); 1029 c = cinfo->llvmInitZ->getOperand(11);
1023 } 1030 }
1024 else { 1031 else {
1025 c = build_offti_array(cd, cinfo->llvmInitZ->getOperand(10)); 1032 c = build_offti_array(cd, cinfo->llvmInitZ->getOperand(11));
1026 } 1033 }
1027 inits.push_back(c); 1034 inits.push_back(c);
1028 1035
1029 // default constructor 1036 // default constructor
1030 if (cd->defaultCtor && !cd->isInterfaceDeclaration()) { 1037 if (cd->defaultCtor && !cd->isInterfaceDeclaration()) {
1032 c = isaConstant(cd->defaultCtor->llvmValue); 1039 c = isaConstant(cd->defaultCtor->llvmValue);
1033 //const llvm::Type* toTy = cinfo->llvmInitZ->getOperand(11)->getType(); 1040 //const llvm::Type* toTy = cinfo->llvmInitZ->getOperand(11)->getType();
1034 c = llvm::ConstantExpr::getBitCast(c, llvm::PointerType::get(llvm::Type::Int8Ty)); // toTy); 1041 c = llvm::ConstantExpr::getBitCast(c, llvm::PointerType::get(llvm::Type::Int8Ty)); // toTy);
1035 } 1042 }
1036 else { 1043 else {
1037 c = cinfo->llvmInitZ->getOperand(11); 1044 c = cinfo->llvmInitZ->getOperand(12);
1038 } 1045 }
1039 inits.push_back(c); 1046 inits.push_back(c);
1040 1047
1041 /*size_t n = inits.size(); 1048 /*size_t n = inits.size();
1042 for (size_t i=0; i<n; ++i) 1049 for (size_t i=0; i<n; ++i)