ref: 6270260b03df40c9e2230079bafbf574238acc34
parent: 5e4f828e9c606506708012a606d5fee50269a2c5
author: Ori Bernstein <[email protected]>
date: Mon Jul 23 12:38:27 EDT 2012
Ostor must ALWAYS write through the pointer. Ostor(Ovar(name), ...) will no longer write to the variable, but through it. This is needed to make indirections work. What was I smoking?
--- a/8/isel.c
+++ b/8/isel.c
@@ -334,8 +334,8 @@
}
} else {
l = selexpr(s, e);
- if (l->type == Locreg)
- l = locmem(0, l, Rnone, m);
+ l = inr(s, l);
+ l = locmem(0, l, Rnone, m);
}
return l;
}
@@ -537,6 +537,14 @@
case Oasn: /* relabel */
die("Unimplemented op %s", opstr(exprop(n)));
break;
+ case Oset:
+ assert(exprop(args[0]) == Ovar);
+ b = selexpr(s, args[1]);
+ a = selexpr(s, args[0]);
+ b = inri(s, b);
+ g(s, Imov, b, a, NULL);
+ r = b;
+ break;
case Ostor: /* reg -> mem */
b = selexpr(s, args[1]);
a = memloc(s, args[0], mode(args[0]));
@@ -545,9 +553,9 @@
r = b;
break;
case Oload: /* mem -> reg */
- b = memloc(s, args[0], mode(n));
+ a = memloc(s, args[0], mode(n));
r = locreg(mode(n));
- g(s, Imov, b, r, NULL);
+ g(s, Imov, a, r, NULL);
break;
case Ocall:
r = gencall(s, n);
--- a/8/simp.c
+++ b/8/simp.c
@@ -128,7 +128,10 @@
Node *n;
assert(a != NULL && b != NULL);
- n = mkexpr(a->line, Ostor, a, b, NULL);
+ if (exprop(a) == Ovar)
+ n = mkexpr(a->line, Oset, a, b, NULL);
+ else
+ n = mkexpr(a->line, Ostor, a, b, NULL);
return n;
}
--- a/parse/bitset.c
+++ b/parse/bitset.c
@@ -126,7 +126,7 @@
if (elt >= bs->nchunks*Sizetbits)
return 0;
else
- return bs->chunks[elt/Sizetbits] & (1ULL << (elt % Sizetbits));
+ return (bs->chunks[elt/Sizetbits] & (1ULL << (elt % Sizetbits))) != 0;
}
void bsunion(Bitset *a, Bitset *b)
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -656,7 +656,7 @@
case Olbl: /* :lbl -> void* */
settype(st, n, mktyptr(n->line, mkty(-1, Tyvoid)));
case Obad: case Ocjmp:
- case Oload: case Ostor:
+ case Oload: case Ostor: case Oset:
case Oslbase: case Osllen:
case Oblit: case Numops:
die("Should not see %s in fe", opstr(exprop(n)));
--- a/parse/ops.def
+++ b/parse/ops.def
@@ -54,7 +54,8 @@
/* backend-only */
O(Ocjmp, 1) /* conditional jump */
O(Oload, 1) /* load from memory */
-O(Ostor, 1) /* store to memory */
+O(Ostor, 1) /* store through to memory */
+O(Oset, 1) /* store to var */
O(Osllen, 1) /* size of slice */
O(Oslbase, 1) /* base of sice */
O(Oblit, 1) /* block copy of memory */