summaryrefslogtreecommitdiff
path: root/src/cmd/8g/cgen.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/8g/cgen.c')
-rw-r--r--src/cmd/8g/cgen.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/cmd/8g/cgen.c b/src/cmd/8g/cgen.c
index b316e6e34..48619ac73 100644
--- a/src/cmd/8g/cgen.c
+++ b/src/cmd/8g/cgen.c
@@ -5,6 +5,8 @@
// TODO(rsc):
// assume CLD?
+#include <u.h>
+#include <libc.h>
#include "gg.h"
void
@@ -96,6 +98,9 @@ cgen(Node *n, Node *res)
if(isslice(n->left->type))
n->addable = n->left->addable;
break;
+ case OITAB:
+ n->addable = n->left->addable;
+ break;
}
// if both are addressable, move
@@ -250,6 +255,13 @@ cgen(Node *n, Node *res)
regfree(&n1);
break;
+ case OITAB:
+ igen(nl, &n1, res);
+ n1.type = ptrto(types[TUINTPTR]);
+ gmove(&n1, res);
+ regfree(&n1);
+ break;
+
case OLEN:
if(istype(nl->type, TMAP) || istype(nl->type, TCHAN)) {
// map has len in the first 32-bit word.
@@ -680,7 +692,6 @@ agen(Node *n, Node *res)
break;
case ODOT:
- t = nl->type;
agen(nl, res);
if(n->xoffset != 0) {
nodconst(&n1, types[tptr], n->xoffset);
@@ -786,6 +797,7 @@ bgen(Node *n, int true, Prog *to)
int et, a;
Node *nl, *nr, *r;
Node n1, n2, tmp, t1, t2, ax;
+ NodeList *ll;
Prog *p1, *p2;
if(debug['g']) {
@@ -798,9 +810,6 @@ bgen(Node *n, int true, Prog *to)
if(n->ninit != nil)
genlist(n->ninit);
- nl = n->left;
- nr = n->right;
-
if(n->type == T) {
convlit(&n, types[TBOOL]);
if(n->type == T)
@@ -813,7 +822,6 @@ bgen(Node *n, int true, Prog *to)
patch(gins(AEND, N, N), to);
return;
}
- nl = N;
nr = N;
switch(n->op) {
@@ -905,7 +913,10 @@ bgen(Node *n, int true, Prog *to)
p1 = gbranch(AJMP, T);
p2 = gbranch(AJMP, T);
patch(p1, pc);
+ ll = n->ninit; // avoid re-genning ninit
+ n->ninit = nil;
bgen(n, 1, p2);
+ n->ninit = ll;
patch(gbranch(AJMP, T), to);
patch(p2, pc);
break;
@@ -1129,24 +1140,29 @@ stkof(Node *n)
* memmove(&res, &n, w);
*/
void
-sgen(Node *n, Node *res, int32 w)
+sgen(Node *n, Node *res, int64 w)
{
Node dst, src, tdst, tsrc;
int32 c, q, odst, osrc;
if(debug['g']) {
- print("\nsgen w=%d\n", w);
+ print("\nsgen w=%lld\n", w);
dump("r", n);
dump("res", res);
}
- if(w == 0)
- return;
- if(n->ullman >= UINF && res->ullman >= UINF) {
+ if(n->ullman >= UINF && res->ullman >= UINF)
fatal("sgen UINF");
- }
- if(w < 0)
- fatal("sgen copy %d", w);
+ if(w < 0 || (int32)w != w)
+ fatal("sgen copy %lld", w);
+
+ if(w == 0) {
+ // evaluate side effects only.
+ tempname(&tdst, types[tptr]);
+ agen(res, &tdst);
+ agen(n, &tdst);
+ return;
+ }
// offset on the stack
osrc = stkof(n);