Mercurial > projects > ldc
comparison gen/toir.cpp @ 1211:50dc0db06238
Merge
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Sun, 12 Apr 2009 22:22:15 +0200 |
parents | 83d3b25c2213 7c7072437a89 |
children | 837f48560863 79758fd2f48a |
comparison
equal
deleted
inserted
replaced
1210:3d4581761b4c | 1211:50dc0db06238 |
---|---|
594 | 594 |
595 #undef BIN_ASSIGN | 595 #undef BIN_ASSIGN |
596 | 596 |
597 ////////////////////////////////////////////////////////////////////////////////////////// | 597 ////////////////////////////////////////////////////////////////////////////////////////// |
598 | 598 |
599 static void errorOnIllegalArrayOp(Expression* base, Expression* e1, Expression* e2) | |
600 { | |
601 Type* t1 = e1->type->toBasetype(); | |
602 Type* t2 = e2->type->toBasetype(); | |
603 | |
604 // valid array ops would have been transformed by optimize | |
605 if ((t1->ty == Tarray || t1->ty == Tsarray) && | |
606 (t2->ty == Tarray || t2->ty == Tsarray) | |
607 ) | |
608 { | |
609 error("Array operation %s not recognized", base->toChars()); | |
610 fatal(); | |
611 } | |
612 } | |
613 | |
614 ////////////////////////////////////////////////////////////////////////////////////////// | |
615 | |
599 DValue* AddExp::toElem(IRState* p) | 616 DValue* AddExp::toElem(IRState* p) |
600 { | 617 { |
601 Logger::print("AddExp::toElem: %s @ %s\n", toChars(), type->toChars()); | 618 Logger::print("AddExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
602 LOG_SCOPE; | 619 LOG_SCOPE; |
603 | 620 |
606 | 623 |
607 Type* t = type->toBasetype(); | 624 Type* t = type->toBasetype(); |
608 Type* e1type = e1->type->toBasetype(); | 625 Type* e1type = e1->type->toBasetype(); |
609 Type* e1next = e1type->nextOf() ? e1type->nextOf()->toBasetype() : NULL; | 626 Type* e1next = e1type->nextOf() ? e1type->nextOf()->toBasetype() : NULL; |
610 Type* e2type = e2->type->toBasetype(); | 627 Type* e2type = e2->type->toBasetype(); |
628 | |
629 errorOnIllegalArrayOp(this, e1, e2); | |
611 | 630 |
612 if (e1type != e2type) { | 631 if (e1type != e2type) { |
613 if (e1type->ty == Tpointer) { | 632 if (e1type->ty == Tpointer) { |
614 Logger::println("add to pointer"); | 633 Logger::println("add to pointer"); |
615 if (DConstValue* cv = r->isConst()) { | 634 if (DConstValue* cv = r->isConst()) { |
646 | 665 |
647 Type* t = type->toBasetype(); | 666 Type* t = type->toBasetype(); |
648 Type* t1 = e1->type->toBasetype(); | 667 Type* t1 = e1->type->toBasetype(); |
649 Type* t2 = e2->type->toBasetype(); | 668 Type* t2 = e2->type->toBasetype(); |
650 | 669 |
670 errorOnIllegalArrayOp(this, e1, e2); | |
671 | |
651 if (t1->ty == Tpointer && t2->ty == Tpointer) { | 672 if (t1->ty == Tpointer && t2->ty == Tpointer) { |
652 LLValue* lv = l->getRVal(); | 673 LLValue* lv = l->getRVal(); |
653 LLValue* rv = r->getRVal(); | 674 LLValue* rv = r->getRVal(); |
654 if (Logger::enabled()) | 675 if (Logger::enabled()) |
655 Logger::cout() << "lv: " << *lv << " rv: " << *rv << '\n'; | 676 Logger::cout() << "lv: " << *lv << " rv: " << *rv << '\n'; |
681 LOG_SCOPE; | 702 LOG_SCOPE; |
682 | 703 |
683 DValue* l = e1->toElem(p); | 704 DValue* l = e1->toElem(p); |
684 DValue* r = e2->toElem(p); | 705 DValue* r = e2->toElem(p); |
685 | 706 |
707 errorOnIllegalArrayOp(this, e1, e2); | |
708 | |
686 if (type->iscomplex()) { | 709 if (type->iscomplex()) { |
687 return DtoComplexMul(loc, type, l, r); | 710 return DtoComplexMul(loc, type, l, r); |
688 } | 711 } |
689 | 712 |
690 return DtoBinMul(type, l, r); | 713 return DtoBinMul(type, l, r); |
698 LOG_SCOPE; | 721 LOG_SCOPE; |
699 | 722 |
700 DValue* l = e1->toElem(p); | 723 DValue* l = e1->toElem(p); |
701 DValue* r = e2->toElem(p); | 724 DValue* r = e2->toElem(p); |
702 | 725 |
726 errorOnIllegalArrayOp(this, e1, e2); | |
727 | |
703 if (type->iscomplex()) { | 728 if (type->iscomplex()) { |
704 return DtoComplexDiv(loc, type, l, r); | 729 return DtoComplexDiv(loc, type, l, r); |
705 } | 730 } |
706 | 731 |
707 return DtoBinDiv(type, l, r); | 732 return DtoBinDiv(type, l, r); |
714 Logger::print("ModExp::toElem: %s @ %s\n", toChars(), type->toChars()); | 739 Logger::print("ModExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
715 LOG_SCOPE; | 740 LOG_SCOPE; |
716 | 741 |
717 DValue* l = e1->toElem(p); | 742 DValue* l = e1->toElem(p); |
718 DValue* r = e2->toElem(p); | 743 DValue* r = e2->toElem(p); |
744 | |
745 errorOnIllegalArrayOp(this, e1, e2); | |
719 | 746 |
720 return DtoBinRem(type, l, r); | 747 return DtoBinRem(type, l, r); |
721 } | 748 } |
722 | 749 |
723 ////////////////////////////////////////////////////////////////////////////////////////// | 750 ////////////////////////////////////////////////////////////////////////////////////////// |
1876 { \ | 1903 { \ |
1877 Logger::print("%sExp::toElem: %s @ %s\n", #X, toChars(), type->toChars()); \ | 1904 Logger::print("%sExp::toElem: %s @ %s\n", #X, toChars(), type->toChars()); \ |
1878 LOG_SCOPE; \ | 1905 LOG_SCOPE; \ |
1879 DValue* u = e1->toElem(p); \ | 1906 DValue* u = e1->toElem(p); \ |
1880 DValue* v = e2->toElem(p); \ | 1907 DValue* v = e2->toElem(p); \ |
1908 errorOnIllegalArrayOp(this, e1, e2); \ | |
1881 LLValue* x = llvm::BinaryOperator::Create(llvm::Instruction::Y, u->getRVal(), v->getRVal(), "tmp", p->scopebb()); \ | 1909 LLValue* x = llvm::BinaryOperator::Create(llvm::Instruction::Y, u->getRVal(), v->getRVal(), "tmp", p->scopebb()); \ |
1882 return new DImValue(type, x); \ | 1910 return new DImValue(type, x); \ |
1883 } | 1911 } |
1884 | 1912 |
1885 BinBitExp(And,And); | 1913 BinBitExp(And,And); |