Mercurial > projects > ldc
comparison gen/arrays.cpp @ 486:a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Reimplemented support for nested functions/class using a new approach.
Added error on taking address of intrinsic.
Fixed problems with the ->syntaxCopy of TypeFunction delegate exp.
Removed DtoDType and replaced all uses with ->toBasetype() instead.
Removed unused inplace stuff.
Fixed a bunch of issues in the runtime unittests, not complete yet.
Added mini tests.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sun, 10 Aug 2008 08:37:38 +0200 |
parents | 672eb4893b55 |
children | 39dbe48d3fe2 |
comparison
equal
deleted
inserted
replaced
485:50f6e2337a6b | 486:a34078905d01 |
---|---|
87 { | 87 { |
88 Logger::cout() << "array assignment type dont match: " << *dst->getType() << "\n\n" << *src->getType() << '\n'; | 88 Logger::cout() << "array assignment type dont match: " << *dst->getType() << "\n\n" << *src->getType() << '\n'; |
89 const LLArrayType* arrty = isaArray(src->getType()->getContainedType(0)); | 89 const LLArrayType* arrty = isaArray(src->getType()->getContainedType(0)); |
90 if (!arrty) | 90 if (!arrty) |
91 { | 91 { |
92 Logger::cout() << "invalid: " << *src << '\n'; | 92 std::cout << "invalid: " << *src << '\n'; |
93 assert(0); | 93 assert(0); |
94 } | 94 } |
95 const LLType* dstty = getPtrToType(arrty->getElementType()); | 95 const LLType* dstty = getPtrToType(arrty->getElementType()); |
96 | 96 |
97 LLValue* dstlen = DtoGEPi(dst,0,0); | 97 LLValue* dstlen = DtoGEPi(dst,0,0); |
242 LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit) | 242 LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit) |
243 { | 243 { |
244 Logger::println("DtoConstArrayInitializer: %s | %s", arrinit->toChars(), arrinit->type->toChars()); | 244 Logger::println("DtoConstArrayInitializer: %s | %s", arrinit->toChars(), arrinit->type->toChars()); |
245 LOG_SCOPE; | 245 LOG_SCOPE; |
246 | 246 |
247 Type* arrinittype = DtoDType(arrinit->type); | 247 Type* arrinittype = arrinit->type->toBasetype(); |
248 | 248 |
249 Type* t; | 249 Type* t; |
250 integer_t tdim; | 250 integer_t tdim; |
251 if (arrinittype->ty == Tsarray) { | 251 if (arrinittype->ty == Tsarray) { |
252 Logger::println("static array"); | 252 Logger::println("static array"); |
528 | 528 |
529 DValue* dptr = new DVarValue(exp->type, ptr, true); | 529 DValue* dptr = new DVarValue(exp->type, ptr, true); |
530 | 530 |
531 DValue* e = exp->toElem(gIR); | 531 DValue* e = exp->toElem(gIR); |
532 | 532 |
533 if (!e->inPlace()) | 533 DtoAssign(exp->loc, dptr, e); |
534 DtoAssign(exp->loc, dptr, e); | |
535 | 534 |
536 return slice; | 535 return slice; |
537 } | 536 } |
538 | 537 |
539 ////////////////////////////////////////////////////////////////////////////////////////// | 538 ////////////////////////////////////////////////////////////////////////////////////////// |
571 DSliceValue* DtoCatArrays(Type* type, Expression* exp1, Expression* exp2) | 570 DSliceValue* DtoCatArrays(Type* type, Expression* exp1, Expression* exp2) |
572 { | 571 { |
573 Logger::println("DtoCatArrays"); | 572 Logger::println("DtoCatArrays"); |
574 LOG_SCOPE; | 573 LOG_SCOPE; |
575 | 574 |
576 Type* t1 = DtoDType(exp1->type); | 575 Type* t1 = exp1->type->toBasetype(); |
577 Type* t2 = DtoDType(exp2->type); | 576 Type* t2 = exp2->type->toBasetype(); |
578 | 577 |
579 assert(t1->ty == Tarray || t1->ty == Tsarray); | 578 assert(t1->ty == Tarray || t1->ty == Tsarray); |
580 assert(t2->ty == Tarray || t2->ty == Tsarray); | 579 assert(t2->ty == Tarray || t2->ty == Tsarray); |
581 | 580 |
582 DValue* e1 = exp1->toElem(gIR); | 581 DValue* e1 = exp1->toElem(gIR); |
612 DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2) | 611 DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2) |
613 { | 612 { |
614 Logger::println("DtoCatArrayElement"); | 613 Logger::println("DtoCatArrayElement"); |
615 LOG_SCOPE; | 614 LOG_SCOPE; |
616 | 615 |
617 Type* t1 = DtoDType(exp1->type); | 616 Type* t1 = exp1->type->toBasetype(); |
618 Type* t2 = DtoDType(exp2->type); | 617 Type* t2 = exp2->type->toBasetype(); |
619 | 618 |
620 DValue* e1 = exp1->toElem(gIR); | 619 DValue* e1 = exp1->toElem(gIR); |
621 DValue* e2 = exp2->toElem(gIR); | 620 DValue* e2 = exp2->toElem(gIR); |
622 | 621 |
623 llvm::Value *len1, *src1, *res; | 622 llvm::Value *len1, *src1, *res; |
624 | 623 |
625 // handle prefix case, eg. int~int[] | 624 // handle prefix case, eg. int~int[] |
626 if (t2->next && t1 == DtoDType(t2->next)) | 625 if (t2->next && t1 == t2->next->toBasetype()) |
627 { | 626 { |
628 len1 = DtoArrayLen(e2); | 627 len1 = DtoArrayLen(e2); |
629 res = gIR->ir->CreateAdd(len1,DtoConstSize_t(1),"tmp"); | 628 res = gIR->ir->CreateAdd(len1,DtoConstSize_t(1),"tmp"); |
630 | 629 |
631 DValue* lenval = new DImValue(Type::tsize_t, res); | 630 DValue* lenval = new DImValue(Type::tsize_t, res); |
681 LLValue* lmem; | 680 LLValue* lmem; |
682 LLValue* rmem; | 681 LLValue* rmem; |
683 | 682 |
684 // cast static arrays to dynamic ones, this turns them into DSliceValues | 683 // cast static arrays to dynamic ones, this turns them into DSliceValues |
685 Logger::println("casting to dynamic arrays"); | 684 Logger::println("casting to dynamic arrays"); |
686 Type* l_ty = DtoDType(l->getType()); | 685 Type* l_ty = l->getType()->toBasetype(); |
687 Type* r_ty = DtoDType(r->getType()); | 686 Type* r_ty = r->getType()->toBasetype(); |
688 assert(l_ty->next == r_ty->next); | 687 assert(l_ty->next == r_ty->next); |
689 if ((l_ty->ty == Tsarray) || (r_ty->ty == Tsarray)) { | 688 if ((l_ty->ty == Tsarray) || (r_ty->ty == Tsarray)) { |
690 Type* a_ty = l_ty->next->arrayOf(); | 689 Type* a_ty = l_ty->next->arrayOf(); |
691 if (l_ty->ty == Tsarray) | 690 if (l_ty->ty == Tsarray) |
692 l = DtoCastArray(loc, l, a_ty); | 691 l = DtoCastArray(loc, l, a_ty); |
813 assert(0); | 812 assert(0); |
814 } | 813 } |
815 | 814 |
816 if (!skip) | 815 if (!skip) |
817 { | 816 { |
818 Type* t = DtoDType(DtoDType(l->getType())->next); | 817 Type* t = l->getType()->toBasetype()->next->toBasetype(); |
819 if (t->ty == Tchar) | 818 if (t->ty == Tchar) |
820 res = DtoArrayEqCmp_impl(loc, "_adCmpChar", l, r, false); | 819 res = DtoArrayEqCmp_impl(loc, "_adCmpChar", l, r, false); |
821 else | 820 else |
822 res = DtoArrayEqCmp_impl(loc, "_adCmp", l, r, true); | 821 res = DtoArrayEqCmp_impl(loc, "_adCmp", l, r, true); |
823 res = gIR->ir->CreateICmp(cmpop, res, DtoConstInt(0), "tmp"); | 822 res = gIR->ir->CreateICmp(cmpop, res, DtoConstInt(0), "tmp"); |
898 LLValue* DtoArrayLen(DValue* v) | 897 LLValue* DtoArrayLen(DValue* v) |
899 { | 898 { |
900 Logger::println("DtoArrayLen"); | 899 Logger::println("DtoArrayLen"); |
901 LOG_SCOPE; | 900 LOG_SCOPE; |
902 | 901 |
903 Type* t = DtoDType(v->getType()); | 902 Type* t = v->getType()->toBasetype(); |
904 if (t->ty == Tarray) { | 903 if (t->ty == Tarray) { |
905 if (DSliceValue* s = v->isSlice()) | 904 if (DSliceValue* s = v->isSlice()) |
906 return s->len; | 905 return s->len; |
907 else if (v->isNull()) | 906 else if (v->isNull()) |
908 return DtoConstSize_t(0); | 907 return DtoConstSize_t(0); |
924 LLValue* DtoArrayPtr(DValue* v) | 923 LLValue* DtoArrayPtr(DValue* v) |
925 { | 924 { |
926 Logger::println("DtoArrayPtr"); | 925 Logger::println("DtoArrayPtr"); |
927 LOG_SCOPE; | 926 LOG_SCOPE; |
928 | 927 |
929 Type* t = DtoDType(v->getType()); | 928 Type* t = v->getType()->toBasetype(); |
930 if (t->ty == Tarray) { | 929 if (t->ty == Tarray) { |
931 if (DSliceValue* s = v->isSlice()) | 930 if (DSliceValue* s = v->isSlice()) |
932 return s->ptr; | 931 return s->ptr; |
933 else if (v->isNull()) | 932 else if (v->isNull()) |
934 return getNullPtr(getPtrToType(DtoType(t->next))); | 933 return getNullPtr(getPtrToType(DtoType(t->next))); |
949 Logger::println("DtoCastArray"); | 948 Logger::println("DtoCastArray"); |
950 LOG_SCOPE; | 949 LOG_SCOPE; |
951 | 950 |
952 const LLType* tolltype = DtoType(to); | 951 const LLType* tolltype = DtoType(to); |
953 | 952 |
954 Type* totype = DtoDType(to); | 953 Type* totype = to->toBasetype(); |
955 Type* fromtype = DtoDType(u->getType()); | 954 Type* fromtype = u->getType()->toBasetype(); |
956 assert(fromtype->ty == Tarray || fromtype->ty == Tsarray); | 955 assert(fromtype->ty == Tarray || fromtype->ty == Tsarray); |
957 | 956 |
958 LLValue* rval; | 957 LLValue* rval; |
959 LLValue* rval2; | 958 LLValue* rval2; |
960 bool isslice = false; | 959 bool isslice = false; |