scc

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

commit 0bf0065e998d253224445d4e04ba75f072ade165
parent a0b3a0df6a6a6ff2c2e5cdc190428bb5e1e47f4c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 12 Jul 2016 11:56:05 +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.

Diffstat:
Mcc2/arch/qbe/cgen.c | 36+++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -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) { @@ -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; @@ -157,7 +162,6 @@ static Node * rhs(Node *np, Node *new) { Node aux; - Symbol *label1, *label2; switch (np->op) { case OBFUN: @@ -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); @@ -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; }