ref: 60f81e0f0e9e2d5e1ef3a7c2bbfbe6f288f989f6
parent: 2e59984d40758e4d4a04f1e21c223a3361f21b0e
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Aug 12 07:14:10 EDT 2016
[cc2-qbe] Add support for OOR and change n to ret This is a basic support for OOR, which is not totally functional, but it improves the current state. There is also a change in the name of the variable n, which was a not very significative name.
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -90,6 +90,8 @@
[OCPL] = ASCPLD
};
+extern Type int32type;
+
static Node *
tmpnode(Node *np)
{
@@ -235,7 +237,7 @@
static Node *
rhs(Node *np, Node *ret)
{
- Node aux1, aux2, *l = np->left, *r = np->right;
+ Node aux1, aux2, *phi, *l = np->left, *r = np->right;
Type *tp;
int off, op;
char *tbl;
@@ -257,9 +259,20 @@
case OOR:
true = newlabel();
false = newlabel();
+ phi = label2node(newlabel());
+ tmpnode(ret);
+
bool(np, true, false);
+
setlabel(true);
+ assign(ret, constnode(1, &int32type));
+ code(ASJMP, NULL, phi, NULL);
+
setlabel(false);
+ assign(ret, constnode(0, &int32type));
+
+ setlabel(phi->u.sym);
+ deltree(phi);
return ret;
case OSHR:
case OMOD:
@@ -319,8 +332,7 @@
Node *
cgen(Node *np)
{
- Node n, *aux, *next, *ifyes, *ifno;
- Symbol *label1, *label2;
+ Node ret, *aux, *next, *phi, *ifyes, *ifno;
setlabel(np->label);
switch (np->op) {
@@ -333,21 +345,20 @@
next = np->next;
if (!next->label)
next->label = newlabel();
+
ifyes = label2node(np->u.sym);
ifno = label2node(next->label);
- bool(np->left, ifyes->u.sym, ifno->u.sym);
- code(ASBRANCH, &n, ifyes, ifno);
- setlabel(ifyes->u.sym);
- setlabel(ifno->u.sym);
+ rhs(np->left, &ret);
+ code(ASBRANCH, &ret, ifyes, ifno);
deltree(ifyes);
deltree(ifno);
break;
case ORET:
- aux = (np->left) ? rhs(np->left, &n) : NULL;
- code(ASRET, aux, NULL, NULL);
+ aux = (np->left) ? rhs(np->left, &ret) : NULL;
+ code(ASRET, NULL, aux, NULL);
break;
default:
- rhs(np, &n);
+ rhs(np, &ret);
break;
}
return NULL;