[hackers] [scc] [cc2-qbe] Implement the . operator || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 15 Sep 2016 17:06:41 +0200 (CEST)

commit ffdf276b7cc0f7e8fabc6217e13a880768add28b
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Sep 15 16:49:35 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Sep 15 17:01:03 2016 +0200

    [cc2-qbe] Implement the . operator

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index d928451..bb5f697 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -90,7 +90,7 @@ static char opasmd[] = {
         [OCPL] = ASCPLD
 };
 
-extern Type int32type, uint32type;
+extern Type int32type, uint32type, ptrtype;
 
 static Node *
 tmpnode(Node *np, Type *tp)
_AT_@ -127,7 +127,8 @@ load(Type *tp, Node *np, Node *new)
                 op = (tp->flags & INTF) ? ASLDL : ASLDD;
                 break;
         default:
- abort();
+ *new = *np;
+ return new;
         }
         code(op, tmpnode(new, tp), np, NULL);
 
_AT_@ -278,6 +279,32 @@ assign(Type *tp, Node *to, Node *from)
         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)
 {
_AT_@ -288,6 +315,8 @@ lhs(Node *np, Node *new)
                 return np;
         case OPTR:
                 return rhs(np->left, new);
+ case OFIELD:
+ return field(np, new, 1);
         default:
                 abort();
         }
_AT_@ -508,6 +537,7 @@ rhs(Node *np, Node *ret)
         case OADDR:
                 return lhs(l, ret);
         case OFIELD:
+ return field(np, ret, 0);
         case OCASE:
         case ODEFAULT:
         case OESWITCH:
Received on Thu Sep 15 2016 - 17:06:41 CEST

This archive was generated by hypermail 2.3.0 : Thu Sep 15 2016 - 17:12:19 CEST