comparison gen/toir.cpp @ 1151:3cf0066e6faf

- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM. - Eliminated the DLRValue DValue. - Implemented proactive handling of l-value CastExpS. - Minor tweak in runtime memory.d .
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Sat, 28 Mar 2009 05:00:43 +0100
parents 5ebe8224988b
children 521dd1626d76
comparison
equal deleted inserted replaced
1150:2a687353c84d 1151:3cf0066e6faf
39 39
40 #include "llvm/Support/ManagedStatic.h" 40 #include "llvm/Support/ManagedStatic.h"
41 41
42 ////////////////////////////////////////////////////////////////////////////////////////// 42 //////////////////////////////////////////////////////////////////////////////////////////
43 43
44 void Expression::cacheLvalue(IRState* irs)
45 {
46 error("expression %s does not mask any l-value", toChars());
47 fatal();
48 }
49
50 //////////////////////////////////////////////////////////////////////////////////////////
51
44 DValue* DeclarationExp::toElem(IRState* p) 52 DValue* DeclarationExp::toElem(IRState* p)
45 { 53 {
46 Logger::print("DeclarationExp::toElem: %s | T=%s\n", toChars(), type->toChars()); 54 Logger::print("DeclarationExp::toElem: %s | T=%s\n", toChars(), type->toChars());
47 LOG_SCOPE; 55 LOG_SCOPE;
48 56
49 return DtoDeclarationExp(declaration); 57 return DtoDeclarationExp(declaration);
50 } 58 }
51 59
52 ////////////////////////////////////////////////////////////////////////////////////////// 60 //////////////////////////////////////////////////////////////////////////////////////////
53 61
62 void VarExp::cacheLvalue(IRState* p)
63 {
64 Logger::println("Caching l-value of %s", toChars());
65 LOG_SCOPE;
66 cachedLvalue = toElem(p)->getLVal();
67 }
68
54 DValue* VarExp::toElem(IRState* p) 69 DValue* VarExp::toElem(IRState* p)
55 { 70 {
56 Logger::print("VarExp::toElem: %s | %s\n", toChars(), type->toChars()); 71 Logger::print("VarExp::toElem: %s @ %s\n", toChars(), type->toChars());
57 LOG_SCOPE; 72 LOG_SCOPE;
58 73
59 assert(var); 74 assert(var);
75
76 if (cachedLvalue)
77 {
78 LLValue* V = cachedLvalue;
79 cachedLvalue = NULL;
80 return new DVarValue(type, V);
81 }
60 82
61 if (VarDeclaration* vd = var->isVarDeclaration()) 83 if (VarDeclaration* vd = var->isVarDeclaration())
62 { 84 {
63 Logger::println("VarDeclaration ' %s ' of type ' %s '", vd->toChars(), vd->type->toChars()); 85 Logger::println("VarDeclaration ' %s ' of type ' %s '", vd->toChars(), vd->type->toChars());
64 86
202 224
203 ////////////////////////////////////////////////////////////////////////////////////////// 225 //////////////////////////////////////////////////////////////////////////////////////////
204 226
205 LLConstant* VarExp::toConstElem(IRState* p) 227 LLConstant* VarExp::toConstElem(IRState* p)
206 { 228 {
207 Logger::print("VarExp::toConstElem: %s | %s\n", toChars(), type->toChars()); 229 Logger::print("VarExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
208 LOG_SCOPE; 230 LOG_SCOPE;
209 231
210 if (StaticStructInitDeclaration* sdecl = var->isStaticStructInitDeclaration()) 232 if (StaticStructInitDeclaration* sdecl = var->isStaticStructInitDeclaration())
211 { 233 {
212 // this seems to be the static initialiser for structs 234 // this seems to be the static initialiser for structs
242 264
243 ////////////////////////////////////////////////////////////////////////////////////////// 265 //////////////////////////////////////////////////////////////////////////////////////////
244 266
245 DValue* IntegerExp::toElem(IRState* p) 267 DValue* IntegerExp::toElem(IRState* p)
246 { 268 {
247 Logger::print("IntegerExp::toElem: %s | %s\n", toChars(), type->toChars()); 269 Logger::print("IntegerExp::toElem: %s @ %s\n", toChars(), type->toChars());
248 LOG_SCOPE; 270 LOG_SCOPE;
249 LLConstant* c = toConstElem(p); 271 LLConstant* c = toConstElem(p);
250 return new DConstValue(type, c); 272 return new DConstValue(type, c);
251 } 273 }
252 274
253 ////////////////////////////////////////////////////////////////////////////////////////// 275 //////////////////////////////////////////////////////////////////////////////////////////
254 276
255 LLConstant* IntegerExp::toConstElem(IRState* p) 277 LLConstant* IntegerExp::toConstElem(IRState* p)
256 { 278 {
257 Logger::print("IntegerExp::toConstElem: %s | %s\n", toChars(), type->toChars()); 279 Logger::print("IntegerExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
258 LOG_SCOPE; 280 LOG_SCOPE;
259 const LLType* t = DtoType(type); 281 const LLType* t = DtoType(type);
260 if (isaPointer(t)) { 282 if (isaPointer(t)) {
261 Logger::println("pointer"); 283 Logger::println("pointer");
262 LLConstant* i = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)value,false); 284 LLConstant* i = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)value,false);
272 294
273 ////////////////////////////////////////////////////////////////////////////////////////// 295 //////////////////////////////////////////////////////////////////////////////////////////
274 296
275 DValue* RealExp::toElem(IRState* p) 297 DValue* RealExp::toElem(IRState* p)
276 { 298 {
277 Logger::print("RealExp::toElem: %s | %s\n", toChars(), type->toChars()); 299 Logger::print("RealExp::toElem: %s @ %s\n", toChars(), type->toChars());
278 LOG_SCOPE; 300 LOG_SCOPE;
279 LLConstant* c = toConstElem(p); 301 LLConstant* c = toConstElem(p);
280 return new DConstValue(type, c); 302 return new DConstValue(type, c);
281 } 303 }
282 304
283 ////////////////////////////////////////////////////////////////////////////////////////// 305 //////////////////////////////////////////////////////////////////////////////////////////
284 306
285 LLConstant* RealExp::toConstElem(IRState* p) 307 LLConstant* RealExp::toConstElem(IRState* p)
286 { 308 {
287 Logger::print("RealExp::toConstElem: %s | %s | %LX\n", toChars(), type->toChars(), value); 309 Logger::print("RealExp::toConstElem: %s @ %s | %LX\n", toChars(), type->toChars(), value);
288 LOG_SCOPE; 310 LOG_SCOPE;
289 Type* t = type->toBasetype(); 311 Type* t = type->toBasetype();
290 return DtoConstFP(t, value); 312 return DtoConstFP(t, value);
291 } 313 }
292 314
320 342
321 ////////////////////////////////////////////////////////////////////////////////////////// 343 //////////////////////////////////////////////////////////////////////////////////////////
322 344
323 DValue* ComplexExp::toElem(IRState* p) 345 DValue* ComplexExp::toElem(IRState* p)
324 { 346 {
325 Logger::print("ComplexExp::toElem(): %s | %s\n", toChars(), type->toChars()); 347 Logger::print("ComplexExp::toElem(): %s @ %s\n", toChars(), type->toChars());
326 LOG_SCOPE; 348 LOG_SCOPE;
327 LLConstant* c = toConstElem(p); 349 LLConstant* c = toConstElem(p);
328 LLValue* res; 350 LLValue* res;
329 351
330 if (c->isNullValue()) { 352 if (c->isNullValue()) {
348 370
349 ////////////////////////////////////////////////////////////////////////////////////////// 371 //////////////////////////////////////////////////////////////////////////////////////////
350 372
351 LLConstant* ComplexExp::toConstElem(IRState* p) 373 LLConstant* ComplexExp::toConstElem(IRState* p)
352 { 374 {
353 Logger::print("ComplexExp::toConstElem(): %s | %s\n", toChars(), type->toChars()); 375 Logger::print("ComplexExp::toConstElem(): %s @ %s\n", toChars(), type->toChars());
354 LOG_SCOPE; 376 LOG_SCOPE;
355 return DtoConstComplex(type, value.re, value.im); 377 return DtoConstComplex(type, value.re, value.im);
356 } 378 }
357 379
358 ////////////////////////////////////////////////////////////////////////////////////////// 380 //////////////////////////////////////////////////////////////////////////////////////////
359 381
360 DValue* StringExp::toElem(IRState* p) 382 DValue* StringExp::toElem(IRState* p)
361 { 383 {
362 Logger::print("StringExp::toElem: %s | %s\n", toChars(), type->toChars()); 384 Logger::print("StringExp::toElem: %s @ %s\n", toChars(), type->toChars());
363 LOG_SCOPE; 385 LOG_SCOPE;
364 386
365 Type* dtype = type->toBasetype(); 387 Type* dtype = type->toBasetype();
366 Type* cty = dtype->nextOf()->toBasetype(); 388 Type* cty = dtype->nextOf()->toBasetype();
367 389
424 446
425 ////////////////////////////////////////////////////////////////////////////////////////// 447 //////////////////////////////////////////////////////////////////////////////////////////
426 448
427 LLConstant* StringExp::toConstElem(IRState* p) 449 LLConstant* StringExp::toConstElem(IRState* p)
428 { 450 {
429 Logger::print("StringExp::toConstElem: %s | %s\n", toChars(), type->toChars()); 451 Logger::print("StringExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
430 LOG_SCOPE; 452 LOG_SCOPE;
431 453
432 Type* t = type->toBasetype(); 454 Type* t = type->toBasetype();
433 Type* cty = t->nextOf()->toBasetype(); 455 Type* cty = t->nextOf()->toBasetype();
434 456
522 return r; 544 return r;
523 } 545 }
524 546
525 ////////////////////////////////////////////////////////////////////////////////////////// 547 //////////////////////////////////////////////////////////////////////////////////////////
526 548
549 /// Finds the proper lvalue for a binassign expressions.
550 /// Makes sure the given LHS expression is only evaluated once.
551 static Expression* findLvalue(IRState* irs, Expression* exp)
552 {
553 Expression* e = exp;
554
555 // skip past any casts
556 while(e->op == TOKcast)
557 e = ((CastExp*)e)->e1;
558
559 // cache lvalue and return
560 e->cacheLvalue(irs);
561 return e;
562 }
563
564 #define BIN_ASSIGN(X) \
565 DValue* X##AssignExp::toElem(IRState* p) \
566 { \
567 Logger::print(#X"AssignExp::toElem: %s @ %s\n", toChars(), type->toChars()); \
568 LOG_SCOPE; \
569 X##Exp e3(loc, e1, e2); \
570 e3.type = e1->type; \
571 DValue* dst = findLvalue(p, e1)->toElem(p); \
572 DValue* res = e3.toElem(p); \
573 DValue* stval = DtoCast(loc, res, dst->getType()); \
574 DtoAssign(loc, dst, stval); \
575 return DtoCast(loc, res, type); \
576 }
577
578 BIN_ASSIGN(Add)
579 BIN_ASSIGN(Min)
580 BIN_ASSIGN(Mul)
581 BIN_ASSIGN(Div)
582 BIN_ASSIGN(Mod)
583 BIN_ASSIGN(And)
584 BIN_ASSIGN(Or)
585 BIN_ASSIGN(Xor)
586 BIN_ASSIGN(Shl)
587 BIN_ASSIGN(Shr)
588 BIN_ASSIGN(Ushr)
589
590 #undef BIN_ASSIGN
591
592 //////////////////////////////////////////////////////////////////////////////////////////
593
527 DValue* AddExp::toElem(IRState* p) 594 DValue* AddExp::toElem(IRState* p)
528 { 595 {
529 Logger::print("AddExp::toElem: %s | %s\n", toChars(), type->toChars()); 596 Logger::print("AddExp::toElem: %s @ %s\n", toChars(), type->toChars());
530 LOG_SCOPE; 597 LOG_SCOPE;
531 598
532 DValue* l = e1->toElem(p); 599 DValue* l = e1->toElem(p);
533 DValue* r = e2->toElem(p); 600 DValue* r = e2->toElem(p);
534 601
563 } 630 }
564 } 631 }
565 632
566 ////////////////////////////////////////////////////////////////////////////////////////// 633 //////////////////////////////////////////////////////////////////////////////////////////
567 634
568 DValue* AddAssignExp::toElem(IRState* p)
569 {
570 Logger::print("AddAssignExp::toElem: %s | %s\n", toChars(), type->toChars());
571 LOG_SCOPE;
572
573 DValue* l = e1->toElem(p);
574 DValue* r = e2->toElem(p);
575
576 Type* t = type->toBasetype();
577
578 DValue* res;
579 if (e1->type->toBasetype()->ty == Tpointer) {
580 LLValue* gep = llvm::GetElementPtrInst::Create(l->getRVal(),r->getRVal(),"tmp",p->scopebb());
581 res = new DImValue(type, gep);
582 }
583 else if (t->iscomplex()) {
584 res = DtoComplexAdd(loc, e1->type, l, r);
585 }
586 else {
587 res = DtoBinAdd(l,r);
588 }
589 DtoAssign(loc, l, res);
590
591 if (res->getType() != type)
592 res = DtoCast(loc, res, type);
593
594 return res;
595 }
596
597 //////////////////////////////////////////////////////////////////////////////////////////
598
599 DValue* MinExp::toElem(IRState* p) 635 DValue* MinExp::toElem(IRState* p)
600 { 636 {
601 Logger::print("MinExp::toElem: %s | %s\n", toChars(), type->toChars()); 637 Logger::print("MinExp::toElem: %s @ %s\n", toChars(), type->toChars());
602 LOG_SCOPE; 638 LOG_SCOPE;
603 639
604 DValue* l = e1->toElem(p); 640 DValue* l = e1->toElem(p);
605 DValue* r = e2->toElem(p); 641 DValue* r = e2->toElem(p);
606 642
633 } 669 }
634 } 670 }
635 671
636 ////////////////////////////////////////////////////////////////////////////////////////// 672 //////////////////////////////////////////////////////////////////////////////////////////
637 673
638 DValue* MinAssignExp::toElem(IRState* p) 674 DValue* MulExp::toElem(IRState* p)
639 { 675 {
640 Logger::print("MinAssignExp::toElem: %s | %s\n", toChars(), type->toChars()); 676 Logger::print("MulExp::toElem: %s @ %s\n", toChars(), type->toChars());
641 LOG_SCOPE; 677 LOG_SCOPE;
642 678
643 DValue* l = e1->toElem(p); 679 DValue* l = e1->toElem(p);
644 DValue* r = e2->toElem(p); 680 DValue* r = e2->toElem(p);
645 681
646 Type* t = type->toBasetype(); 682 if (type->iscomplex()) {
647 683 return DtoComplexMul(loc, type, l, r);
648 DValue* res; 684 }
649 if (e1->type->toBasetype()->ty == Tpointer) { 685
650 Logger::println("ptr"); 686 return DtoBinMul(type, l, r);
651 LLValue* tmp = r->getRVal(); 687 }
652 LLValue* zero = llvm::ConstantInt::get(tmp->getType(),0,false); 688
653 tmp = llvm::BinaryOperator::CreateSub(zero,tmp,"tmp",p->scopebb()); 689 //////////////////////////////////////////////////////////////////////////////////////////
654 tmp = llvm::GetElementPtrInst::Create(l->getRVal(),tmp,"tmp",p->scopebb()); 690
655 res = new DImValue(type, tmp); 691 DValue* DivExp::toElem(IRState* p)
656 } 692 {
657 else if (t->iscomplex()) { 693 Logger::print("DivExp::toElem: %s @ %s\n", toChars(), type->toChars());
658 Logger::println("complex");
659 res = DtoComplexSub(loc, type, l, r);
660 }
661 else {
662 Logger::println("basic");
663 res = DtoBinSub(l,r);
664 }
665 DtoAssign(loc, l, res);
666
667 if (res->getType() != type)
668 res = DtoCast(loc, res, type);
669
670 return res;
671 }
672
673 //////////////////////////////////////////////////////////////////////////////////////////
674
675 DValue* MulExp::toElem(IRState* p)
676 {
677 Logger::print("MulExp::toElem: %s | %s\n", toChars(), type->toChars());
678 LOG_SCOPE; 694 LOG_SCOPE;
679 695
680 DValue* l = e1->toElem(p); 696 DValue* l = e1->toElem(p);
681 DValue* r = e2->toElem(p); 697 DValue* r = e2->toElem(p);
682 698
683 if (type->iscomplex()) { 699 if (type->iscomplex()) {
684 return DtoComplexMul(loc, type, l, r); 700 return DtoComplexDiv(loc, type, l, r);
685 } 701 }
686 702
687 return DtoBinMul(type, l, r); 703 return DtoBinDiv(type, l, r);
688 } 704 }
689 705
690 ////////////////////////////////////////////////////////////////////////////////////////// 706 //////////////////////////////////////////////////////////////////////////////////////////
691 707
692 DValue* MulAssignExp::toElem(IRState* p) 708 DValue* ModExp::toElem(IRState* p)
693 { 709 {
694 Logger::print("MulAssignExp::toElem: %s | %s\n", toChars(), type->toChars()); 710 Logger::print("ModExp::toElem: %s @ %s\n", toChars(), type->toChars());
695 LOG_SCOPE; 711 LOG_SCOPE;
696 712
697 DValue* l = e1->toElem(p); 713 DValue* l = e1->toElem(p);
698 DValue* r = e2->toElem(p); 714 DValue* r = e2->toElem(p);
699 715
700 DValue* res;
701 if (type->iscomplex()) {
702 res = DtoComplexMul(loc, type, l, r);
703 }
704 else {
705 res = DtoBinMul(l->getType(), l, r);
706 }
707 DtoAssign(loc, l, res);
708
709 if (res->getType() != type)
710 res = DtoCast(loc, res, type);
711
712 return res;
713 }
714
715 //////////////////////////////////////////////////////////////////////////////////////////
716
717 DValue* DivExp::toElem(IRState* p)
718 {
719 Logger::print("DivExp::toElem: %s | %s\n", toChars(), type->toChars());
720 LOG_SCOPE;
721
722 DValue* l = e1->toElem(p);
723 DValue* r = e2->toElem(p);
724
725 if (type->iscomplex()) {
726 return DtoComplexDiv(loc, type, l, r);
727 }
728
729 return DtoBinDiv(type, l, r);
730 }
731
732 //////////////////////////////////////////////////////////////////////////////////////////
733
734 DValue* DivAssignExp::toElem(IRState* p)
735 {
736 Logger::print("DivAssignExp::toElem: %s | %s\n", toChars(), type->toChars());
737 LOG_SCOPE;
738
739 DValue* l = e1->toElem(p);
740 DValue* r = e2->toElem(p);
741
742 DValue* res;
743 if (type->iscomplex()) {
744 res = DtoComplexDiv(loc, type, l, r);
745 }
746 else {
747 res = DtoBinDiv(l->getType(), l, r);
748 }
749 DtoAssign(loc, l, res);
750
751 if (res->getType() != type)
752 res = DtoCast(loc, res, type);
753
754 return res;
755 }
756
757 //////////////////////////////////////////////////////////////////////////////////////////
758
759 DValue* ModExp::toElem(IRState* p)
760 {
761 Logger::print("ModExp::toElem: %s | %s\n", toChars(), type->toChars());
762 LOG_SCOPE;
763
764 DValue* l = e1->toElem(p);
765 DValue* r = e2->toElem(p);
766
767 return DtoBinRem(type, l, r); 716 return DtoBinRem(type, l, r);
768 } 717 }
769 718
770 ////////////////////////////////////////////////////////////////////////////////////////// 719 //////////////////////////////////////////////////////////////////////////////////////////
771 720
772 DValue* ModAssignExp::toElem(IRState* p)
773 {
774 Logger::print("ModAssignExp::toElem: %s | %s\n", toChars(), type->toChars());
775 LOG_SCOPE;
776
777 DValue* l = e1->toElem(p);
778 DValue* r = e2->toElem(p);
779
780 DValue* res = DtoBinRem(l->getType(), l, r);
781 DtoAssign(loc, l, res);
782
783 if (res->getType() != type)
784 res = DtoCast(loc, res, type);
785
786 return res;
787 }
788
789 //////////////////////////////////////////////////////////////////////////////////////////
790
791 DValue* CallExp::toElem(IRState* p) 721 DValue* CallExp::toElem(IRState* p)
792 { 722 {
793 Logger::print("CallExp::toElem: %s | %s\n", toChars(), type->toChars()); 723 Logger::print("CallExp::toElem: %s @ %s\n", toChars(), type->toChars());
794 LOG_SCOPE; 724 LOG_SCOPE;
795 725
796 // get the callee value 726 // get the callee value
797 DValue* fnval = e1->toElem(p); 727 DValue* fnval = e1->toElem(p);
798 728
831 761
832 ////////////////////////////////////////////////////////////////////////////////////////// 762 //////////////////////////////////////////////////////////////////////////////////////////
833 763
834 DValue* CastExp::toElem(IRState* p) 764 DValue* CastExp::toElem(IRState* p)
835 { 765 {
836 Logger::print("CastExp::toElem: %s | %s\n", toChars(), type->toChars()); 766 Logger::print("CastExp::toElem: %s @ %s\n", toChars(), type->toChars());
837 LOG_SCOPE; 767 LOG_SCOPE;
838 768
839 // get the value to cast 769 // get the value to cast
840 DValue* u = e1->toElem(p); 770 DValue* u = e1->toElem(p);
841 771
846 776
847 // paint the type, if necessary 777 // paint the type, if necessary
848 if (!type->equals(to)) 778 if (!type->equals(to))
849 v = DtoPaintType(loc, v, type); 779 v = DtoPaintType(loc, v, type);
850 780
851 // slices are not valid lvalues 781 // return the new rvalue
852 if (v->isSlice())
853 return v;
854 // if we're casting a lvalue, keep it around, we might be in a lvalue cast.
855 else if(u->isLVal())
856 return new DLRValue(u, v);
857 // otherwise just return the new value
858 return v; 782 return v;
859 } 783 }
860 784
861 ////////////////////////////////////////////////////////////////////////////////////////// 785 //////////////////////////////////////////////////////////////////////////////////////////
862 786
863 LLConstant* CastExp::toConstElem(IRState* p) 787 LLConstant* CastExp::toConstElem(IRState* p)
864 { 788 {
865 Logger::print("CastExp::toConstElem: %s | %s\n", toChars(), type->toChars()); 789 Logger::print("CastExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
866 LOG_SCOPE; 790 LOG_SCOPE;
867 791
868 LLConstant* res; 792 LLConstant* res;
869 const LLType* lltype = DtoType(type); 793 const LLType* lltype = DtoType(type);
870 Type* tb = to->toBasetype(); 794 Type* tb = to->toBasetype();
897 821
898 ////////////////////////////////////////////////////////////////////////////////////////// 822 //////////////////////////////////////////////////////////////////////////////////////////
899 823
900 DValue* SymOffExp::toElem(IRState* p) 824 DValue* SymOffExp::toElem(IRState* p)
901 { 825 {
902 Logger::print("SymOffExp::toElem: %s | %s\n", toChars(), type->toChars()); 826 Logger::print("SymOffExp::toElem: %s @ %s\n", toChars(), type->toChars());
903 LOG_SCOPE; 827 LOG_SCOPE;
904 828
905 assert(0 && "SymOffExp::toElem should no longer be called :/"); 829 assert(0 && "SymOffExp::toElem should no longer be called :/");
906 return 0; 830 return 0;
907 } 831 }
908 832
909 ////////////////////////////////////////////////////////////////////////////////////////// 833 //////////////////////////////////////////////////////////////////////////////////////////
910 834
911 DValue* AddrExp::toElem(IRState* p) 835 DValue* AddrExp::toElem(IRState* p)
912 { 836 {
913 Logger::println("AddrExp::toElem: %s | %s", toChars(), type->toChars()); 837 Logger::println("AddrExp::toElem: %s @ %s", toChars(), type->toChars());
914 LOG_SCOPE; 838 LOG_SCOPE;
915 DValue* v = e1->toElem(p); 839 DValue* v = e1->toElem(p);
916 if (v->isField()) { 840 if (v->isField()) {
917 Logger::println("is field"); 841 Logger::println("is field");
918 return v; 842 return v;
1028 } 952 }
1029 } 953 }
1030 954
1031 ////////////////////////////////////////////////////////////////////////////////////////// 955 //////////////////////////////////////////////////////////////////////////////////////////
1032 956
957 void PtrExp::cacheLvalue(IRState* p)
958 {
959 Logger::println("Caching l-value of %s", toChars());
960 LOG_SCOPE;
961 cachedLvalue = e1->toElem(p)->getRVal();
962 }
963
1033 DValue* PtrExp::toElem(IRState* p) 964 DValue* PtrExp::toElem(IRState* p)
1034 { 965 {
1035 Logger::println("PtrExp::toElem: %s | %s", toChars(), type->toChars()); 966 Logger::println("PtrExp::toElem: %s @ %s", toChars(), type->toChars());
1036 LOG_SCOPE; 967 LOG_SCOPE;
1037 968
1038 DValue* a = e1->toElem(p); 969 // function pointers are special
1039 970 if (type->toBasetype()->ty == Tfunction)
1040 // this is *so* ugly.. I'd really like to figure out some way to avoid this badness... 971 {
1041 LLValue* lv = a->getRVal(); 972 assert(!cachedLvalue);
1042 LLValue* v = lv; 973 return new DImValue(type, e1->toElem(p)->getRVal());
1043 974 }
1044 Type* bt = type->toBasetype(); 975
1045 976 // get the rvalue and return it as an lvalue
1046 // we can't load function pointers, but they aren't passed by reference either 977 LLValue* V;
1047 // FIXME: maybe a MayLoad function isn't a bad idea after all ... 978 if (cachedLvalue)
1048 if (!DtoIsPassedByRef(bt) && bt->ty != Tfunction) 979 {
1049 v = DtoLoad(v); 980 V = cachedLvalue;
1050 981 cachedLvalue = NULL;
1051 return new DLRValue(new DVarValue(type, lv), new DImValue(type, v)); 982 }
1052 } 983 else
1053 984 {
1054 ////////////////////////////////////////////////////////////////////////////////////////// 985 V = e1->toElem(p)->getRVal();
986 }
987 return new DVarValue(type, V);
988 }
989
990 //////////////////////////////////////////////////////////////////////////////////////////
991
992 void DotVarExp::cacheLvalue(IRState* p)
993 {
994 Logger::println("Caching l-value of %s", toChars());
995 LOG_SCOPE;
996 cachedLvalue = toElem(p)->getLVal();
997 }
1055 998
1056 DValue* DotVarExp::toElem(IRState* p) 999 DValue* DotVarExp::toElem(IRState* p)
1057 { 1000 {
1058 Logger::print("DotVarExp::toElem: %s | %s\n", toChars(), type->toChars()); 1001 Logger::print("DotVarExp::toElem: %s @ %s\n", toChars(), type->toChars());
1059 LOG_SCOPE; 1002 LOG_SCOPE;
1003
1004 if (cachedLvalue)
1005 {
1006 LLValue *V = cachedLvalue;
1007 cachedLvalue = NULL;
1008 VarDeclaration* vd = var->isVarDeclaration();
1009 assert(vd);
1010 return new DVarValue(type, vd, V);
1011 }
1060 1012
1061 DValue* l = e1->toElem(p); 1013 DValue* l = e1->toElem(p);
1062 1014
1063 Type* t = type->toBasetype(); 1015 Type* t = type->toBasetype();
1064 Type* e1type = e1->type->toBasetype(); 1016 Type* e1type = e1->type->toBasetype();
1163 1115
1164 ////////////////////////////////////////////////////////////////////////////////////////// 1116 //////////////////////////////////////////////////////////////////////////////////////////
1165 1117
1166 DValue* ThisExp::toElem(IRState* p) 1118 DValue* ThisExp::toElem(IRState* p)
1167 { 1119 {
1168 Logger::print("ThisExp::toElem: %s | %s\n", toChars(), type->toChars()); 1120 Logger::print("ThisExp::toElem: %s @ %s\n", toChars(), type->toChars());
1169 LOG_SCOPE; 1121 LOG_SCOPE;
1170 1122
1171 // this seems to happen for dmd generated assert statements like: 1123 // this seems to happen for dmd generated assert statements like:
1172 // assert(this, "null this"); 1124 // assert(this, "null this");
1173 // FIXME: check for TOKthis in AssertExp instead 1125 // FIXME: check for TOKthis in AssertExp instead
1196 return 0; 1148 return 0;
1197 } 1149 }
1198 1150
1199 ////////////////////////////////////////////////////////////////////////////////////////// 1151 //////////////////////////////////////////////////////////////////////////////////////////
1200 1152
1153 void IndexExp::cacheLvalue(IRState* p)
1154 {
1155 Logger::println("Caching l-value of %s", toChars());
1156 LOG_SCOPE;
1157 cachedLvalue = toElem(p)->getLVal();
1158 }
1159
1201 DValue* IndexExp::toElem(IRState* p) 1160 DValue* IndexExp::toElem(IRState* p)
1202 { 1161 {
1203 Logger::print("IndexExp::toElem: %s | %s\n", toChars(), type->toChars()); 1162 Logger::print("IndexExp::toElem: %s @ %s\n", toChars(), type->toChars());
1204 LOG_SCOPE; 1163 LOG_SCOPE;
1164
1165 if (cachedLvalue)
1166 {
1167 LLValue* V = cachedLvalue;
1168 cachedLvalue = NULL;
1169 return new DVarValue(type, V);
1170 }
1205 1171
1206 DValue* l = e1->toElem(p); 1172 DValue* l = e1->toElem(p);
1207 1173
1208 Type* e1type = e1->type->toBasetype(); 1174 Type* e1type = e1->type->toBasetype();
1209 1175
1241 1207
1242 ////////////////////////////////////////////////////////////////////////////////////////// 1208 //////////////////////////////////////////////////////////////////////////////////////////
1243 1209
1244 DValue* SliceExp::toElem(IRState* p) 1210 DValue* SliceExp::toElem(IRState* p)
1245 { 1211 {
1246 Logger::print("SliceExp::toElem: %s | %s\n", toChars(), type->toChars()); 1212 Logger::print("SliceExp::toElem: %s @ %s\n", toChars(), type->toChars());
1247 LOG_SCOPE; 1213 LOG_SCOPE;
1248 1214
1249 // this is the new slicing code, it's different in that a full slice will no longer retain the original pointer. 1215 // this is the new slicing code, it's different in that a full slice will no longer retain the original pointer.
1250 // but this was broken if there *was* no original pointer, ie. a slice of a slice... 1216 // but this was broken if there *was* no original pointer, ie. a slice of a slice...
1251 // now all slices have *both* the 'len' and 'ptr' fields set to != null. 1217 // now all slices have *both* the 'len' and 'ptr' fields set to != null.
1318 1284
1319 ////////////////////////////////////////////////////////////////////////////////////////// 1285 //////////////////////////////////////////////////////////////////////////////////////////
1320 1286
1321 DValue* CmpExp::toElem(IRState* p) 1287 DValue* CmpExp::toElem(IRState* p)
1322 { 1288 {
1323 Logger::print("CmpExp::toElem: %s | %s\n", toChars(), type->toChars()); 1289 Logger::print("CmpExp::toElem: %s @ %s\n", toChars(), type->toChars());
1324 LOG_SCOPE; 1290 LOG_SCOPE;
1325 1291
1326 DValue* l = e1->toElem(p); 1292 DValue* l = e1->toElem(p);
1327 DValue* r = e2->toElem(p); 1293 DValue* r = e2->toElem(p);
1328 1294
1437 1403
1438 ////////////////////////////////////////////////////////////////////////////////////////// 1404 //////////////////////////////////////////////////////////////////////////////////////////
1439 1405
1440 DValue* EqualExp::toElem(IRState* p) 1406 DValue* EqualExp::toElem(IRState* p)
1441 { 1407 {
1442 Logger::print("EqualExp::toElem: %s | %s\n", toChars(), type->toChars()); 1408 Logger::print("EqualExp::toElem: %s @ %s\n", toChars(), type->toChars());
1443 LOG_SCOPE; 1409 LOG_SCOPE;
1444 1410
1445 DValue* l = e1->toElem(p); 1411 DValue* l = e1->toElem(p);
1446 DValue* r = e2->toElem(p); 1412 DValue* r = e2->toElem(p);
1447 1413
1528 1494
1529 ////////////////////////////////////////////////////////////////////////////////////////// 1495 //////////////////////////////////////////////////////////////////////////////////////////
1530 1496
1531 DValue* PostExp::toElem(IRState* p) 1497 DValue* PostExp::toElem(IRState* p)
1532 { 1498 {
1533 Logger::print("PostExp::toElem: %s | %s\n", toChars(), type->toChars()); 1499 Logger::print("PostExp::toElem: %s @ %s\n", toChars(), type->toChars());
1534 LOG_SCOPE; 1500 LOG_SCOPE;
1535 1501
1536 DValue* l = e1->toElem(p); 1502 DValue* l = e1->toElem(p);
1537 DValue* r = e2->toElem(p); 1503 DValue* r = e2->toElem(p);
1538 1504
1582 1548
1583 ////////////////////////////////////////////////////////////////////////////////////////// 1549 //////////////////////////////////////////////////////////////////////////////////////////
1584 1550
1585 DValue* NewExp::toElem(IRState* p) 1551 DValue* NewExp::toElem(IRState* p)
1586 { 1552 {
1587 Logger::print("NewExp::toElem: %s | %s\n", toChars(), type->toChars()); 1553 Logger::print("NewExp::toElem: %s @ %s\n", toChars(), type->toChars());
1588 LOG_SCOPE; 1554 LOG_SCOPE;
1589 1555
1590 assert(newtype); 1556 assert(newtype);
1591 Type* ntype = newtype->toBasetype(); 1557 Type* ntype = newtype->toBasetype();
1592 1558
1663 1629
1664 ////////////////////////////////////////////////////////////////////////////////////////// 1630 //////////////////////////////////////////////////////////////////////////////////////////
1665 1631
1666 DValue* DeleteExp::toElem(IRState* p) 1632 DValue* DeleteExp::toElem(IRState* p)
1667 { 1633 {
1668 Logger::print("DeleteExp::toElem: %s | %s\n", toChars(), type->toChars()); 1634 Logger::print("DeleteExp::toElem: %s @ %s\n", toChars(), type->toChars());
1669 LOG_SCOPE; 1635 LOG_SCOPE;
1670 1636
1671 DValue* dval = e1->toElem(p); 1637 DValue* dval = e1->toElem(p);
1672 Type* et = e1->type->toBasetype(); 1638 Type* et = e1->type->toBasetype();
1673 1639
1723 1689
1724 ////////////////////////////////////////////////////////////////////////////////////////// 1690 //////////////////////////////////////////////////////////////////////////////////////////
1725 1691
1726 DValue* ArrayLengthExp::toElem(IRState* p) 1692 DValue* ArrayLengthExp::toElem(IRState* p)
1727 { 1693 {
1728 Logger::print("ArrayLengthExp::toElem: %s | %s\n", toChars(), type->toChars()); 1694 Logger::print("ArrayLengthExp::toElem: %s @ %s\n", toChars(), type->toChars());
1729 LOG_SCOPE; 1695 LOG_SCOPE;
1730 1696
1731 DValue* u = e1->toElem(p); 1697 DValue* u = e1->toElem(p);
1732 return new DImValue(type, DtoArrayLen(u)); 1698 return new DImValue(type, DtoArrayLen(u));
1733 } 1699 }
1796 1762
1797 ////////////////////////////////////////////////////////////////////////////////////////// 1763 //////////////////////////////////////////////////////////////////////////////////////////
1798 1764
1799 DValue* NotExp::toElem(IRState* p) 1765 DValue* NotExp::toElem(IRState* p)
1800 { 1766 {
1801 Logger::print("NotExp::toElem: %s | %s\n", toChars(), type->toChars()); 1767 Logger::print("NotExp::toElem: %s @ %s\n", toChars(), type->toChars());
1802 LOG_SCOPE; 1768 LOG_SCOPE;
1803 1769
1804 DValue* u = e1->toElem(p); 1770 DValue* u = e1->toElem(p);
1805 1771
1806 LLValue* b = DtoCast(loc, u, Type::tbool)->getRVal(); 1772 LLValue* b = DtoCast(loc, u, Type::tbool)->getRVal();
1813 1779
1814 ////////////////////////////////////////////////////////////////////////////////////////// 1780 //////////////////////////////////////////////////////////////////////////////////////////
1815 1781
1816 DValue* AndAndExp::toElem(IRState* p) 1782 DValue* AndAndExp::toElem(IRState* p)
1817 { 1783 {
1818 Logger::print("AndAndExp::toElem: %s | %s\n", toChars(), type->toChars()); 1784 Logger::print("AndAndExp::toElem: %s @ %s\n", toChars(), type->toChars());
1819 LOG_SCOPE; 1785 LOG_SCOPE;
1820 1786
1821 // allocate a temporary for the final result. failed to come up with a better way :/ 1787 // allocate a temporary for the final result. failed to come up with a better way :/
1822 LLValue* resval = 0; 1788 LLValue* resval = 0;
1823 resval = DtoAlloca(LLType::Int1Ty,"andandtmp"); 1789 resval = DtoAlloca(LLType::Int1Ty,"andandtmp");
1851 1817
1852 ////////////////////////////////////////////////////////////////////////////////////////// 1818 //////////////////////////////////////////////////////////////////////////////////////////
1853 1819
1854 DValue* OrOrExp::toElem(IRState* p) 1820 DValue* OrOrExp::toElem(IRState* p)
1855 { 1821 {
1856 Logger::print("OrOrExp::toElem: %s | %s\n", toChars(), type->toChars()); 1822 Logger::print("OrOrExp::toElem: %s @ %s\n", toChars(), type->toChars());
1857 LOG_SCOPE; 1823 LOG_SCOPE;
1858 1824
1859 // allocate a temporary for the final result. failed to come up with a better way :/ 1825 // allocate a temporary for the final result. failed to come up with a better way :/
1860 LLValue* resval = 0; 1826 LLValue* resval = 0;
1861 resval = DtoAlloca(LLType::Int1Ty,"orortmp"); 1827 resval = DtoAlloca(LLType::Int1Ty,"orortmp");
1889 ////////////////////////////////////////////////////////////////////////////////////////// 1855 //////////////////////////////////////////////////////////////////////////////////////////
1890 1856
1891 #define BinBitExp(X,Y) \ 1857 #define BinBitExp(X,Y) \
1892 DValue* X##Exp::toElem(IRState* p) \ 1858 DValue* X##Exp::toElem(IRState* p) \
1893 { \ 1859 { \
1894 Logger::print("%sExp::toElem: %s | %s\n", #X, toChars(), type->toChars()); \ 1860 Logger::print("%sExp::toElem: %s @ %s\n", #X, toChars(), type->toChars()); \
1895 LOG_SCOPE; \ 1861 LOG_SCOPE; \
1896 DValue* u = e1->toElem(p); \ 1862 DValue* u = e1->toElem(p); \
1897 DValue* v = e2->toElem(p); \ 1863 DValue* v = e2->toElem(p); \
1898 LLValue* x = llvm::BinaryOperator::Create(llvm::Instruction::Y, u->getRVal(), v->getRVal(), "tmp", p->scopebb()); \ 1864 LLValue* x = llvm::BinaryOperator::Create(llvm::Instruction::Y, u->getRVal(), v->getRVal(), "tmp", p->scopebb()); \
1899 return new DImValue(type, x); \ 1865 return new DImValue(type, x); \
1900 } \
1901 \
1902 DValue* X##AssignExp::toElem(IRState* p) \
1903 { \
1904 Logger::print("%sAssignExp::toElem: %s | %s\n", #X, toChars(), type->toChars()); \
1905 LOG_SCOPE; \
1906 DValue* u = e1->toElem(p); \
1907 DValue* v = e2->toElem(p); \
1908 LLValue* uval = u->getRVal(); \
1909 LLValue* vval = v->getRVal(); \
1910 LLValue* tmp = llvm::BinaryOperator::Create(llvm::Instruction::Y, uval, vval, "tmp", p->scopebb()); \
1911 DtoStore(DtoPointedType(u->getLVal(), tmp), u->getLVal()); \
1912 return u; \
1913 } 1866 }
1914 1867
1915 BinBitExp(And,And); 1868 BinBitExp(And,And);
1916 BinBitExp(Or,Or); 1869 BinBitExp(Or,Or);
1917 BinBitExp(Xor,Xor); 1870 BinBitExp(Xor,Xor);
1918 BinBitExp(Shl,Shl); 1871 BinBitExp(Shl,Shl);
1919 BinBitExp(Ushr,LShr); 1872 BinBitExp(Ushr,LShr);
1920 1873
1921 DValue* ShrExp::toElem(IRState* p) 1874 DValue* ShrExp::toElem(IRState* p)
1922 { 1875 {
1923 Logger::print("ShrExp::toElem: %s | %s\n", toChars(), type->toChars()); 1876 Logger::print("ShrExp::toElem: %s @ %s\n", toChars(), type->toChars());
1924 LOG_SCOPE; 1877 LOG_SCOPE;
1925 DValue* u = e1->toElem(p); 1878 DValue* u = e1->toElem(p);
1926 DValue* v = e2->toElem(p); 1879 DValue* v = e2->toElem(p);
1927 LLValue* x; 1880 LLValue* x;
1928 if (e1->type->isunsigned()) 1881 if (e1->type->isunsigned())
1930 else 1883 else
1931 x = p->ir->CreateAShr(u->getRVal(), v->getRVal(), "tmp"); 1884 x = p->ir->CreateAShr(u->getRVal(), v->getRVal(), "tmp");
1932 return new DImValue(type, x); 1885 return new DImValue(type, x);
1933 } 1886 }
1934 1887
1935 DValue* ShrAssignExp::toElem(IRState* p)
1936 {
1937 Logger::print("ShrAssignExp::toElem: %s | %s\n", toChars(), type->toChars());
1938 LOG_SCOPE;
1939 DValue* u = e1->toElem(p);
1940 DValue* v = e2->toElem(p);
1941 LLValue* uval = u->getRVal();
1942 LLValue* vval = v->getRVal();
1943 LLValue* tmp;
1944 if (e1->type->isunsigned())
1945 tmp = p->ir->CreateLShr(uval, vval, "tmp");
1946 else
1947 tmp = p->ir->CreateAShr(uval, vval, "tmp");
1948 DtoStore(DtoPointedType(u->getLVal(), tmp), u->getLVal());
1949 return u;
1950 }
1951
1952 ////////////////////////////////////////////////////////////////////////////////////////// 1888 //////////////////////////////////////////////////////////////////////////////////////////
1953 1889
1954 DValue* HaltExp::toElem(IRState* p) 1890 DValue* HaltExp::toElem(IRState* p)
1955 { 1891 {
1956 Logger::print("HaltExp::toElem: %s\n", toChars()); 1892 Logger::print("HaltExp::toElem: %s\n", toChars());
1978 1914
1979 ////////////////////////////////////////////////////////////////////////////////////////// 1915 //////////////////////////////////////////////////////////////////////////////////////////
1980 1916
1981 DValue* DelegateExp::toElem(IRState* p) 1917 DValue* DelegateExp::toElem(IRState* p)
1982 { 1918 {
1983 Logger::print("DelegateExp::toElem: %s | %s\n", toChars(), type->toChars()); 1919 Logger::print("DelegateExp::toElem: %s @ %s\n", toChars(), type->toChars());
1984 LOG_SCOPE; 1920 LOG_SCOPE;
1985 1921
1986 if(func->isStatic()) 1922 if(func->isStatic())
1987 error("can't take delegate of static function %s, it does not require a context ptr", func->toChars()); 1923 error("can't take delegate of static function %s, it does not require a context ptr", func->toChars());
1988 1924
2039 1975
2040 ////////////////////////////////////////////////////////////////////////////////////////// 1976 //////////////////////////////////////////////////////////////////////////////////////////
2041 1977
2042 DValue* IdentityExp::toElem(IRState* p) 1978 DValue* IdentityExp::toElem(IRState* p)
2043 { 1979 {
2044 Logger::print("IdentityExp::toElem: %s | %s\n", toChars(), type->toChars()); 1980 Logger::print("IdentityExp::toElem: %s @ %s\n", toChars(), type->toChars());
2045 LOG_SCOPE; 1981 LOG_SCOPE;
2046 1982
2047 DValue* u = e1->toElem(p); 1983 DValue* u = e1->toElem(p);
2048 DValue* v = e2->toElem(p); 1984 DValue* v = e2->toElem(p);
2049 1985
2099 2035
2100 ////////////////////////////////////////////////////////////////////////////////////////// 2036 //////////////////////////////////////////////////////////////////////////////////////////
2101 2037
2102 DValue* CommaExp::toElem(IRState* p) 2038 DValue* CommaExp::toElem(IRState* p)
2103 { 2039 {
2104 Logger::print("CommaExp::toElem: %s | %s\n", toChars(), type->toChars()); 2040 Logger::print("CommaExp::toElem: %s @ %s\n", toChars(), type->toChars());
2105 LOG_SCOPE; 2041 LOG_SCOPE;
2106 2042
2107 DValue* u = e1->toElem(p); 2043 DValue* u = e1->toElem(p);
2108 DValue* v = e2->toElem(p); 2044 DValue* v = e2->toElem(p);
2109 assert(e2->type == type); 2045 assert(e2->type == type);
2112 2048
2113 ////////////////////////////////////////////////////////////////////////////////////////// 2049 //////////////////////////////////////////////////////////////////////////////////////////
2114 2050
2115 DValue* CondExp::toElem(IRState* p) 2051 DValue* CondExp::toElem(IRState* p)
2116 { 2052 {
2117 Logger::print("CondExp::toElem: %s | %s\n", toChars(), type->toChars()); 2053 Logger::print("CondExp::toElem: %s @ %s\n", toChars(), type->toChars());
2118 LOG_SCOPE; 2054 LOG_SCOPE;
2119 2055
2120 Type* dtype = type->toBasetype(); 2056 Type* dtype = type->toBasetype();
2121 const LLType* resty = DtoType(dtype); 2057 const LLType* resty = DtoType(dtype);
2122 2058
2157 2093
2158 ////////////////////////////////////////////////////////////////////////////////////////// 2094 //////////////////////////////////////////////////////////////////////////////////////////
2159 2095
2160 DValue* ComExp::toElem(IRState* p) 2096 DValue* ComExp::toElem(IRState* p)
2161 { 2097 {
2162 Logger::print("ComExp::toElem: %s | %s\n", toChars(), type->toChars()); 2098 Logger::print("ComExp::toElem: %s @ %s\n", toChars(), type->toChars());
2163 LOG_SCOPE; 2099 LOG_SCOPE;
2164 2100
2165 DValue* u = e1->toElem(p); 2101 DValue* u = e1->toElem(p);
2166 2102
2167 LLValue* value = u->getRVal(); 2103 LLValue* value = u->getRVal();
2173 2109
2174 ////////////////////////////////////////////////////////////////////////////////////////// 2110 //////////////////////////////////////////////////////////////////////////////////////////
2175 2111
2176 DValue* NegExp::toElem(IRState* p) 2112 DValue* NegExp::toElem(IRState* p)
2177 { 2113 {
2178 Logger::print("NegExp::toElem: %s | %s\n", toChars(), type->toChars()); 2114 Logger::print("NegExp::toElem: %s @ %s\n", toChars(), type->toChars());
2179 LOG_SCOPE; 2115 LOG_SCOPE;
2180 2116
2181 DValue* l = e1->toElem(p); 2117 DValue* l = e1->toElem(p);
2182 2118
2183 if (type->iscomplex()) { 2119 if (type->iscomplex()) {
2192 2128
2193 ////////////////////////////////////////////////////////////////////////////////////////// 2129 //////////////////////////////////////////////////////////////////////////////////////////
2194 2130
2195 DValue* CatExp::toElem(IRState* p) 2131 DValue* CatExp::toElem(IRState* p)
2196 { 2132 {
2197 Logger::print("CatExp::toElem: %s | %s\n", toChars(), type->toChars()); 2133 Logger::print("CatExp::toElem: %s @ %s\n", toChars(), type->toChars());
2198 LOG_SCOPE; 2134 LOG_SCOPE;
2199 2135
2200 Type* t = type->toBasetype(); 2136 Type* t = type->toBasetype();
2201 2137
2202 bool arrNarr = e1->type->toBasetype() == e2->type->toBasetype(); 2138 bool arrNarr = e1->type->toBasetype() == e2->type->toBasetype();
2216 2152
2217 ////////////////////////////////////////////////////////////////////////////////////////// 2153 //////////////////////////////////////////////////////////////////////////////////////////
2218 2154
2219 DValue* CatAssignExp::toElem(IRState* p) 2155 DValue* CatAssignExp::toElem(IRState* p)
2220 { 2156 {
2221 Logger::print("CatAssignExp::toElem: %s | %s\n", toChars(), type->toChars()); 2157 Logger::print("CatAssignExp::toElem: %s @ %s\n", toChars(), type->toChars());
2222 LOG_SCOPE; 2158 LOG_SCOPE;
2223 2159
2224 DValue* l = e1->toElem(p); 2160 DValue* l = e1->toElem(p);
2225 2161
2226 Type* e1type = e1->type->toBasetype(); 2162 Type* e1type = e1->type->toBasetype();
2243 2179
2244 ////////////////////////////////////////////////////////////////////////////////////////// 2180 //////////////////////////////////////////////////////////////////////////////////////////
2245 2181
2246 DValue* FuncExp::toElem(IRState* p) 2182 DValue* FuncExp::toElem(IRState* p)
2247 { 2183 {
2248 Logger::print("FuncExp::toElem: %s | %s\n", toChars(), type->toChars()); 2184 Logger::print("FuncExp::toElem: %s @ %s\n", toChars(), type->toChars());
2249 LOG_SCOPE; 2185 LOG_SCOPE;
2250 2186
2251 assert(fd); 2187 assert(fd);
2252 2188
2253 if (fd->isNested()) Logger::println("nested"); 2189 if (fd->isNested()) Logger::println("nested");
2282 2218
2283 ////////////////////////////////////////////////////////////////////////////////////////// 2219 //////////////////////////////////////////////////////////////////////////////////////////
2284 2220
2285 LLConstant* FuncExp::toConstElem(IRState* p) 2221 LLConstant* FuncExp::toConstElem(IRState* p)
2286 { 2222 {
2287 Logger::print("FuncExp::toConstElem: %s | %s\n", toChars(), type->toChars()); 2223 Logger::print("FuncExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
2288 LOG_SCOPE; 2224 LOG_SCOPE;
2289 2225
2290 assert(fd); 2226 assert(fd);
2291 assert(fd->tok == TOKfunction); 2227 assert(fd->tok == TOKfunction);
2292 2228
2298 2234
2299 ////////////////////////////////////////////////////////////////////////////////////////// 2235 //////////////////////////////////////////////////////////////////////////////////////////
2300 2236
2301 DValue* ArrayLiteralExp::toElem(IRState* p) 2237 DValue* ArrayLiteralExp::toElem(IRState* p)
2302 { 2238 {
2303 Logger::print("ArrayLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); 2239 Logger::print("ArrayLiteralExp::toElem: %s @ %s\n", toChars(), type->toChars());
2304 LOG_SCOPE; 2240 LOG_SCOPE;
2305 2241
2306 // D types 2242 // D types
2307 Type* arrayType = type->toBasetype(); 2243 Type* arrayType = type->toBasetype();
2308 Type* elemType = arrayType->nextOf()->toBasetype(); 2244 Type* elemType = arrayType->nextOf()->toBasetype();
2367 2303
2368 ////////////////////////////////////////////////////////////////////////////////////////// 2304 //////////////////////////////////////////////////////////////////////////////////////////
2369 2305
2370 LLConstant* ArrayLiteralExp::toConstElem(IRState* p) 2306 LLConstant* ArrayLiteralExp::toConstElem(IRState* p)
2371 { 2307 {
2372 Logger::print("ArrayLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars()); 2308 Logger::print("ArrayLiteralExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
2373 LOG_SCOPE; 2309 LOG_SCOPE;
2374 2310
2375 // extract D types 2311 // extract D types
2376 Type* bt = type->toBasetype(); 2312 Type* bt = type->toBasetype();
2377 Type* elemt = bt->nextOf(); 2313 Type* elemt = bt->nextOf();
2407 2343
2408 ////////////////////////////////////////////////////////////////////////////////////////// 2344 //////////////////////////////////////////////////////////////////////////////////////////
2409 2345
2410 DValue* StructLiteralExp::toElem(IRState* p) 2346 DValue* StructLiteralExp::toElem(IRState* p)
2411 { 2347 {
2412 Logger::print("StructLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); 2348 Logger::print("StructLiteralExp::toElem: %s @ %s\n", toChars(), type->toChars());
2413 LOG_SCOPE; 2349 LOG_SCOPE;
2414 2350
2415 // get inits 2351 // get inits
2416 std::vector<LLValue*> inits(sd->fields.dim, NULL); 2352 std::vector<LLValue*> inits(sd->fields.dim, NULL);
2417 2353
2465 2401
2466 ////////////////////////////////////////////////////////////////////////////////////////// 2402 //////////////////////////////////////////////////////////////////////////////////////////
2467 2403
2468 LLConstant* StructLiteralExp::toConstElem(IRState* p) 2404 LLConstant* StructLiteralExp::toConstElem(IRState* p)
2469 { 2405 {
2470 Logger::print("StructLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars()); 2406 Logger::print("StructLiteralExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
2471 LOG_SCOPE; 2407 LOG_SCOPE;
2472 2408
2473 // get inits 2409 // get inits
2474 std::vector<LLValue*> inits(sd->fields.dim, NULL); 2410 std::vector<LLValue*> inits(sd->fields.dim, NULL);
2475 2411
2494 2430
2495 ////////////////////////////////////////////////////////////////////////////////////////// 2431 //////////////////////////////////////////////////////////////////////////////////////////
2496 2432
2497 DValue* InExp::toElem(IRState* p) 2433 DValue* InExp::toElem(IRState* p)
2498 { 2434 {
2499 Logger::print("InExp::toElem: %s | %s\n", toChars(), type->toChars()); 2435 Logger::print("InExp::toElem: %s @ %s\n", toChars(), type->toChars());
2500 LOG_SCOPE; 2436 LOG_SCOPE;
2501 2437
2502 DValue* key = e1->toElem(p); 2438 DValue* key = e1->toElem(p);
2503 DValue* aa = e2->toElem(p); 2439 DValue* aa = e2->toElem(p);
2504 2440
2520 2456
2521 ////////////////////////////////////////////////////////////////////////////////////////// 2457 //////////////////////////////////////////////////////////////////////////////////////////
2522 2458
2523 DValue* AssocArrayLiteralExp::toElem(IRState* p) 2459 DValue* AssocArrayLiteralExp::toElem(IRState* p)
2524 { 2460 {
2525 Logger::print("AssocArrayLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); 2461 Logger::print("AssocArrayLiteralExp::toElem: %s @ %s\n", toChars(), type->toChars());
2526 LOG_SCOPE; 2462 LOG_SCOPE;
2527 2463
2528 assert(keys); 2464 assert(keys);
2529 assert(values); 2465 assert(values);
2530 assert(keys->dim == values->dim); 2466 assert(keys->dim == values->dim);