Mercurial > projects > ldc
comparison gen/classes.cpp @ 363:4d7495038ae8 trunk
[svn r384] Some minor code cleanups.
author | lindquist |
---|---|
date | Mon, 14 Jul 2008 21:49:54 +0200 |
parents | 3c5e19bfcbf2 |
children | 7d91d82000ae |
comparison
equal
deleted
inserted
replaced
362:faa03bf92f0d | 363:4d7495038ae8 |
---|---|
796 // custom allocator | 796 // custom allocator |
797 else if (newexp->allocator) | 797 else if (newexp->allocator) |
798 { | 798 { |
799 DValue* res = DtoCallDFunc(newexp->allocator, newexp->newargs); | 799 DValue* res = DtoCallDFunc(newexp->allocator, newexp->newargs); |
800 mem = DtoBitCast(res->getRVal(), DtoType(tc), "newclass_custom"); | 800 mem = DtoBitCast(res->getRVal(), DtoType(tc), "newclass_custom"); |
801 | |
802 // DtoForceDeclareDsymbol(newexp->allocator); | |
803 // assert(newexp->newargs); | |
804 // assert(newexp->newargs->dim == 1); | |
805 // | |
806 // llvm::Function* fn = newexp->allocator->ir.irFunc->func; | |
807 // assert(fn); | |
808 // DValue* arg = ((Expression*)newexp->newargs->data[0])->toElem(gIR); | |
809 // mem = gIR->CreateCallOrInvoke(fn, arg->getRVal(), "newclass_custom_alloc")->get(); | |
810 // mem = DtoBitCast(mem, DtoType(tc), "newclass_custom"); | |
811 } | 801 } |
812 // default allocator | 802 // default allocator |
813 else | 803 else |
814 { | 804 { |
815 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_newclass"); | 805 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_newclass"); |
1087 unsigned idx = 0; | 1077 unsigned idx = 0; |
1088 unsigned r = LLVM_ClassOffsetToIndex(this, os, idx); | 1078 unsigned r = LLVM_ClassOffsetToIndex(this, os, idx); |
1089 assert(r != (unsigned)-1 && "Offset not found in any aggregate field"); | 1079 assert(r != (unsigned)-1 && "Offset not found in any aggregate field"); |
1090 // vtable is 0, monitor is 1 | 1080 // vtable is 0, monitor is 1 |
1091 r += 2; | 1081 r += 2; |
1092 // interface offset further | |
1093 //r += vtblInterfaces->dim; | |
1094 // the final index was not pushed | 1082 // the final index was not pushed |
1095 result.push_back(r); | 1083 result.push_back(r); |
1096 } | 1084 } |
1097 | 1085 |
1098 ////////////////////////////////////////////////////////////////////////////////////////// | 1086 ////////////////////////////////////////////////////////////////////////////////////////// |
1105 if (idxs.empty()) | 1093 if (idxs.empty()) |
1106 idxs.push_back(0); | 1094 idxs.push_back(0); |
1107 | 1095 |
1108 const LLType* st = DtoType(cd->type); | 1096 const LLType* st = DtoType(cd->type); |
1109 if (ptr->getType() != st) { | 1097 if (ptr->getType() != st) { |
1110 //assert(cd->ir.irStruct->hasUnions); | |
1111 ptr = gIR->ir->CreateBitCast(ptr, st, "tmp"); | 1098 ptr = gIR->ir->CreateBitCast(ptr, st, "tmp"); |
1112 } | 1099 } |
1113 | 1100 |
1114 const LLType* llt = getPtrToType(DtoType(t)); | 1101 const LLType* llt = getPtrToType(DtoType(t)); |
1115 unsigned dataoffset = 2; | 1102 unsigned dataoffset = 2; |
1116 | 1103 |
1117 IrStruct* irstruct = cd->ir.irStruct; | 1104 IrStruct* irstruct = cd->ir.irStruct; |
1118 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) { | 1105 for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) { |
1119 //for (unsigned i=0; i<cd->fields.dim; ++i) { | |
1120 //VarDeclaration* vd = (VarDeclaration*)cd->fields.data[i]; | |
1121 VarDeclaration* vd = i->second.var; | 1106 VarDeclaration* vd = i->second.var; |
1122 assert(vd); | 1107 assert(vd); |
1123 Type* vdtype = DtoDType(vd->type); | 1108 Type* vdtype = DtoDType(vd->type); |
1124 //Logger::println("found %u type %s", vd->offset, vdtype->toChars()); | 1109 //Logger::println("found %u type %s", vd->offset, vdtype->toChars()); |
1125 assert(vd->ir.irField->index >= 0); | 1110 assert(vd->ir.irField->index >= 0); |
1193 #if OPAQUE_VTBLS | 1178 #if OPAQUE_VTBLS |
1194 funcval = DtoBitCast(funcval, getPtrToType(DtoType(fdecl->type))); | 1179 funcval = DtoBitCast(funcval, getPtrToType(DtoType(fdecl->type))); |
1195 Logger::cout() << "funcval casted: " << *funcval << '\n'; | 1180 Logger::cout() << "funcval casted: " << *funcval << '\n'; |
1196 #endif | 1181 #endif |
1197 | 1182 |
1198 //assert(funcval->getType() == DtoType(fdecl->type)); | |
1199 //cc = DtoCallingConv(fdecl->linkage); | |
1200 | |
1201 return funcval; | 1183 return funcval; |
1202 } | 1184 } |
1203 | 1185 |
1204 ////////////////////////////////////////////////////////////////////////////////////////// | 1186 ////////////////////////////////////////////////////////////////////////////////////////// |
1205 | 1187 |