Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include <u.h> | 5 #include <u.h> |
6 #include <libc.h> | 6 #include <libc.h> |
7 #include "gg.h" | 7 #include "gg.h" |
8 | 8 |
9 /* | 9 /* |
10 * generate: | 10 * generate: |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 | 552 |
553 /* | 553 /* |
554 * generate: | 554 * generate: |
555 * res = &n; | 555 * res = &n; |
556 */ | 556 */ |
557 void | 557 void |
558 agen(Node *n, Node *res) | 558 agen(Node *n, Node *res) |
559 { | 559 { |
560 Node *nl; | 560 Node *nl; |
561 Node n1, n2, n3; | 561 Node n1, n2, n3; |
562 Prog *p1; | |
563 int r; | 562 int r; |
564 | 563 |
565 if(debug['g']) { | 564 if(debug['g']) { |
566 dump("\nagen-res", res); | 565 dump("\nagen-res", res); |
567 dump("agen-r", n); | 566 dump("agen-r", n); |
568 } | 567 } |
569 if(n == N || n->type == T || res == N || res->type == T) | 568 if(n == N || n->type == T || res == N || res->type == T) |
570 fatal("agen"); | 569 fatal("agen"); |
571 | 570 |
572 while(n->op == OCONVNOP) | 571 while(n->op == OCONVNOP) |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 break; | 696 break; |
698 | 697 |
699 case ODOTPTR: | 698 case ODOTPTR: |
700 cgen(nl, res); | 699 cgen(nl, res); |
701 if(n->xoffset != 0) { | 700 if(n->xoffset != 0) { |
702 // explicit check for nil if struct is large enough | 701 // explicit check for nil if struct is large enough |
703 // that we might derive too big a pointer. | 702 // that we might derive too big a pointer. |
704 if(nl->type->type->width >= unmappedzero) { | 703 if(nl->type->type->width >= unmappedzero) { |
705 regalloc(&n1, types[tptr], N); | 704 regalloc(&n1, types[tptr], N); |
706 gmove(res, &n1); | 705 gmove(res, &n1); |
707 » » » » p1 = gins(AMOVW, &n1, &n1); | 706 » » » » regalloc(&n2, types[TUINT8], &n1); |
708 » » » » p1->from.type = D_OREG; | 707 » » » » n2.op = OINDREG; |
remyoudompheng
2012/12/04 11:12:41
s/n2/n1 on these three lines
dfc
2012/12/04 11:17:54
Done.
| |
709 » » » » p1->from.offset = 0; | 708 » » » » n2.type = types[TUINT8]; |
709 » » » » n2.xoffset = 0; | |
710 » » » » gmove(&n1, &n2); | |
remyoudompheng
2012/12/04 11:12:41
you are doing
MOVBU Rn, 0(Rn)
here, I suppose i
dfc
2012/12/04 11:17:54
Whoops.
| |
710 regfree(&n1); | 711 regfree(&n1); |
712 regfree(&n2); | |
711 } | 713 } |
712 nodconst(&n1, types[TINT32], n->xoffset); | 714 nodconst(&n1, types[TINT32], n->xoffset); |
713 regalloc(&n2, n1.type, N); | 715 regalloc(&n2, n1.type, N); |
714 regalloc(&n3, types[tptr], N); | 716 regalloc(&n3, types[tptr], N); |
715 gmove(&n1, &n2); | 717 gmove(&n1, &n2); |
716 gmove(res, &n3); | 718 gmove(res, &n3); |
717 gins(optoas(OADD, types[tptr]), &n2, &n3); | 719 gins(optoas(OADD, types[tptr]), &n2, &n3); |
718 gmove(&n3, res); | 720 gmove(&n3, res); |
719 regfree(&n2); | 721 regfree(&n2); |
720 regfree(&n3); | 722 regfree(&n3); |
721 } | 723 } |
722 break; | 724 break; |
723 } | 725 } |
724 | 726 |
725 ret: | 727 ret: |
726 ; | 728 ; |
727 } | 729 } |
728 | 730 |
729 /* | 731 /* |
730 * generate: | 732 * generate: |
731 * newreg = &n; | 733 * newreg = &n; |
732 * res = newreg | 734 * res = newreg |
733 * | 735 * |
734 * on exit, a has been changed to be *newreg. | 736 * on exit, a has been changed to be *newreg. |
735 * caller must regfree(a). | 737 * caller must regfree(a). |
736 */ | 738 */ |
737 void | 739 void |
738 igen(Node *n, Node *a, Node *res) | 740 igen(Node *n, Node *a, Node *res) |
739 { | 741 { |
740 » Node n1; | 742 » Node n1, n2; |
741 » Prog *p1; | |
742 int r; | 743 int r; |
743 | 744 |
744 if(debug['g']) { | 745 if(debug['g']) { |
745 dump("\nigen-n", n); | 746 dump("\nigen-n", n); |
746 } | 747 } |
747 switch(n->op) { | 748 switch(n->op) { |
748 case ONAME: | 749 case ONAME: |
749 if((n->class&PHEAP) || n->class == PPARAMREF) | 750 if((n->class&PHEAP) || n->class == PPARAMREF) |
750 break; | 751 break; |
751 *a = *n; | 752 *a = *n; |
(...skipping 26 matching lines...) Expand all Loading... | |
778 } else { | 779 } else { |
779 regalloc(a, types[tptr], res); | 780 regalloc(a, types[tptr], res); |
780 cgen(n->left, a); | 781 cgen(n->left, a); |
781 } | 782 } |
782 if(n->xoffset != 0) { | 783 if(n->xoffset != 0) { |
783 // explicit check for nil if struct is large enough | 784 // explicit check for nil if struct is large enough |
784 // that we might derive too big a pointer. | 785 // that we might derive too big a pointer. |
785 if(n->left->type->type->width >= unmappedzero) { | 786 if(n->left->type->type->width >= unmappedzero) { |
786 regalloc(&n1, types[tptr], N); | 787 regalloc(&n1, types[tptr], N); |
787 gmove(a, &n1); | 788 gmove(a, &n1); |
788 » » » » p1 = gins(AMOVW, &n1, &n1); | 789 » » » » regalloc(&n2, types[TUINT8], &n1); |
789 » » » » p1->from.type = D_OREG; | 790 » » » » n2.op = OINDREG; |
remyoudompheng
2012/12/04 11:12:41
s/n2/n1 on these 3 lines
dfc
2012/12/04 11:17:54
Done.
| |
790 » » » » p1->from.offset = 0; | 791 » » » » n2.type = types[TUINT8]; |
792 » » » » n2.xoffset = 0; | |
793 » » » » gmove(&n1, &n2); | |
remyoudompheng
2012/12/04 11:12:41
same
dfc
2012/12/04 11:17:54
Done.
| |
791 regfree(&n1); | 794 regfree(&n1); |
795 regfree(&n2); | |
792 } | 796 } |
793 } | 797 } |
794 a->op = OINDREG; | 798 a->op = OINDREG; |
795 a->xoffset = n->xoffset; | 799 a->xoffset = n->xoffset; |
796 a->type = n->type; | 800 a->type = n->type; |
797 return; | 801 return; |
798 | 802 |
799 case OCALLMETH: | 803 case OCALLMETH: |
800 case OCALLFUNC: | 804 case OCALLFUNC: |
801 case OCALLINTER: | 805 case OCALLINTER: |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
950 | 954 |
951 // &a is in &n3 (allocated in res) | 955 // &a is in &n3 (allocated in res) |
952 // i is in &n1 (if not constant) | 956 // i is in &n1 (if not constant) |
953 // w is width | 957 // w is width |
954 | 958 |
955 // explicit check for nil if array is large enough | 959 // explicit check for nil if array is large enough |
956 // that we might derive too big a pointer. | 960 // that we might derive too big a pointer. |
957 if(isfixedarray(nl->type) && nl->type->width >= unmappedzero) { | 961 if(isfixedarray(nl->type) && nl->type->width >= unmappedzero) { |
958 regalloc(&n4, types[tptr], N); | 962 regalloc(&n4, types[tptr], N); |
959 gmove(&n3, &n4); | 963 gmove(&n3, &n4); |
960 » » » p1 = gins(AMOVW, &n4, &n4); | 964 » » » regalloc(&tmp, types[TUINT8], &n4); |
961 » » » p1->from.type = D_OREG; | 965 » » » n4.op = OINDREG; |
962 » » » p1->from.offset = 0; | 966 » » » n4.type = types[TUINT8]; |
967 » » » n4.xoffset = 0; | |
968 » » » gmove(&n4, &tmp); | |
remyoudompheng
2012/12/04 11:12:41
this one is OK
| |
963 regfree(&n4); | 969 regfree(&n4); |
970 regfree(&tmp); | |
964 } | 971 } |
965 | 972 |
966 // constant index | 973 // constant index |
967 if(isconst(nr, CTINT)) { | 974 if(isconst(nr, CTINT)) { |
968 if(isconst(nl, CTSTR)) | 975 if(isconst(nl, CTSTR)) |
969 fatal("constant string constant index"); | 976 fatal("constant string constant index"); |
970 v = mpgetfix(nr->val.u.xval); | 977 v = mpgetfix(nr->val.u.xval); |
971 if(isslice(nl->type) || nl->type->etype == TSTRING) { | 978 if(isslice(nl->type) || nl->type->etype == TSTRING) { |
972 if(!debug['B'] && !n->bounded) { | 979 if(!debug['B'] && !n->bounded) { |
973 n1 = n3; | 980 n1 = n3; |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1706 regfree(&nodl); | 1713 regfree(&nodl); |
1707 return 0; | 1714 return 0; |
1708 | 1715 |
1709 yes: | 1716 yes: |
1710 if(freer) | 1717 if(freer) |
1711 regfree(&nodr); | 1718 regfree(&nodr); |
1712 if(freel) | 1719 if(freel) |
1713 regfree(&nodl); | 1720 regfree(&nodl); |
1714 return 1; | 1721 return 1; |
1715 } | 1722 } |
OLD | NEW |