comparison gen/typinf.cpp @ 758:f04dde6e882c

Added initial D2 support, D2 frontend and changes to codegen to make things compile.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 11 Nov 2008 01:38:48 +0100
parents 6aaa3d3c1183
children fa306ca8843b
comparison
equal deleted inserted replaced
757:2c730d530c98 758:f04dde6e882c
59 //printf("Type::getInternalTypeInfo() %s\n", toChars()); 59 //printf("Type::getInternalTypeInfo() %s\n", toChars());
60 t = toBasetype(); 60 t = toBasetype();
61 switch (t->ty) 61 switch (t->ty)
62 { 62 {
63 case Tsarray: 63 case Tsarray:
64 t = t->next->arrayOf(); // convert to corresponding dynamic array type 64 #if 0
65 // convert to corresponding dynamic array type
66 t = t->nextOf()->mutableOf()->arrayOf();
67 #endif
65 break; 68 break;
66 69
67 case Tclass: 70 case Tclass:
68 if (((TypeClass *)t)->sym->isInterfaceDeclaration()) 71 if (((TypeClass *)t)->sym->isInterfaceDeclaration())
69 break; 72 break;
70 goto Linternal; 73 goto Linternal;
71 74
72 case Tarray: 75 case Tarray:
73 if (t->next->ty != Tclass) 76 #if DMDV2
77 // convert to corresponding dynamic array type
78 t = t->nextOf()->mutableOf()->arrayOf();
79 #endif
80 if (t->nextOf()->ty != Tclass)
74 break; 81 break;
75 goto Linternal; 82 goto Linternal;
76 83
77 case Tfunction: 84 case Tfunction:
78 case Tdelegate: 85 case Tdelegate:
82 if (!tid) 89 if (!tid)
83 { tid = new TypeInfoDeclaration(t, 1); 90 { tid = new TypeInfoDeclaration(t, 1);
84 internalTI[t->ty] = tid; 91 internalTI[t->ty] = tid;
85 } 92 }
86 e = new VarExp(0, tid); 93 e = new VarExp(0, tid);
87 //e = e->addressOf(sc); 94 e = e->addressOf(sc);
88 e->type = tid->type; // do this so we don't get redundant dereference 95 e->type = tid->type; // do this so we don't get redundant dereference
89 return e; 96 return e;
90 97
91 default: 98 default:
92 break; 99 break;
93 } 100 }
94 //printf("\tcalling getTypeInfo() %s\n", t->toChars()); 101 //printf("\tcalling getTypeInfo() %s\n", t->toChars());
95 return t->getTypeInfo(sc); 102 return t->getTypeInfo(sc);
96 } 103 }
97
98 104
99 /**************************************************** 105 /****************************************************
100 * Get the exact TypeInfo. 106 * Get the exact TypeInfo.
101 */ 107 */
102 108
106 Type *t; 112 Type *t;
107 113
108 //printf("Type::getTypeInfo() %p, %s\n", this, toChars()); 114 //printf("Type::getTypeInfo() %p, %s\n", this, toChars());
109 t = merge(); // do this since not all Type's are merge'd 115 t = merge(); // do this since not all Type's are merge'd
110 if (!t->vtinfo) 116 if (!t->vtinfo)
111 { t->vtinfo = t->getTypeInfoDeclaration(); 117 {
118 #if DMDV2
119 if (t->isConst())
120 t->vtinfo = new TypeInfoConstDeclaration(t);
121 else if (t->isInvariant())
122 t->vtinfo = new TypeInfoInvariantDeclaration(t);
123 else
124 #endif
125 t->vtinfo = t->getTypeInfoDeclaration();
112 assert(t->vtinfo); 126 assert(t->vtinfo);
113 127
114 /* If this has a custom implementation in std/typeinfo, then 128 /* If this has a custom implementation in std/typeinfo, then
115 * do not generate a COMDAT for it. 129 * do not generate a COMDAT for it.
116 */ 130 */
474 { 488 {
475 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); 489 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt)));
476 } 490 }
477 else 491 else
478 { 492 {
493 #if DMDV2
494 assert(0 && "initializer not implemented");
495 #else
479 const LLType* memty = DtoType(sd->memtype); 496 const LLType* memty = DtoType(sd->memtype);
480 LLConstant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned()); 497 LLConstant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned());
481 std::string ciname(sd->mangle()); 498 std::string ciname(sd->mangle());
482 ciname.append("__init"); 499 ciname.append("__init");
483 llvm::GlobalVariable* civar = new llvm::GlobalVariable(memty,true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); 500 llvm::GlobalVariable* civar = new llvm::GlobalVariable(memty,true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module);
484 LLConstant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); 501 LLConstant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt);
485 size_t cisize = getTypeStoreSize(memty); 502 size_t cisize = getTypeStoreSize(memty);
486 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); 503 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
504 #endif
487 } 505 }
488 506
489 // create the symbol 507 // create the symbol
490 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); 508 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
491 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); 509 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
759 LOG_SCOPE; 777 LOG_SCOPE;
760 778
761 assert(tinfo->ty == Tdelegate); 779 assert(tinfo->ty == Tdelegate);
762 TypeDelegate *tc = (TypeDelegate *)tinfo; 780 TypeDelegate *tc = (TypeDelegate *)tinfo;
763 781
764 LLVM_D_Define_TypeInfoBase(tc->next->next, this, Type::typeinfodelegate); 782 LLVM_D_Define_TypeInfoBase(tc->nextOf()->nextOf(), this, Type::typeinfodelegate);
765 } 783 }
766 784
767 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt) 785 void TypeInfoDelegateDeclaration::toDt(dt_t **pdt)
768 { 786 {
769 assert(0); 787 assert(0);
960 } 978 }
961 979
962 // uint m_flags; 980 // uint m_flags;
963 sinits.push_back(DtoConstUint(tc->hasPointers())); 981 sinits.push_back(DtoConstUint(tc->hasPointers()));
964 982
983 #if DMDV2
984
985 // const(MemberInfo[]) function(in char[]) xgetMembers;
986 sinits.push_back(LLConstant::getNullValue(stype->getElementType(sinits.size())));
987
988 //void function(void*) xdtor;
989 sinits.push_back(LLConstant::getNullValue(stype->getElementType(sinits.size())));
990
991 //void function(void*) xpostblit;
992 sinits.push_back(LLConstant::getNullValue(stype->getElementType(sinits.size())));
993
994 #endif
995
965 // create the symbol 996 // create the symbol
966 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); 997 LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits);
967 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); 998 isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit);
968 } 999 }
969 1000
1167 1198
1168 void TypeInfoTupleDeclaration::toDt(dt_t **pdt) 1199 void TypeInfoTupleDeclaration::toDt(dt_t **pdt)
1169 { 1200 {
1170 assert(0); 1201 assert(0);
1171 } 1202 }
1203
1204 /* ========================================================================= */
1205
1206 #if DMDV2
1207
1208 void TypeInfoConstDeclaration::llvmDeclare()
1209 {
1210 Logger::println("TypeInfoConstDeclaration::toDt() %s", toChars());
1211 LOG_SCOPE;
1212
1213 LLVM_D_Declare_TypeInfoBase(this, Type::typeinfoconst);
1214 }
1215
1216 void TypeInfoConstDeclaration::llvmDefine()
1217 {
1218 Logger::println("TypeInfoConstDeclaration::toDt() %s", toChars());
1219 LOG_SCOPE;
1220
1221 Type *tm = tinfo->mutableOf();
1222 tm = tm->merge();
1223
1224 LLVM_D_Define_TypeInfoBase(tm, this, Type::typeinfoconst);
1225 }
1226
1227 void TypeInfoConstDeclaration::toDt(dt_t **pdt)
1228 {
1229 assert(0);
1230 }
1231
1232 // void TypeInfoConstDeclaration::toDt(dt_t **pdt)
1233 // {
1234 // //printf("TypeInfoConstDeclaration::toDt() %s\n", toChars());
1235 // dtxoff(pdt, Type::typeinfoconst->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Const
1236 // dtdword(pdt, 0); // monitor
1237 // Type *tm = tinfo->mutableOf();
1238 // tm = tm->merge();
1239 // tm->getTypeInfo(NULL);
1240 // dtxoff(pdt, tm->vtinfo->toSymbol(), 0, TYnptr);
1241 // }
1242
1243 ///////////////////////////////////////////////////////////
1244
1245 /* ========================================================================= */
1246
1247 void TypeInfoInvariantDeclaration::toDt(dt_t **pdt)
1248 {
1249 assert(0 && "TypeInfoInvariantDeclaration::toDt");
1250 }
1251
1252 void TypeInfoInvariantDeclaration::llvmDeclare()
1253 {
1254 assert(0 && "TypeInfoInvariantDeclaration::llvmDeclare");
1255 }
1256
1257 void TypeInfoInvariantDeclaration::llvmDefine()
1258 {
1259 assert(0 && "TypeInfoInvariantDeclaration::llvmDeclare");
1260 }
1261
1262 // void TypeInfoInvariantDeclaration::toDt(dt_t **pdt)
1263 // {
1264 // //printf("TypeInfoInvariantDeclaration::toDt() %s\n", toChars());
1265 // dtxoff(pdt, Type::typeinfoinvariant->toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Invariant
1266 // dtdword(pdt, 0); // monitor
1267 // Type *tm = tinfo->mutableOf();
1268 // tm = tm->merge();
1269 // tm->getTypeInfo(NULL);
1270 // dtxoff(pdt, tm->vtinfo->toSymbol(), 0, TYnptr);
1271 // }
1272
1273 #endif