comparison gen/arrays.cpp @ 163:a8cd9bc1021a trunk

[svn r179] lots and lots of fixes, much more of tango now compiles/works.
author lindquist
date Mon, 05 May 2008 07:36:29 +0200
parents 1856c62af24b
children db9890b3fb64
comparison
equal deleted inserted replaced
162:1856c62af24b 163:a8cd9bc1021a
613 Expression* e = exp1; 613 Expression* e = exp1;
614 exp1 = exp2; 614 exp1 = exp2;
615 exp2 = e; 615 exp2 = e;
616 } 616 }
617 617
618 assert(t1->ty == Tarray);
619 assert(t2 == DtoDType(t1->next));
620
621 DValue* e1 = exp1->toElem(gIR); 618 DValue* e1 = exp1->toElem(gIR);
622 DValue* e2 = exp2->toElem(gIR); 619 DValue* e2 = exp2->toElem(gIR);
623 620
624 llvm::Value *len1, *src1, *res; 621 llvm::Value *len1, *src1, *res;
625 llvm::Value* a = e1->getRVal(); 622
626 len1 = gIR->ir->CreateLoad(DtoGEPi(a,0,0,"tmp"),"tmp"); 623 len1 = DtoArrayLen(e1);
627 res = gIR->ir->CreateAdd(len1,DtoConstSize_t(1),"tmp"); 624 res = gIR->ir->CreateAdd(len1,DtoConstSize_t(1),"tmp");
628 625
629 llvm::Value* mem = DtoNewDynArray(arr, res, DtoDType(t1->next), false); 626 llvm::Value* mem = DtoNewDynArray(arr, res, DtoDType(t1->next), false);
630 627
631 src1 = gIR->ir->CreateLoad(DtoGEPi(a,0,1,"tmp"),"tmp"); 628 src1 = DtoArrayPtr(e1);
632 629
633 DtoMemCpy(mem,src1,len1); 630 DtoMemCpy(mem,src1,len1);
634 631
635 mem = gIR->ir->CreateGEP(mem,len1,"tmp"); 632 mem = gIR->ir->CreateGEP(mem,len1,"tmp");
636 DVarValue* memval = new DVarValue(e2->getType(), mem, true); 633 DVarValue* memval = new DVarValue(e2->getType(), mem, true);
639 636
640 ////////////////////////////////////////////////////////////////////////////////////////// 637 //////////////////////////////////////////////////////////////////////////////////////////
641 // helper for eq and cmp 638 // helper for eq and cmp
642 static llvm::Value* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, bool useti) 639 static llvm::Value* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, bool useti)
643 { 640 {
641 Logger::println("comparing arrays");
644 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, func); 642 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, func);
645 assert(fn); 643 assert(fn);
646 644
647 llvm::Value* lmem; 645 llvm::Value* lmem;
648 llvm::Value* rmem; 646 llvm::Value* rmem;
649 647
650 // cast static arrays to dynamic ones, this turns them into DSliceValues 648 // cast static arrays to dynamic ones, this turns them into DSliceValues
649 Logger::println("casting to dynamic arrays");
651 Type* l_ty = DtoDType(l->getType()); 650 Type* l_ty = DtoDType(l->getType());
652 Type* r_ty = DtoDType(r->getType()); 651 Type* r_ty = DtoDType(r->getType());
653 assert(l_ty->next == r_ty->next); 652 assert(l_ty->next == r_ty->next);
654 if ((l_ty->ty == Tsarray) || (r_ty->ty == Tsarray)) { 653 if ((l_ty->ty == Tsarray) || (r_ty->ty == Tsarray)) {
655 Type* a_ty = new Type(Tarray, l_ty->next); 654 Type* a_ty = new Type(Tarray, l_ty->next);
657 l = DtoCastArray(l, a_ty); 656 l = DtoCastArray(l, a_ty);
658 if (r_ty->ty == Tsarray) 657 if (r_ty->ty == Tsarray)
659 r = DtoCastArray(r, a_ty); 658 r = DtoCastArray(r, a_ty);
660 } 659 }
661 660
661 Logger::println("giving storage");
662
662 // we need to give slices storage 663 // we need to give slices storage
663 if (l->isSlice()) { 664 if (l->isSlice()) {
664 lmem = new llvm::AllocaInst(DtoType(l->getType()), "tmpparam", gIR->topallocapoint()); 665 lmem = new llvm::AllocaInst(DtoType(l->getType()), "tmpparam", gIR->topallocapoint());
665 DtoSetArray(lmem, DtoArrayLen(l), DtoArrayPtr(l)); 666 DtoSetArray(lmem, DtoArrayLen(l), DtoArrayPtr(l));
666 } 667 }
668 // also null
669 else if (l->isNull())
670 {
671 lmem = new llvm::AllocaInst(DtoType(l->getType()), "tmpparam", gIR->topallocapoint());
672 DtoSetArray(lmem, llvm::Constant::getNullValue(DtoSize_t()), llvm::Constant::getNullValue(DtoType(l->getType()->next->pointerTo())));
673 }
667 else 674 else
668 lmem = l->getRVal(); 675 lmem = l->getRVal();
669 676
677 // and for the rvalue ...
678 // we need to give slices storage
670 if (r->isSlice()) { 679 if (r->isSlice()) {
671 rmem = new llvm::AllocaInst(DtoType(r->getType()), "tmpparam", gIR->topallocapoint()); 680 rmem = new llvm::AllocaInst(DtoType(r->getType()), "tmpparam", gIR->topallocapoint());
672 DtoSetArray(rmem, DtoArrayLen(r), DtoArrayPtr(r)); 681 DtoSetArray(rmem, DtoArrayLen(r), DtoArrayPtr(r));
673 } 682 }
683 // also null
684 else if (r->isNull())
685 {
686 rmem = new llvm::AllocaInst(DtoType(r->getType()), "tmpparam", gIR->topallocapoint());
687 DtoSetArray(rmem, llvm::Constant::getNullValue(DtoSize_t()), llvm::Constant::getNullValue(DtoType(r->getType()->next->pointerTo())));
688 }
674 else 689 else
675 rmem = r->getRVal(); 690 rmem = r->getRVal();
676 691
677 const llvm::Type* pt = fn->getFunctionType()->getParamType(0); 692 const llvm::Type* pt = fn->getFunctionType()->getParamType(0);
678 693
679 std::vector<llvm::Value*> args; 694 std::vector<llvm::Value*> args;
695 Logger::cout() << "bitcasting to " << *pt << '\n';
696 Logger::cout() << *lmem << '\n';
697 Logger::cout() << *rmem << '\n';
680 args.push_back(DtoBitCast(lmem,pt)); 698 args.push_back(DtoBitCast(lmem,pt));
681 args.push_back(DtoBitCast(rmem,pt)); 699 args.push_back(DtoBitCast(rmem,pt));
682 700
683 // pass element typeinfo ? 701 // pass element typeinfo ?
684 if (useti) { 702 if (useti) {
903 921
904 Logger::cout() << "from array or sarray" << '\n'; 922 Logger::cout() << "from array or sarray" << '\n';
905 if (totype->ty == Tpointer) { 923 if (totype->ty == Tpointer) {
906 Logger::cout() << "to pointer" << '\n'; 924 Logger::cout() << "to pointer" << '\n';
907 assert(fromtype->next == totype->next || totype->next->ty == Tvoid); 925 assert(fromtype->next == totype->next || totype->next->ty == Tvoid);
908 llvm::Value* ptr = DtoGEPi(u->getRVal(),0,1,"tmp",gIR->scopebb()); 926 rval = DtoArrayPtr(u);
909 rval = new llvm::LoadInst(ptr, "tmp", gIR->scopebb());
910 if (fromtype->next != totype->next) 927 if (fromtype->next != totype->next)
911 rval = gIR->ir->CreateBitCast(rval, getPtrToType(llvm::Type::Int8Ty), "tmp"); 928 rval = gIR->ir->CreateBitCast(rval, getPtrToType(llvm::Type::Int8Ty), "tmp");
912 } 929 }
913 else if (totype->ty == Tarray) { 930 else if (totype->ty == Tarray) {
914 Logger::cout() << "to array" << '\n'; 931 Logger::cout() << "to array" << '\n';