scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 8dc4c07f1f609644988ce825cf6d62b29d420517
parent 7843ca2e4e10e7b485b6de0b406bd702ff4a28a4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 16 Aug 2016 09:10:13 +0200

[cc2-qbe] Add ternary()

This code is directly taken and adapted from the old
cgen for qbe.

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

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -350,6 +350,34 @@ bool(Node *np, Symbol *true, Symbol *false) } static Node * +ternary(Node *np, Node *ret) +{ + Node *yes, *no, *phi, *colon, aux1, aux2, aux3; + + tmpnode(ret, &np->type); + yes = label2node(NULL); + no = label2node(NULL); + phi = label2node(NULL); + + colon = np->right; + code(ASBRANCH, rhs(np->left, &aux1), yes, no); + + setlabel(yes->u.sym); + assign(ret, rhs(colon->left, &aux2)); + code(ASJMP, NULL, phi, NULL); + + setlabel(no->u.sym); + assign(ret, rhs(colon->right, &aux3)); + setlabel(phi->u.sym); + + deltree(yes); + deltree(no); + deltree(phi); + + return ret; +} + +static Node * function(void) { Symbol *p; @@ -470,6 +498,8 @@ rhs(Node *np, Node *ret) lhs(l, &aux2); rhs(r, ret); return assign(&aux2, ret); + case OASK: + return ternary(np, ret); default: abort(); }