Mercurial > projects > ddmd
comparison dmd/AssignExp.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | 1765f3ef917d |
children | e3afd1303184 |
comparison
equal
deleted
inserted
replaced
129:010eb8f0e18d | 130:60bb0fe4563e |
---|---|
3 import dmd.common; | 3 import dmd.common; |
4 import dmd.Expression; | 4 import dmd.Expression; |
5 import dmd.Identifier; | 5 import dmd.Identifier; |
6 import dmd.backend.elem; | 6 import dmd.backend.elem; |
7 import dmd.InterState; | 7 import dmd.InterState; |
8 import dmd.Argument; | 8 import dmd.Parameter; |
9 import dmd.IndexExp; | 9 import dmd.IndexExp; |
10 import dmd.CallExp; | 10 import dmd.CallExp; |
11 import dmd.CastExp; | 11 import dmd.CastExp; |
12 import dmd.TypeSArray; | 12 import dmd.TypeSArray; |
13 import dmd.StructLiteralExp; | 13 import dmd.StructLiteralExp; |
388 e2.buildArrayIdent(buf, arguments); | 388 e2.buildArrayIdent(buf, arguments); |
389 e1.buildArrayIdent(buf, arguments); | 389 e1.buildArrayIdent(buf, arguments); |
390 buf.writestring("Assign"); | 390 buf.writestring("Assign"); |
391 } | 391 } |
392 | 392 |
393 override Expression buildArrayLoop(Arguments fparams) | 393 override Expression buildArrayLoop(Parameters fparams) |
394 { | 394 { |
395 /* Evaluate assign expressions right to left | 395 /* Evaluate assign expressions right to left |
396 */ | 396 */ |
397 Expression ex2 = e2.buildArrayLoop(fparams); | 397 Expression ex2 = e2.buildArrayLoop(fparams); |
398 version (DMDV2) { | 398 version (DMDV2) { |
410 return e; | 410 return e; |
411 } | 411 } |
412 | 412 |
413 override elem* toElem(IRState* irs) | 413 override elem* toElem(IRState* irs) |
414 { | 414 { |
415 elem* e; | |
416 IndexExp ae; | |
417 int r; | |
418 Type t1b; | 415 Type t1b; |
419 | 416 |
420 //printf("AssignExp.toElem('%s')\n", toChars()); | 417 //printf("AssignExp.toElem('%s')\n", toChars()); |
421 t1b = e1.type.toBasetype(); | 418 t1b = e1.type.toBasetype(); |
422 | 419 |
425 { | 422 { |
426 // Generate: | 423 // Generate: |
427 // _d_arraysetlength(e2, sizeelem, &ale.e1); | 424 // _d_arraysetlength(e2, sizeelem, &ale.e1); |
428 | 425 |
429 ArrayLengthExp ale = cast(ArrayLengthExp)e1; | 426 ArrayLengthExp ale = cast(ArrayLengthExp)e1; |
430 elem* p1; | 427 |
431 elem* p2; | 428 auto p1 = e2.toElem(irs); |
432 elem* p3; | 429 auto p3 = ale.e1.toElem(irs); |
433 elem* ep; | |
434 Type t1; | |
435 | |
436 p1 = e2.toElem(irs); | |
437 p3 = ale.e1.toElem(irs); | |
438 p3 = addressElem(p3, null); | 430 p3 = addressElem(p3, null); |
439 t1 = ale.e1.type.toBasetype(); | 431 Type t1 = ale.e1.type.toBasetype(); |
440 | 432 |
441 static if (true) { | |
442 // call _d_arraysetlengthT(ti, e2, &ale.e1); | 433 // call _d_arraysetlengthT(ti, e2, &ale.e1); |
443 p2 = t1.getTypeInfo(null).toElem(irs); | 434 auto p2 = t1.getTypeInfo(null).toElem(irs); |
444 ep = el_params(p3, p1, p2, null); // c function | 435 auto ep = el_params(p3, p1, p2, null); // c function |
445 r = t1.nextOf().isZeroInit(Loc(0)) ? RTLSYM.RTLSYM_ARRAYSETLENGTHT : RTLSYM.RTLSYM_ARRAYSETLENGTHIT; | 436 int r = t1.nextOf().isZeroInit(Loc(0)) ? RTLSYM.RTLSYM_ARRAYSETLENGTHT : RTLSYM.RTLSYM_ARRAYSETLENGTHIT; |
446 } else { | 437 |
447 if (t1.next.isZeroInit()) | 438 auto e = el_bin(OPER.OPcall, type.totym(), el_var(rtlsym[r]), ep); |
448 { | |
449 p2 = t1.getTypeInfo(null).toElem(irs); | |
450 ep = el_params(p3, p1, p2, null); // c function | |
451 r = RTLSYM.RTLSYM_ARRAYSETLENGTHT; | |
452 } | |
453 else | |
454 { | |
455 p2 = el_long(TYM.TYint, t1.next.size()); | |
456 ep = el_params(p3, p2, p1, null); // c function | |
457 Expression init = t1.next.defaultInit(); | |
458 ep = el_param(el_long(TYM.TYint, init.type.size()), ep); | |
459 elem* ei = init.toElem(irs); | |
460 ep = el_param(ei, ep); | |
461 r = RTLSYM.RTLSYM_ARRAYSETLENGTH3; | |
462 } | |
463 } | |
464 e = el_bin(OPER.OPcall, type.totym(), el_var(rtlsym[r]), ep); | |
465 el_setLoc(e, loc); | 439 el_setLoc(e, loc); |
466 return e; | 440 return e; |
467 } | 441 } |
468 | 442 |
443 elem *e; | |
444 IndexExp ae; | |
445 | |
469 // Look for array[]=n | 446 // Look for array[]=n |
470 if (e1.op == TOK.TOKslice) | 447 if (e1.op == TOK.TOKslice) |
471 { | 448 { |
472 Type t1 = t1b; | 449 Type t1 = t1b; |
473 Type t2 = e2.type.toBasetype(); | 450 Type t2 = e2.type.toBasetype(); |
558 elem_print(n1); | 535 elem_print(n1); |
559 printf("enbytes\n"); | 536 printf("enbytes\n"); |
560 elem_print(enbytes); | 537 elem_print(enbytes); |
561 } | 538 } |
562 | 539 |
563 if (global.params.useArrayBounds && eupr && ta.ty != TY.Tpointer) | 540 if (irs.arrayBoundsCheck() && eupr && ta.ty != TY.Tpointer) |
564 { | 541 { |
565 elem *c1; | 542 elem *c1; |
566 elem *c2; | 543 elem *c2; |
567 elem *ea; | 544 elem *ea; |
568 elem *eb; | 545 elem *eb; |
649 else | 626 else |
650 { | 627 { |
651 /* It's array1[]=array2[] | 628 /* It's array1[]=array2[] |
652 * which is a memcpy | 629 * which is a memcpy |
653 */ | 630 */ |
654 elem* eto; | |
655 elem* efrom; | |
656 elem* esize; | |
657 elem* ep; | 631 elem* ep; |
658 | 632 |
659 eto = e1.toElem(irs); | 633 auto eto = e1.toElem(irs); |
660 efrom = e2.toElem(irs); | 634 auto efrom = e2.toElem(irs); |
661 | 635 |
662 uint size = cast(uint)t1.nextOf().size(); | 636 uint size = cast(uint)t1.nextOf().size(); |
663 esize = el_long(TYM.TYint, size); | 637 auto esize = el_long(TYM.TYint, size); |
664 | 638 |
665 /* Determine if we need to do postblit | 639 /* Determine if we need to do postblit |
666 */ | 640 */ |
667 int postblit = 0; | 641 int postblit = 0; |
668 if (needsPostblit(t1)) | 642 if (needsPostblit(t1)) |
669 postblit = 1; | 643 postblit = 1; |
670 | 644 |
671 assert(e2.type.ty != TY.Tpointer); | 645 assert(e2.type.ty != TY.Tpointer); |
672 | 646 |
673 if (!postblit && !global.params.useArrayBounds) | 647 if (!postblit && !irs.arrayBoundsCheck()) |
674 { | 648 { |
675 elem* epto; | 649 auto ex = el_same(&eto); |
676 elem* epfr; | |
677 elem* elen; | |
678 elem* ex; | |
679 | |
680 ex = el_same(&eto); | |
681 | 650 |
682 // Determine if elen is a constant | 651 // Determine if elen is a constant |
652 elem *elen; | |
683 if (eto.Eoper == OPER.OPpair && eto.E1.Eoper == OPER.OPconst) | 653 if (eto.Eoper == OPER.OPpair && eto.E1.Eoper == OPER.OPconst) |
684 { | 654 { |
685 elen = el_copytree(eto.E1); | 655 elen = el_copytree(eto.E1); |
686 } | 656 } |
687 else | 657 else |
689 // It's not a constant, so pull it from the dynamic array | 659 // It's not a constant, so pull it from the dynamic array |
690 elen = el_una(OPER.OP64_32, TYM.TYint, el_copytree(ex)); | 660 elen = el_una(OPER.OP64_32, TYM.TYint, el_copytree(ex)); |
691 } | 661 } |
692 | 662 |
693 esize = el_bin(OPER.OPmul, TYM.TYint, elen, esize); | 663 esize = el_bin(OPER.OPmul, TYM.TYint, elen, esize); |
694 epto = array_toPtr(e1.type, ex); | 664 auto epto = array_toPtr(e1.type, ex); |
695 epfr = array_toPtr(e2.type, efrom); | 665 auto epfr = array_toPtr(e2.type, efrom); |
696 static if (true) { | 666 static if (true) { |
697 // memcpy() is faster, so if we can't beat 'em, join 'em | 667 // memcpy() is faster, so if we can't beat 'em, join 'em |
698 e = el_params(esize, epfr, epto, null); | 668 e = el_params(esize, epfr, epto, null); |
699 e = el_bin(OPER.OPcall, TYM.TYnptr, el_var(rtlsym[RTLSYM.RTLSYM_MEMCPY]), e); | 669 e = el_bin(OPER.OPcall, TYM.TYnptr, el_var(rtlsym[RTLSYM.RTLSYM_MEMCPY]), e); |
700 } else { | 670 } else { |