[hackers] [scc] [cc2-qbe] Move statements ops to cgen || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 12 Jul 2016 11:58:57 +0200 (CEST)

commit 0bf0065e998d253224445d4e04ba75f072ade165
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Jul 12 11:56:05 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Jul 12 11:56:05 2016 +0200

    [cc2-qbe] Move statements ops to cgen
    
    This makes the code more orthogonal, because we do not have
    to worry about the case of ret with or without expression.

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 1eb0997..d87bc41 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -106,6 +106,7 @@ static Node *
 bool(Node *np, Node *new, Symbol *true, Symbol *false)
 {
         Node *l = np->left, *r = np->right;
+ Node *ifyes, *ifno;
         Symbol *label;
 
         switch (np->op) {
_AT_@ -122,8 +123,12 @@ bool(Node *np, Node *new, Symbol *true, Symbol *false)
                 bool(r, new, true, false);
                 break;
         default:
- rhs(np, new);
- code(ASBRANCH, new, label2node(true), label2node(false));
+ ifyes = label2node(true);
+ ifno = label2node(false);
+ rhs(l, new);
+ code(ASBRANCH, new, ifyes, ifno);
+ deltree(ifyes);
+ deltree(ifno);
                 break;
         }
         return new;
_AT_@ -157,7 +162,6 @@ static Node *
 rhs(Node *np, Node *new)
 {
         Node aux;
- Symbol *label1, *label2;
 
         switch (np->op) {
         case OBFUN:
_AT_@ -167,14 +171,6 @@ rhs(Node *np, Node *new)
         case OMEM:
         case OAUTO:
                 return load(np, new);
- case OJMP:
- case OBRANCH:
- case ORET:
- label1 = newlabel();
- label2 = newlabel();
- bool(np, new, label1, label2);
- setlabel(label1);
- return NULL;
         case OASSIG:
                 lhs(np->left, new);
                 rhs(np->right, &aux);
_AT_@ -188,9 +184,23 @@ rhs(Node *np, Node *new)
 Node *
 cgen(Node *np)
 {
- Node n;
+ Node n, *aux;
+ Symbol *label1, *label2;
 
- rhs(np, &n);
+ switch (np->op) {
+ case OJMP:
+ code(ASJMP, NULL, NULL, NULL);
+ break;
+ case OBRANCH:
+ break;
+ case ORET:
+ aux = (np->left) ? rhs(np->left, &n) : NULL;
+ code(ASRET, aux, NULL, NULL);
+ break;
+ default:
+ rhs(np, &n);
+ break;
+ }
         return NULL;
 }
 
Received on Tue Jul 12 2016 - 11:58:57 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 12 2016 - 12:00:17 CEST