Mercurial > projects > ldc
comparison gen/toir.cpp @ 364:8014dbd24605 trunk
[svn r385] Fix lvalue cast problems with -= and friends.
Fix complex DtoBoolean.
author | ChristianK |
---|---|
date | Mon, 14 Jul 2008 22:48:03 +0200 |
parents | 4d7495038ae8 |
children | bfb9d28f045a |
comparison
equal
deleted
inserted
replaced
363:4d7495038ae8 | 364:8014dbd24605 |
---|---|
663 else { | 663 else { |
664 res = DtoBinAdd(l,r); | 664 res = DtoBinAdd(l,r); |
665 } | 665 } |
666 DtoAssign(l, res); | 666 DtoAssign(l, res); |
667 | 667 |
668 // might need to return l here if used as an lvalue | |
669 // but when can this ever happen? | |
670 return res; | 668 return res; |
671 } | 669 } |
672 | 670 |
673 ////////////////////////////////////////////////////////////////////////////////////////// | 671 ////////////////////////////////////////////////////////////////////////////////////////// |
674 | 672 |
737 Logger::println("basic"); | 735 Logger::println("basic"); |
738 res = DtoBinSub(l,r); | 736 res = DtoBinSub(l,r); |
739 } | 737 } |
740 DtoAssign(l, res); | 738 DtoAssign(l, res); |
741 | 739 |
742 return l; | 740 return res; |
743 } | 741 } |
744 | 742 |
745 ////////////////////////////////////////////////////////////////////////////////////////// | 743 ////////////////////////////////////////////////////////////////////////////////////////// |
746 | 744 |
747 DValue* MulExp::toElem(IRState* p) | 745 DValue* MulExp::toElem(IRState* p) |
776 else { | 774 else { |
777 res = DtoBinMul(l,r); | 775 res = DtoBinMul(l,r); |
778 } | 776 } |
779 DtoAssign(l, res); | 777 DtoAssign(l, res); |
780 | 778 |
781 return l; | 779 return res; |
782 } | 780 } |
783 | 781 |
784 ////////////////////////////////////////////////////////////////////////////////////////// | 782 ////////////////////////////////////////////////////////////////////////////////////////// |
785 | 783 |
786 DValue* DivExp::toElem(IRState* p) | 784 DValue* DivExp::toElem(IRState* p) |
815 else { | 813 else { |
816 res = DtoBinDiv(l,r); | 814 res = DtoBinDiv(l,r); |
817 } | 815 } |
818 DtoAssign(l, res); | 816 DtoAssign(l, res); |
819 | 817 |
820 return l; | 818 return res; |
821 } | 819 } |
822 | 820 |
823 ////////////////////////////////////////////////////////////////////////////////////////// | 821 ////////////////////////////////////////////////////////////////////////////////////////// |
824 | 822 |
825 DValue* ModExp::toElem(IRState* p) | 823 DValue* ModExp::toElem(IRState* p) |
844 DValue* r = e2->toElem(p); | 842 DValue* r = e2->toElem(p); |
845 | 843 |
846 DValue* res = DtoBinRem(l, r); | 844 DValue* res = DtoBinRem(l, r); |
847 DtoAssign(l, res); | 845 DtoAssign(l, res); |
848 | 846 |
849 return l; | 847 return res; |
850 } | 848 } |
851 | 849 |
852 ////////////////////////////////////////////////////////////////////////////////////////// | 850 ////////////////////////////////////////////////////////////////////////////////////////// |
853 | 851 |
854 // TODO: the method below could really use a cleanup/splitup | 852 // TODO: the method below could really use a cleanup/splitup |
1965 llvm::BasicBlock* oldend = p->scopeend(); | 1963 llvm::BasicBlock* oldend = p->scopeend(); |
1966 llvm::BasicBlock* assertbb = llvm::BasicBlock::Create("assert", p->topfunc(), oldend); | 1964 llvm::BasicBlock* assertbb = llvm::BasicBlock::Create("assert", p->topfunc(), oldend); |
1967 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("noassert", p->topfunc(), oldend); | 1965 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("noassert", p->topfunc(), oldend); |
1968 | 1966 |
1969 // test condition | 1967 // test condition |
1970 LLValue* condval = cond->getRVal(); | 1968 LLValue* condval = DtoBoolean(cond); |
1971 condval = DtoBoolean(condval); | |
1972 | 1969 |
1973 // branch | 1970 // branch |
1974 llvm::BranchInst::Create(endbb, assertbb, condval, p->scopebb()); | 1971 llvm::BranchInst::Create(endbb, assertbb, condval, p->scopebb()); |
1975 | 1972 |
1976 // call assert runtime functions | 1973 // call assert runtime functions |
1995 Logger::print("NotExp::toElem: %s | %s\n", toChars(), type->toChars()); | 1992 Logger::print("NotExp::toElem: %s | %s\n", toChars(), type->toChars()); |
1996 LOG_SCOPE; | 1993 LOG_SCOPE; |
1997 | 1994 |
1998 DValue* u = e1->toElem(p); | 1995 DValue* u = e1->toElem(p); |
1999 | 1996 |
2000 LLValue* b = DtoBoolean(u->getRVal()); | 1997 LLValue* b = DtoBoolean(u); |
2001 | 1998 |
2002 LLConstant* zero = llvm::ConstantInt::get(LLType::Int1Ty, 0, true); | 1999 LLConstant* zero = llvm::ConstantInt::get(LLType::Int1Ty, 0, true); |
2003 b = p->ir->CreateICmpEQ(b,zero); | 2000 b = p->ir->CreateICmpEQ(b,zero); |
2004 | 2001 |
2005 return new DImValue(type, b); | 2002 return new DImValue(type, b); |
2021 | 2018 |
2022 llvm::BasicBlock* oldend = p->scopeend(); | 2019 llvm::BasicBlock* oldend = p->scopeend(); |
2023 llvm::BasicBlock* andand = llvm::BasicBlock::Create("andand", gIR->topfunc(), oldend); | 2020 llvm::BasicBlock* andand = llvm::BasicBlock::Create("andand", gIR->topfunc(), oldend); |
2024 llvm::BasicBlock* andandend = llvm::BasicBlock::Create("andandend", gIR->topfunc(), oldend); | 2021 llvm::BasicBlock* andandend = llvm::BasicBlock::Create("andandend", gIR->topfunc(), oldend); |
2025 | 2022 |
2026 LLValue* ubool = DtoBoolean(u->getRVal()); | 2023 LLValue* ubool = DtoBoolean(u); |
2027 DtoStore(ubool,resval); | 2024 DtoStore(ubool,resval); |
2028 llvm::BranchInst::Create(andand,andandend,ubool,p->scopebb()); | 2025 llvm::BranchInst::Create(andand,andandend,ubool,p->scopebb()); |
2029 | 2026 |
2030 p->scope() = IRScope(andand, andandend); | 2027 p->scope() = IRScope(andand, andandend); |
2031 DValue* v = e2->toElem(p); | 2028 DValue* v = e2->toElem(p); |
2032 | 2029 |
2033 LLValue* vbool = DtoBoolean(v->getRVal()); | 2030 LLValue* vbool = DtoBoolean(v); |
2034 LLValue* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); | 2031 LLValue* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); |
2035 DtoStore(uandvbool,resval); | 2032 DtoStore(uandvbool,resval); |
2036 llvm::BranchInst::Create(andandend,p->scopebb()); | 2033 llvm::BranchInst::Create(andandend,p->scopebb()); |
2037 | 2034 |
2038 p->scope() = IRScope(andandend, oldend); | 2035 p->scope() = IRScope(andandend, oldend); |
2057 | 2054 |
2058 llvm::BasicBlock* oldend = p->scopeend(); | 2055 llvm::BasicBlock* oldend = p->scopeend(); |
2059 llvm::BasicBlock* oror = llvm::BasicBlock::Create("oror", gIR->topfunc(), oldend); | 2056 llvm::BasicBlock* oror = llvm::BasicBlock::Create("oror", gIR->topfunc(), oldend); |
2060 llvm::BasicBlock* ororend = llvm::BasicBlock::Create("ororend", gIR->topfunc(), oldend); | 2057 llvm::BasicBlock* ororend = llvm::BasicBlock::Create("ororend", gIR->topfunc(), oldend); |
2061 | 2058 |
2062 LLValue* ubool = DtoBoolean(u->getRVal()); | 2059 LLValue* ubool = DtoBoolean(u); |
2063 DtoStore(ubool,resval); | 2060 DtoStore(ubool,resval); |
2064 llvm::BranchInst::Create(ororend,oror,ubool,p->scopebb()); | 2061 llvm::BranchInst::Create(ororend,oror,ubool,p->scopebb()); |
2065 | 2062 |
2066 p->scope() = IRScope(oror, ororend); | 2063 p->scope() = IRScope(oror, ororend); |
2067 DValue* v = e2->toElem(p); | 2064 DValue* v = e2->toElem(p); |
2068 | 2065 |
2069 LLValue* vbool = DtoBoolean(v->getRVal()); | 2066 LLValue* vbool = DtoBoolean(v); |
2070 DtoStore(vbool,resval); | 2067 DtoStore(vbool,resval); |
2071 llvm::BranchInst::Create(ororend,p->scopebb()); | 2068 llvm::BranchInst::Create(ororend,p->scopebb()); |
2072 | 2069 |
2073 p->scope() = IRScope(ororend, oldend); | 2070 p->scope() = IRScope(ororend, oldend); |
2074 | 2071 |
2319 llvm::BasicBlock* condtrue = llvm::BasicBlock::Create("condtrue", gIR->topfunc(), oldend); | 2316 llvm::BasicBlock* condtrue = llvm::BasicBlock::Create("condtrue", gIR->topfunc(), oldend); |
2320 llvm::BasicBlock* condfalse = llvm::BasicBlock::Create("condfalse", gIR->topfunc(), oldend); | 2317 llvm::BasicBlock* condfalse = llvm::BasicBlock::Create("condfalse", gIR->topfunc(), oldend); |
2321 llvm::BasicBlock* condend = llvm::BasicBlock::Create("condend", gIR->topfunc(), oldend); | 2318 llvm::BasicBlock* condend = llvm::BasicBlock::Create("condend", gIR->topfunc(), oldend); |
2322 | 2319 |
2323 DValue* c = econd->toElem(p); | 2320 DValue* c = econd->toElem(p); |
2324 LLValue* cond_val = DtoBoolean(c->getRVal()); | 2321 LLValue* cond_val = DtoBoolean(c); |
2325 llvm::BranchInst::Create(condtrue,condfalse,cond_val,p->scopebb()); | 2322 llvm::BranchInst::Create(condtrue,condfalse,cond_val,p->scopebb()); |
2326 | 2323 |
2327 p->scope() = IRScope(condtrue, condfalse); | 2324 p->scope() = IRScope(condtrue, condfalse); |
2328 DValue* u = e1->toElem(p); | 2325 DValue* u = e1->toElem(p); |
2329 DtoAssign(dvv, u); | 2326 DtoAssign(dvv, u); |