Changeset 778:4adf0f742896
- Timestamp:
- 11/22/08 12:35:52 (2 months ago)
- Files:
-
- gen/arrays.cpp (modified) (1 diff)
- gen/classes.cpp (modified) (2 diffs)
- gen/complex.cpp (modified) (1 diff)
- gen/llvmhelpers.cpp (modified) (6 diffs)
- gen/llvmhelpers.h (modified) (1 diff)
- gen/statements.cpp (modified) (4 diffs)
- gen/toir.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gen/arrays.cpp
r758 r778 946 946 assert(0); 947 947 } 948 else if (totype->ty == Tbool) { 949 // return (arr.ptr !is null) 950 LLValue* ptr = DtoArrayPtr(u); 951 LLConstant* nul = getNullPtr(ptr->getType()); 952 rval = gIR->ir->CreateICmpNE(ptr, nul, "tmp"); 953 } 948 954 else { 949 955 assert(0); gen/classes.cpp
r758 r778 925 925 Type* to = _to->toBasetype(); 926 926 if (to->ty == Tpointer) { 927 Logger::println("to pointer"); 927 928 const LLType* tolltype = DtoType(_to); 928 929 LLValue* rval = DtoBitCast(val->getRVal(), tolltype); 929 930 return new DImValue(_to, rval); 931 } 932 else if (to->ty == Tbool) { 933 Logger::println("to bool"); 934 LLValue* llval = val->getRVal(); 935 LLValue* zero = LLConstant::getNullValue(llval->getType()); 936 return new DImValue(_to, gIR->ir->CreateICmpNE(llval, zero, "tmp")); 930 937 } 931 938 … … 948 955 } 949 956 else { 950 Logger::println("to object");957 Logger::println("to class"); 951 958 int poffset; 952 959 if (fc->sym->isInterfaceDeclaration()) { gen/complex.cpp
r741 r778 455 455 return DtoCastFloat(loc, re, to); 456 456 } 457 else if (to->ty == Tbool) { 458 return new DImValue(_to, DtoComplexEquals(loc, TOKnotequal, val, DtoNullValue(vty))); 459 } 457 460 else 458 461 assert(0); gen/llvmhelpers.cpp
r773 r778 570 570 } 571 571 572 if (to->isintegral()) { 572 if (to->ty == Tbool) { 573 LLValue* zero = LLConstantInt::get(rval->getType(), 0, false); 574 rval = gIR->ir->CreateICmpNE(rval, zero, "tmp"); 575 } 576 else if (to->isintegral()) { 573 577 if (fromsz < tosz || from->ty == Tbool) { 574 578 if (Logger::enabled()) … … 580 584 } 581 585 } 582 else if (fromsz > tosz || to->ty == Tbool) {586 else if (fromsz > tosz) { 583 587 rval = new llvm::TruncInst(rval, tolltype, "tmp", gIR->scopebb()); 584 588 } … … 627 631 rval = DtoBitCast(src, tolltype); 628 632 } 633 else if (totype->ty == Tbool) { 634 LLValue* src = val->getRVal(); 635 LLValue* zero = LLConstant::getNullValue(src->getType()); 636 rval = gIR->ir->CreateICmpNE(src, zero, "tmp"); 637 } 629 638 else if (totype->isintegral()) { 630 639 rval = new llvm::PtrToIntInst(val->getRVal(), tolltype, "tmp", gIR->scopebb()); … … 654 663 LLValue* rval; 655 664 656 if (totype->iscomplex()) { 665 if (totype->ty == Tbool) { 666 rval = val->getRVal(); 667 LLValue* zero = LLConstant::getNullValue(rval->getType()); 668 rval = gIR->ir->CreateFCmpONE(rval, zero, "tmp"); 669 } 670 else if (totype->iscomplex()) { 657 671 return DtoComplex(loc, to, val); 658 672 } … … 694 708 { 695 709 return DtoPaintType(loc, val, to); 710 } 711 else if (to->toBasetype()->ty == Tbool) 712 { 713 return new DImValue(to, DtoDelegateEquals(TOKnotequal, val->getRVal(), NULL)); 696 714 } 697 715 else … … 1615 1633 ////////////////////////////////////////////////////////////////////////////////////////// 1616 1634 1617 LLValue* DtoBoolean(Loc& loc, DValue* dval)1618 {1619 Type* dtype = dval->getType()->toBasetype();1620 TY ty = dtype->ty;1621 1622 // integer1623 if (dtype->isintegral())1624 {1625 LLValue* val = dval->getRVal();1626 if (val->getType() == LLType::Int1Ty)1627 return val;1628 else {1629 LLValue* zero = LLConstantInt::get(val->getType(), 0, false);1630 return gIR->ir->CreateICmpNE(val, zero, "tmp");1631 }1632 }1633 // complex1634 else if (dtype->iscomplex())1635 {1636 return DtoComplexEquals(loc, TOKnotequal, dval, DtoNullValue(dtype));1637 }1638 // floating point1639 else if (dtype->isfloating())1640 {1641 LLValue* val = dval->getRVal();1642 LLValue* zero = LLConstant::getNullValue(val->getType());1643 return gIR->ir->CreateFCmpONE(val, zero, "tmp");1644 }1645 // pointer/class1646 else if (ty == Tpointer || ty == Tclass) {1647 LLValue* val = dval->getRVal();1648 LLValue* zero = LLConstant::getNullValue(val->getType());1649 if (Logger::enabled())1650 {1651 Logger::cout() << "val: " << *val << '\n';1652 Logger::cout() << "zero: " << *zero << '\n';1653 }1654 return gIR->ir->CreateICmpNE(val, zero, "tmp");1655 }1656 // dynamic array1657 else if (ty == Tarray)1658 {1659 // return (arr.ptr !is null)1660 LLValue* ptr = DtoArrayPtr(dval);1661 LLConstant* nul = getNullPtr(ptr->getType());1662 return gIR->ir->CreateICmpNE(ptr, nul, "tmp");1663 }1664 // delegate1665 else if (ty == Tdelegate)1666 {1667 // return (dg !is null)1668 return DtoDelegateEquals(TOKnotequal, dval->getRVal(), NULL);1669 }1670 // unknown1671 std::cout << "unsupported -> bool : " << dtype->toChars() << '\n';1672 assert(0);1673 return 0;1674 }1675 1676 //////////////////////////////////////////////////////////////////////////////////////////1677 1678 1635 void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, std::string& name) 1679 1636 { gen/llvmhelpers.h
r747 r778 109 109 void findDefaultTarget(); 110 110 111 /// Converts any value to a boolean (llvm i1)112 LLValue* DtoBoolean(Loc& loc, DValue* dval);113 114 111 /// get the default initializer of the type 115 112 LLConstant* DtoDefaultInit(Type* t); gen/statements.cpp
r774 r778 169 169 if (Logger::enabled()) 170 170 Logger::cout() << "if conditional: " << *cond_val << '\n'; 171 cond_val = Dto Boolean(loc, cond_e);171 cond_val = DtoCast(loc, cond_e, Type::tbool)->getRVal(); 172 172 } 173 173 LLValue* ifgoback = llvm::BranchInst::Create(ifbb, elsebb, cond_val, gIR->scopebb()); … … 257 257 // create the condition 258 258 DValue* cond_e = condition->toElem(p); 259 LLValue* cond_val = Dto Boolean(loc, cond_e);259 LLValue* cond_val = DtoCast(loc, cond_e, Type::tbool)->getRVal(); 260 260 delete cond_e; 261 261 … … 313 313 // create the condition 314 314 DValue* cond_e = condition->toElem(p); 315 LLValue* cond_val = Dto Boolean(loc, cond_e);315 LLValue* cond_val = DtoCast(loc, cond_e, Type::tbool)->getRVal(); 316 316 delete cond_e; 317 317 … … 358 358 { 359 359 DValue* cond_e = condition->toElem(p); 360 cond_val = Dto Boolean(loc, cond_e);360 cond_val = DtoCast(loc, cond_e, Type::tbool)->getRVal(); 361 361 delete cond_e; 362 362 } gen/toir.cpp
r770 r778 1650 1650 1651 1651 // test condition 1652 LLValue* condval = Dto Boolean(loc, cond);1652 LLValue* condval = DtoCast(loc, cond, Type::tbool)->getRVal(); 1653 1653 1654 1654 // branch … … 1676 1676 DValue* u = e1->toElem(p); 1677 1677 1678 LLValue* b = Dto Boolean(loc, u);1678 LLValue* b = DtoCast(loc, u, Type::tbool)->getRVal(); 1679 1679 1680 1680 LLConstant* zero = DtoConstBool(false); … … 1702 1702 llvm::BasicBlock* andandend = llvm::BasicBlock::Create("andandend", gIR->topfunc(), oldend); 1703 1703 1704 LLValue* ubool = Dto Boolean(loc, u);1704 LLValue* ubool = DtoCast(loc, u, Type::tbool)->getRVal(); 1705 1705 DtoStore(ubool,resval); 1706 1706 llvm::BranchInst::Create(andand,andandend,ubool,p->scopebb()); … … 1709 1709 DValue* v = e2->toElem(p); 1710 1710 1711 LLValue* vbool = Dto Boolean(loc, v);1711 LLValue* vbool = DtoCast(loc, v, Type::tbool)->getRVal(); 1712 1712 LLValue* uandvbool = llvm::BinaryOperator::Create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); 1713 1713 DtoStore(uandvbool,resval); … … 1738 1738 llvm::BasicBlock* ororend = llvm::BasicBlock::Create("ororend", gIR->topfunc(), oldend); 1739 1739 1740 LLValue* ubool = Dto Boolean(loc, u);1740 LLValue* ubool = DtoCast(loc, u, Type::tbool)->getRVal(); 1741 1741 DtoStore(ubool,resval); 1742 1742 llvm::BranchInst::Create(ororend,oror,ubool,p->scopebb()); … … 1745 1745 DValue* v = e2->toElem(p); 1746 1746 1747 LLValue* vbool = Dto Boolean(loc, v);1747 LLValue* vbool = DtoCast(loc, v, Type::tbool)->getRVal(); 1748 1748 DtoStore(vbool,resval); 1749 1749 llvm::BranchInst::Create(ororend,p->scopebb()); … … 2000 2000 2001 2001 DValue* c = econd->toElem(p); 2002 LLValue* cond_val = Dto Boolean(loc, c);2002 LLValue* cond_val = DtoCast(loc, c, Type::tbool)->getRVal(); 2003 2003 llvm::BranchInst::Create(condtrue,condfalse,cond_val,p->scopebb()); 2004 2004 … … 2421 2421 DValue* BoolExp::toElem(IRState* p) 2422 2422 { 2423 return new DImValue(type, Dto Boolean(loc, e1->toElem(p)));2423 return new DImValue(type, DtoCast(loc, e1->toElem(p), Type::tbool)->getRVal()); 2424 2424 } 2425 2425

