ref: 81272f61a868aa2d047c2620191b88d4fe9769bd
parent: a107efa5686c6b4526e202609057600d2543550f
author: Michael Forney <[email protected]>
date: Fri Feb 17 06:08:26 EST 2017
[cc2-qbe] Fix generated qbe for ternary expressions
--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -141,7 +141,13 @@
ASALLOC,
ASFORM,
+ ASCOPYB,
+ ASCOPYH,
ASCOPYW,
+ ASCOPYL,
+ ASCOPYS,
+ ASCOPYD,
+
ASVSTAR,
ASVARG,
};
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -280,6 +280,32 @@
return from;
}
+static Node *
+copy(Type *tp, Node *to, Node *from)
+{
+ int op;
+
+ switch (tp->size) {
+ case 1:
+ op = ASCOPYB;
+ break;
+ case 2:
+ op = ASCOPYH;
+ break;
+ case 4:
+ op = (tp->flags & FLOATF) ? ASCOPYS : ASCOPYW;
+ break;
+ case 8:
+ op = (tp->flags & FLOATF) ? ASCOPYD : ASCOPYL;
+ break;
+ default:
+ /* TODO: Need to handle the general case */
+ abort();
+ }
+ code(op, to, from, NULL);
+ return from;
+}
+
/* TODO: Do field() transformation in sethi */
static Node *
@@ -368,11 +394,11 @@
code(ASBRANCH, rhs(np->left, &aux1), &ifyes, &ifno);
setlabel(ifyes.u.sym);
- assign(&ret->type, ret, rhs(colon->left, &aux2));
+ copy(&ret->type, ret, rhs(colon->left, &aux2));
code(ASJMP, NULL, &phi, NULL);
setlabel(ifno.u.sym);
- assign(&ret->type, ret, rhs(colon->right, &aux3));
+ copy(&ret->type, ret, rhs(colon->right, &aux3));
setlabel(phi.u.sym);
return ret;
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -32,7 +32,12 @@
[ASLDS] = {.fun = unary, .txt = "loads", .letter = 's'},
[ASLDD] = {.fun = unary, .txt = "loadd", .letter = 'd'},
+ [ASCOPYB] = {.fun = unary, .txt = "copy", .letter = 'b'},
+ [ASCOPYH] = {.fun = unary, .txt = "copy", .letter = 'h'},
[ASCOPYW] = {.fun = unary, .txt = "copy", .letter = 'w'},
+ [ASCOPYL] = {.fun = unary, .txt = "copy", .letter = 'l'},
+ [ASCOPYS] = {.fun = unary, .txt = "copy", .letter = 's'},
+ [ASCOPYD] = {.fun = unary, .txt = "copy", .letter = 'd'},
[ASSTB] = {.fun = store, .txt = "store", .letter = 'b'},
[ASSTH] = {.fun = store, .txt = "store", .letter = 'h'},
--- /dev/null
+++ b/tests/execute/0112-cond.c
@@ -1,0 +1,11 @@
+int
+main()
+{
+ int x = 0;
+ int y = 1;
+ if(x ? 1 : 0)
+ return 1;
+ if(y ? 0 : 1)
+ return 2;
+ return 0;
+}
--- a/tests/execute/scc-tests.lst
+++ b/tests/execute/scc-tests.lst
@@ -102,3 +102,4 @@
0109-struct.c
0110-typedefcast.c
0111-doubledef.c
+0112-cond.c