[hackers] [scc] [cc2-qbe] Add OINC and ODEC || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 14 Sep 2016 15:32:31 +0200 (CEST)

commit e062187973bf14214d5917be3ec9b70fa0f68d9f
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Sep 14 14:58:43 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Sep 14 15:32:23 2016 +0200

    [cc2-qbe] Add OINC and ODEC
    
    These are special cases of abbreviatures and they need special dealing.

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index b4bf862..d928451 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -254,17 +254,6 @@ call(Node *np, Node *ret)
 }
 
 static Node *
-abbrev(Node *np, Node *ret)
-{
- Node aux;
-
- tmpnode(&aux, &np->type);
- aux.right = np->right;
- aux.left = np->left;
- return rhs(&aux, ret);
-}
-
-static Node *
 assign(Type *tp, Node *to, Node *from)
 {
         int op;
_AT_@ -403,6 +392,7 @@ rhs(Node *np, Node *ret)
         case OELOOP:
         case OEFUN:
                 return NULL;
+ case OTMP:
         case OCONST:
                 *ret = *np;
                 return np;
_AT_@ -480,12 +470,35 @@ rhs(Node *np, Node *ret)
         case OCAST:
                 return cast(tp, rhs(l, &aux1), ret);
         case OASSIG:
- /* TODO: see what is the more difficult */
- if (np->u.subop != 0)
- r = abbrev(np, &aux1);
- lhs(l, &aux2);
- rhs(r, ret);
- return assign(&np->type, &aux2, ret);
+ /* TODO: Do this transformations in sethi */
+ switch (np->u.subop) {
+ case OINC:
+ op = OADD;
+ goto post_oper;
+ case ODEC:
+ op = OSUB;
+ post_oper:
+ aux1.op = op;
+ aux1.left = rhs(l, ret);
+ aux1.right = r;
+ aux1.type = np->type;
+ rhs(&aux1, &aux2);
+ lhs(l, &aux1);
+ assign(tp, &aux1, &aux2);
+ break;
+ default:
+ aux2.type = np->type;
+ aux2.op = np->u.subop;
+ aux2.right = np->right;
+ aux2.left = np->left;
+ r = rhs(&aux2, &aux1);
+ case 0:
+ /* TODO: see what is the most difficult */
+ lhs(l, &aux2);
+ rhs(r, ret);
+ return assign(tp, &aux2, ret);
+ }
+ return ret;
         case OASK:
                 return ternary(np, ret);
         case OCOMMA:
_AT_@ -495,8 +508,6 @@ rhs(Node *np, Node *ret)
         case OADDR:
                 return lhs(l, ret);
         case OFIELD:
- case OINC:
- case ODEC:
         case OCASE:
         case ODEFAULT:
         case OESWITCH:
diff --git a/cc2/parser.c b/cc2/parser.c
index 778e516..d616ff7 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
_AT_@ -129,6 +129,8 @@ static struct decoc {
         ['j'] = { NULL, jump, .u.op = OJMP},
         ['y'] = { NULL, jump, .u.op = OBRANCH},
         ['h'] = { NULL, oreturn, .u.op = ORET},
+ ['i'] = { NULL, NULL, .u.op = OINC},
+ ['d'] = { NULL, NULL, .u.op = ODEC},
 
         ['b'] = { NULL, loop, .u.op = OBLOOP},
         ['e'] = { NULL, loop, .u.op = OELOOP},
Received on Wed Sep 14 2016 - 15:32:31 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 14 2016 - 15:36:22 CEST