comparison gen/classes.cpp @ 328:7086a84ab3d6 trunk

[svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length. Fixed issues with DMD generated assert statements when using class invariants, generally due to incomplete ASTs. Removed some dead code. Added a few comments.
author lindquist
date Fri, 11 Jul 2008 00:17:00 +0200
parents 781af50846b2
children aaade6ded589
comparison
equal deleted inserted replaced
327:781af50846b2 328:7086a84ab3d6
1334 return DtoConstSlice(size, ptr); 1334 return DtoConstSlice(size, ptr);
1335 } 1335 }
1336 1336
1337 static LLConstant* build_class_dtor(ClassDeclaration* cd) 1337 static LLConstant* build_class_dtor(ClassDeclaration* cd)
1338 { 1338 {
1339 #if 0
1340 // construct the function
1341 std::vector<const LLType*> paramTypes;
1342 paramTypes.push_back(getPtrToType(cd->type->ir.type->get()));
1343
1344 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy, paramTypes, false);
1345
1346 if (cd->dtors.dim == 0) {
1347 return llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty));
1348 }
1349 else if (cd->dtors.dim == 1) {
1350 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[0];
1351 DtoForceDeclareDsymbol(d);
1352 assert(d->ir.irFunc->func);
1353 return llvm::ConstantExpr::getBitCast(isaConstant(d->ir.irFunc->func), getPtrToType(LLType::Int8Ty));
1354 }
1355
1356 std::string gname("_D");
1357 gname.append(cd->mangle());
1358 gname.append("12__destructorMFZv");
1359
1360 llvm::Function* func = llvm::Function::Create(fnTy, DtoInternalLinkage(cd), gname, gIR->module);
1361 LLValue* thisptr = func->arg_begin();
1362 thisptr->setName("this");
1363
1364 llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", func);
1365 IRBuilder builder(bb);
1366
1367 for (size_t i = 0; i < cd->dtors.dim; i++)
1368 {
1369 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[i];
1370 DtoForceDeclareDsymbol(d);
1371 assert(d->ir.irFunc->func);
1372 gIR->CreateCallOrInvoke(d->ir.irFunc->func, thisptr);
1373 }
1374 builder.CreateRetVoid();
1375
1376 return llvm::ConstantExpr::getBitCast(func, getPtrToType(LLType::Int8Ty));
1377 #else
1378
1379 FuncDeclaration* dtor = cd->dtor; 1339 FuncDeclaration* dtor = cd->dtor;
1380 1340
1381 // if no destructor emit a null 1341 // if no destructor emit a null
1382 if (!dtor) 1342 if (!dtor)
1383 return getNullPtr(getVoidPtrType()); 1343 return getNullPtr(getVoidPtrType());
1384 1344
1385 DtoForceDeclareDsymbol(dtor); 1345 DtoForceDeclareDsymbol(dtor);
1386 return llvm::ConstantExpr::getBitCast(dtor->ir.irFunc->func, getPtrToType(LLType::Int8Ty)); 1346 return llvm::ConstantExpr::getBitCast(dtor->ir.irFunc->func, getPtrToType(LLType::Int8Ty));
1387 #endif
1388 } 1347 }
1389 1348
1390 static unsigned build_classinfo_flags(ClassDeclaration* cd) 1349 static unsigned build_classinfo_flags(ClassDeclaration* cd)
1391 { 1350 {
1392 // adapted from original dmd code 1351 // adapted from original dmd code
1554 1513
1555 // invariant 1514 // invariant
1556 if (cd->inv) { 1515 if (cd->inv) {
1557 DtoForceDeclareDsymbol(cd->inv); 1516 DtoForceDeclareDsymbol(cd->inv);
1558 c = cd->inv->ir.irFunc->func; 1517 c = cd->inv->ir.irFunc->func;
1559 // c = llvm::ConstantExpr::getBitCast(c, defc->getOperand(8)->getType()); 1518 c = llvm::ConstantExpr::getBitCast(c, defc->getOperand(8)->getType());
1560 } 1519 }
1561 else { 1520 else {
1562 c = defc->getOperand(8); 1521 c = defc->getOperand(8);
1563 } 1522 }
1564 inits.push_back(c); 1523 inits.push_back(c);