[hackers] [scc/qbe] [cc2-qbe] Add ternary() || Roberto E. Vargas Caballero
commit 8dc4c07f1f609644988ce825cf6d62b29d420517
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Aug 16 09:10:13 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Aug 17 14:29:25 2016 +0200
[cc2-qbe] Add ternary()
This code is directly taken and adapted from the old
cgen for qbe.
diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 3e509eb..efed0ab 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -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;
_AT_@ -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();
}
Received on Wed Aug 17 2016 - 14:29:50 CEST
This archive was generated by hypermail 2.3.0
: Wed Aug 17 2016 - 14:36:50 CEST