ref: 359e72e4eb64218746f39b969a6a75b4d83ff9c7
parent: 0860ef11851c91d24450bafb7d57b539f5dbc87d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Sep 15 12:49:35 EDT 2016
[cc2-qbe] Implement the . operator
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -90,7 +90,7 @@
[OCPL] = ASCPLD
};
-extern Type int32type, uint32type;
+extern Type int32type, uint32type, ptrtype;
static Node *
tmpnode(Node *np, Type *tp)
@@ -127,7 +127,8 @@
op = (tp->flags & INTF) ? ASLDL : ASLDD;
break;
default:
- abort();
+ *new = *np;
+ return new;
}
code(op, tmpnode(new, tp), np, NULL);
@@ -278,7 +279,33 @@
return from;
}
+/* TODO: Do field() transformation in sethi */
+
static Node *
+field(Node *np, Node *ret, int islhs)
+{
+ Node base, node, off, add, *addr;
+ TUINT offset = np->right->u.sym->u.off;
+
+ addr = rhs(np->left, &base);
+
+ if (offset != 0) {
+ node.op = OADD;
+ node.type = ptrtype;
+ node.left = addr;
+ node.right = constnode(&off, offset, &ptrtype);
+ addr = rhs(&node, &add);
+ }
+
+ if (islhs)
+ *ret = *addr;
+ else
+ load(&np->type, addr, ret);
+
+ return ret;
+}
+
+static Node *
lhs(Node *np, Node *new)
{
switch (np->op) {
@@ -288,6 +315,8 @@
return np;
case OPTR:
return rhs(np->left, new);
+ case OFIELD:
+ return field(np, new, 1);
default:
abort();
}
@@ -508,6 +537,7 @@
case OADDR:
return lhs(l, ret);
case OFIELD:
+ return field(np, ret, 0);
case OCASE:
case ODEFAULT:
case OESWITCH: