[hackers] [scc] [cc2] Accept a destiny pointer in constnode() || Roberto E. Vargas Caballero

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

commit 867d0a47dcf173249f4af7f191ef5e7c38d7f988
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Sep 1 17:05:41 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Sep 14 15:32:23 2016 +0200

    [cc2] Accept a destiny pointer in constnode()
    
    There are cases where we will need only temporary nodes,
    so, like we already did in functions like label2node,
    the best option is to pass a pointer and let to constnode()
    to take the decision of allocating memory or not.

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 95dfdc5..b4bf862 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -420,11 +420,11 @@ rhs(Node *np, Node *ret)
                 bool(np, true, false);
 
                 setlabel(true);
- assign(&int32type, ret, constnode(1, &int32type));
+ assign(&int32type, ret, constnode(&aux2, 1, &int32type));
                 code(ASJMP, NULL, phi, NULL);
 
                 setlabel(false);
- assign(&int32type, ret, constnode(0, &int32type));
+ assign(&int32type, ret, constnode(&aux2, 0, &int32type));
 
                 setlabel(phi->u.sym);
                 return ret;
_AT_@ -575,12 +575,12 @@ sethi(Node *np)
                 break;
         case OCPL:
                 np->op = OAND;
- rp = constnode(~(TUINT) 0, &np->type);
+ rp = constnode(NULL, ~(TUINT) 0, &np->type);
                 goto binary;
         case OSNEG:
                 np->op = OSUB;
                 rp = lp;
- lp = constnode(0, &np->type);
+ lp = constnode(NULL, 0, &np->type);
                 if ((np->type.flags & INTF) == 0)
                         lp->u.f = 0.0;
         default:
diff --git a/cc2/cc2.h b/cc2/cc2.h
index 7595276..1677c53 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -216,7 +216,8 @@ extern void writeout(void), endinit(void), newfun(void);
 extern void code(int op, Node *to, Node *from1, Node *from2);
 extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *);
 extern void setlabel(Symbol *sym), getbblocks(void);
-extern Node *label2node(Node *np, Symbol *sym), *constnode(TUINT n, Type *tp);
+extern Node *label2node(Node *np, Symbol *sym);
+extern Node *constnode(Node *np, TUINT n, Type *tp);
 extern Symbol *newlabel(void);
 
 /* node.c */
diff --git a/cc2/code.c b/cc2/code.c
index f7eba65..5a1170f 100644
--- a/cc2/code.c
+++ b/cc2/code.c
_AT_@ -83,11 +83,10 @@ label2node(Node *np, Symbol *sym)
 }
 
 Node *
-constnode(TUINT n, Type *tp)
+constnode(Node *np, TUINT n, Type *tp)
 {
- Node *np;
-
- np = newnode(OCONST);
+ if (!np)
+ np = newnode(OCONST);
         np->type = *tp;
         np->u.i = n;
         return np;
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:15 CEST