comparison gen/llvmhelpers.cpp @ 803:c62c6936635b

Removed DtoConstFieldInitializer, it's no longer needed and was buggy.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sat, 29 Nov 2008 21:26:50 +0100
parents 92ea3015ace6
children 6c2ff06c4201
comparison
equal deleted inserted replaced
802:28ce72c60a21 803:c62c6936635b
1426 return _init; 1426 return _init;
1427 } 1427 }
1428 1428
1429 ////////////////////////////////////////////////////////////////////////////////////////// 1429 //////////////////////////////////////////////////////////////////////////////////////////
1430 1430
1431 LLConstant* DtoConstFieldInitializer(Loc loc, Type* t, Initializer* init)
1432 {
1433 Logger::println("DtoConstFieldInitializer");
1434 LOG_SCOPE;
1435
1436 const LLType* _type = DtoType(t);
1437
1438 LLConstant* _init = DtoConstInitializer(loc, t, init);
1439 assert(_init);
1440 if (_type != _init->getType())
1441 {
1442 if (Logger::enabled())
1443 Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n';
1444 if (t->ty == Tsarray)
1445 {
1446 const LLArrayType* arrty = isaArray(_type);
1447 uint64_t n = arrty->getNumElements();
1448 std::vector<LLConstant*> vals(n,_init);
1449 _init = llvm::ConstantArray::get(arrty, vals);
1450 }
1451 else if (t->ty == Tarray)
1452 {
1453 assert(isaStruct(_type));
1454 _init = llvm::ConstantAggregateZero::get(_type);
1455 }
1456 else if (t->ty == Tstruct)
1457 {
1458 const LLStructType* structty = isaStruct(_type);
1459 TypeStruct* ts = (TypeStruct*)t;
1460 assert(ts);
1461 assert(ts->sym);
1462 assert(ts->sym->ir.irStruct->constInit);
1463 _init = ts->sym->ir.irStruct->constInit;
1464 }
1465 else if (t->ty == Tclass)
1466 {
1467 _init = llvm::Constant::getNullValue(_type);
1468 }
1469 else {
1470 Logger::println("failed for type %s", t->toChars());
1471 assert(0);
1472 }
1473 }
1474
1475 return _init;
1476 }
1477
1478 //////////////////////////////////////////////////////////////////////////////////////////
1479
1480 DValue* DtoInitializer(LLValue* target, Initializer* init) 1431 DValue* DtoInitializer(LLValue* target, Initializer* init)
1481 { 1432 {
1482 if (!init) 1433 if (!init)
1483 return 0; 1434 return 0;
1484 else if (ExpInitializer* ex = init->isExpInitializer()) 1435 else if (ExpInitializer* ex = init->isExpInitializer())
1535 Type* expbase = exp->type->toBasetype(); 1486 Type* expbase = exp->type->toBasetype();
1536 Logger::println("expbase: %s", expbase->toChars()); 1487 Logger::println("expbase: %s", expbase->toChars());
1537 Type* t = base->toBasetype(); 1488 Type* t = base->toBasetype();
1538 1489
1539 LLSmallVector<size_t, 4> dims; 1490 LLSmallVector<size_t, 4> dims;
1540
1541 // handle zero initializers
1542 if (expbase->isintegral() && exp->isConst())
1543 {
1544 if (!exp->toInteger())
1545 return LLConstant::getNullValue(dstTy);
1546 }
1547 else if (exp->op == TOKnull)
1548 {
1549 return LLConstant::getNullValue(dstTy);
1550 }
1551 1491
1552 while(1) 1492 while(1)
1553 { 1493 {
1554 Logger::println("t: %s", t->toChars()); 1494 Logger::println("t: %s", t->toChars());
1555 if (t->equals(expbase)) 1495 if (t->equals(expbase))