comparison gen/llvmhelpers.cpp @ 372:83ade4f4025a trunk

[svn r393] Started implementation for DtoNullValue.
author ChristianK
date Tue, 15 Jul 2008 14:53:16 +0200
parents 051ab876fe11
children d1574e142e93
comparison
equal deleted inserted replaced
371:f2b608012699 372:83ade4f4025a
628 } 628 }
629 } 629 }
630 630
631 /****************************************************************************************/ 631 /****************************************************************************************/
632 /*//////////////////////////////////////////////////////////////////////////////////////// 632 /*////////////////////////////////////////////////////////////////////////////////////////
633 // NULL VALUE HELPER
634 ////////////////////////////////////////////////////////////////////////////////////////*/
635
636 DValue* DtoNullValue(Type* type)
637 {
638 Type* basetype = type->toBasetype();
639 TY basety = basetype->ty;
640 const LLType* lltype = DtoType(basetype);
641
642 // complex, needs to be first since complex are also floating
643 if (basetype->iscomplex())
644 {
645 const LLType* basefp = DtoComplexBaseType(basetype);
646 return new DComplexValue(type, LLConstant::getNullValue(basefp), LLConstant::getNullValue(basefp));
647 }
648 // integer, floating, pointer and class have no special representation
649 else if (basetype->isintegral() || basetype->isfloating() || basety == Tpointer || basety == Tclass)
650 {
651 return new DConstValue(type, LLConstant::getNullValue(lltype));
652 }
653 // dynamic array
654 else if (basety == Tarray)
655 {
656 //TODO: What types do the constants here need to have?
657 return new DSliceValue(type, NULL, NULL);
658 }
659 // delegate
660 else if (basety == Tdelegate)
661 {
662 //TODO: Is this correct?
663 return new DNullValue(type, LLConstant::getNullValue(lltype));
664 }
665
666 // unknown
667 std::cout << "unsupported: null value for " << type->toChars() << '\n';
668 assert(0);
669 return 0;
670
671 }
672
673
674 /****************************************************************************************/
675 /*////////////////////////////////////////////////////////////////////////////////////////
633 // CASTING HELPERS 676 // CASTING HELPERS
634 ////////////////////////////////////////////////////////////////////////////////////////*/ 677 ////////////////////////////////////////////////////////////////////////////////////////*/
635 678
636 DValue* DtoCastInt(DValue* val, Type* _to) 679 DValue* DtoCastInt(DValue* val, Type* _to)
637 { 680 {
1333 } 1376 }
1334 } 1377 }
1335 // complex 1378 // complex
1336 else if (dtype->iscomplex()) 1379 else if (dtype->iscomplex())
1337 { 1380 {
1338 // huh? 1381 return DtoComplexEquals(TOKnotequal, dval, DtoNullValue(dtype));
1339 return DtoComplexEquals(TOKnotequal, dval, DtoComplex(dtype, new DNullValue(Type::tint8, llvm::ConstantInt::get(LLType::Int8Ty, 0))));
1340 } 1382 }
1341 // floating point 1383 // floating point
1342 else if (dtype->isfloating()) 1384 else if (dtype->isfloating())
1343 { 1385 {
1344 LLValue* val = dval->getRVal(); 1386 LLValue* val = dval->getRVal();