ref: 3cea2cc045613d03524b69dc7b5a116105c54202
parent: 2573b7fab4e3a73d0de572bcf3f23bfcfd76f83e
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Aug 16 05:10:13 EDT 2016
[cc2-qbe] Add ternary() This code is directly taken and adapted from the old cgen for qbe.
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -350,6 +350,34 @@
}
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 @@
lhs(l, &aux2);
rhs(r, ret);
return assign(&aux2, ret);
+ case OASK:
+ return ternary(np, ret);
default:
abort();
}