ref: 7c88dc7a0c96e24b53b0aeea66d74b3a757be2d4
parent: c405c48a66cc5a7eeb192db81d42c08da2b19d73
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Feb 12 07:44:10 EST 2015
Add assign operation in cc2 This is a basic implementation, that only implements byte assignments. It will be expanded later.
--- a/cc2/cgen.c
+++ b/cc2/cgen.c
@@ -104,14 +104,16 @@
lp = np->left;
rp = np->right;
if (np->addable >= ADDABLE) {
+ if (parent && parent->op == OASSIG)
+ return;
move(np);
return;
}
if (!lp) {
- cgen(rp);
+ cgen(rp, np);
} else if (!rp) {
- cgen(lp);
+ cgen(lp, np);
} else {
Node *p, *q;
if (lp->complex > rp->complex)
@@ -118,8 +120,8 @@
p = lp, q = rp;
else
p = rp, q = lp;
- cgen(p);
- cgen(q);
+ cgen(p, np);
+ cgen(q, np);
}
switch (np->op) {
@@ -149,9 +151,28 @@
code(LD, L, lower[lp->u.reg]);
}
code(ADD, lp->u.reg, rp->u.reg);
+ np->op = REG;
+ np->u.reg = lp->u.reg;
break;
case 4:
case 8:
+ abort();
+ }
+ break;
+ case OASSIG:
+ switch (np->type->size) {
+ case 1:
+ switch (lp->op) {
+ case AUTO:
+ code(LDX, IX, lp->u.sym->u.v.off, rp->u.reg);
+ break;
+ case REG:
+ case MEM:
+ default:
+ abort();
+ }
+ break;
+ default:
abort();
}
break;