scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 867d0a47dcf173249f4af7f191ef5e7c38d7f988
parent ebe3fa641b06cbc0602f87439d8918d997260a17
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  1 Sep 2016 17:05:41 +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.

Diffstat:
Mcc2/arch/qbe/cgen.c | 8++++----
Mcc2/cc2.h | 3++-
Mcc2/code.c | 7+++----
3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -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; @@ -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 @@ -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 @@ -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;