scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit bc0bf0027ba8d82e645ee0b7099fa958be2eded3
parent 30f27528f11cb62062805ee9d854c1011d0933cd
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 10 May 2016 10:20:03 +0200

[cc2-qbe] Remove l and r variables in cgen()

These variables are not useful anymore after the last change
to load, because we don't keep them updated. The actuar left
and right are in np.
This way of working is generating some "memory leaks", because
some nodes become unlinked from the root, and it means that
they will not be freed until cleaning the arena.

Diffstat:
cc2/arch/qbe/cgen.c | 17+++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -245,10 +245,11 @@ abbrev(Node *np) return np->right = cgen(tmp); } +/* TODO: Fix "memory leaks" */ Node * cgen(Node *np) { - Node *l, *r, *ifyes, *ifno, *next; + Node *ifyes, *ifno, *next; Symbol *sym; Type *tp; int op, off; @@ -258,8 +259,8 @@ cgen(Node *np) return NULL; setlabel(np->label); - l = cgen(np->left); - r = cgen(np->right); + np->left = cgen(np->left); + np->right = cgen(np->right); tp = &np->type; switch (np->op) { @@ -317,7 +318,7 @@ cgen(Node *np) case OADDR: np->flags |= ISTMP; np->op = OTMP; - np->u.sym = l->u.sym; + np->u.sym = np->left->u.sym; return np; case OPTR: load(np, LOADL); @@ -331,7 +332,7 @@ cgen(Node *np) case ODEC: abort(); case OASSIG: - r = abbrev(np); + abbrev(np); switch (tp->size) { case 1: op = ASSTB; @@ -348,8 +349,8 @@ cgen(Node *np) default: abort(); } - code(op, l, r, NULL); - return r; + code(op, np->left, load(np, LOADR), NULL); + return np->right; case OCALL: case OFIELD: case OCOMMA: @@ -360,7 +361,7 @@ cgen(Node *np) abort(); case OBRANCH: next = np->next; - l = load(np, LOADL); + load(np, LOADL); if (next->label) { sym = getsym(TMPSYM); sym->kind = SLABEL;