[hackers] [scc/qbe] [cc2-qbe] Add support for OOR and change n to ret || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 12 Aug 2016 11:18:01 +0200 (CEST)

commit 3f64cb4dcdcb644d411961c445f7899e1d0c61b2
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Aug 12 11:14:10 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Aug 12 11:14:10 2016 +0200

    [cc2-qbe] Add support for OOR and change n to ret
    
    This is a basic support for OOR, which is not totally
    functional, but it improves the current state. There is
    also a change in the name of the variable n, which
    was a not very significative name.

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index e360c77..5e39694 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -90,6 +90,8 @@ static char opasmd[] = {
         [OCPL] = ASCPLD
 };
 
+extern Type int32type;
+
 static Node *
 tmpnode(Node *np)
 {
_AT_@ -235,7 +237,7 @@ function(void)
 static Node *
 rhs(Node *np, Node *ret)
 {
- Node aux1, aux2, *l = np->left, *r = np->right;
+ Node aux1, aux2, *phi, *l = np->left, *r = np->right;
         Type *tp;
         int off, op;
         char *tbl;
_AT_@ -257,9 +259,20 @@ rhs(Node *np, Node *ret)
         case OOR:
                 true = newlabel();
                 false = newlabel();
+ phi = label2node(newlabel());
+ tmpnode(ret);
+
                 bool(np, true, false);
+
                 setlabel(true);
+ assign(ret, constnode(1, &int32type));
+ code(ASJMP, NULL, phi, NULL);
+
                 setlabel(false);
+ assign(ret, constnode(0, &int32type));
+
+ setlabel(phi->u.sym);
+ deltree(phi);
                 return ret;
         case OSHR:
         case OMOD:
_AT_@ -319,8 +332,7 @@ rhs(Node *np, Node *ret)
 Node *
 cgen(Node *np)
 {
- Node n, *aux, *next, *ifyes, *ifno;
- Symbol *label1, *label2;
+ Node ret, *aux, *next, *phi, *ifyes, *ifno;
 
         setlabel(np->label);
         switch (np->op) {
_AT_@ -333,21 +345,20 @@ cgen(Node *np)
                 next = np->next;
                 if (!next->label)
                         next->label = newlabel();
+
                 ifyes = label2node(np->u.sym);
                 ifno = label2node(next->label);
- bool(np->left, ifyes->u.sym, ifno->u.sym);
- code(ASBRANCH, &n, ifyes, ifno);
- setlabel(ifyes->u.sym);
- setlabel(ifno->u.sym);
+ rhs(np->left, &ret);
+ code(ASBRANCH, &ret, ifyes, ifno);
                 deltree(ifyes);
                 deltree(ifno);
                 break;
         case ORET:
- aux = (np->left) ? rhs(np->left, &n) : NULL;
- code(ASRET, aux, NULL, NULL);
+ aux = (np->left) ? rhs(np->left, &ret) : NULL;
+ code(ASRET, NULL, aux, NULL);
                 break;
         default:
- rhs(np, &n);
+ rhs(np, &ret);
                 break;
         }
         return NULL;
Received on Fri Aug 12 2016 - 11:18:01 CEST

This archive was generated by hypermail 2.3.0 : Fri Aug 12 2016 - 11:24:27 CEST