LEFT | RIGHT |
(no file at all) | |
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 /* | 5 /* |
6 * portable half of code generator. | 6 * portable half of code generator. |
7 * mainly statements and control flow. | 7 * mainly statements and control flow. |
8 */ | 8 */ |
9 | 9 |
10 #include <u.h> | 10 #include <u.h> |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 ········ | 822 ········ |
823 base = temp(types[TUINTPTR]); | 823 base = temp(types[TUINTPTR]); |
824 | 824 |
825 if(isnil(n->left)) { | 825 if(isnil(n->left)) { |
826 tempname(&src, n->left->type); | 826 tempname(&src, n->left->type); |
827 cgen(n->left, &src); | 827 cgen(n->left, &src); |
828 } else | 828 } else |
829 src = *n->left; | 829 src = *n->left; |
830 if(n->op == OSLICE || n->op == OSLICE3 || n->op == OSLICESTR) | 830 if(n->op == OSLICE || n->op == OSLICE3 || n->op == OSLICESTR) |
831 src.xoffset += Array_array; | 831 src.xoffset += Array_array; |
832 src.type = types[TUINTPTR]; | |
833 | 832 |
834 if(n->op == OSLICEARR || n->op == OSLICE3ARR) { | 833 if(n->op == OSLICEARR || n->op == OSLICE3ARR) { |
835 if(!isptr[n->left->type->etype]) | 834 if(!isptr[n->left->type->etype]) |
836 fatal("slicearr is supposed to work on pointer: %+N\n",
n); | 835 fatal("slicearr is supposed to work on pointer: %+N\n",
n); |
837 cgen(&src, base); | 836 cgen(&src, base); |
838 cgen_checknil(base); | 837 cgen_checknil(base); |
839 if(offs != N) { | 838 if(offs != N) { |
840 add = nod(OADD, base, offs); | 839 add = nod(OADD, base, offs); |
841 typecheck(&add, Erv); | 840 typecheck(&add, Erv); |
842 cgen(add, base); | 841 cgen(add, base); |
843 } | 842 } |
844 } else if(offs == N) { | 843 } else if(offs == N) { |
| 844 src.type = types[tptr]; |
845 cgen(&src, base); | 845 cgen(&src, base); |
846 } else { | 846 } else { |
847 » » add = nod(OADD, &src, offs); | 847 » » src.type = types[tptr]; |
| 848 » » add = nod(OADDPTR, &src, offs); |
848 typecheck(&add, Erv); | 849 typecheck(&add, Erv); |
849 cgen(add, base); | 850 cgen(add, base); |
850 } | 851 } |
851 ········ | 852 ········ |
852 // committed to the update | 853 // committed to the update |
853 gvardef(res); | 854 gvardef(res); |
854 | 855 |
855 // dst.array = src.array [ + lo *width ] | 856 // dst.array = src.array [ + lo *width ] |
856 dst = *res; | 857 dst = *res; |
857 dst.xoffset += Array_array; | 858 dst.xoffset += Array_array; |
858 » dst.type = types[TUINTPTR]; | 859 » dst.type = types[tptr]; |
859 ········ | 860 ········ |
860 cgen(base, &dst); | 861 cgen(base, &dst); |
861 | 862 |
862 // dst.len = hi [ - lo ] | 863 // dst.len = hi [ - lo ] |
863 dst = *res; | 864 dst = *res; |
864 dst.xoffset += Array_nel; | 865 dst.xoffset += Array_nel; |
865 dst.type = types[simtype[TUINT]]; | 866 dst.type = types[simtype[TUINT]]; |
866 cgen(len, &dst); | 867 cgen(len, &dst); |
867 | 868 |
868 if(n->op != OSLICESTR) { | 869 if(n->op != OSLICESTR) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 Node* | 963 Node* |
963 temp(Type *t) | 964 temp(Type *t) |
964 { | 965 { |
965 Node *n; | 966 Node *n; |
966 ········ | 967 ········ |
967 n = nod(OXXX, N, N); | 968 n = nod(OXXX, N, N); |
968 tempname(n, t); | 969 tempname(n, t); |
969 n->sym->def->used = 1; | 970 n->sym->def->used = 1; |
970 return n->orig; | 971 return n->orig; |
971 } | 972 } |
LEFT | RIGHT |