summaryrefslogtreecommitdiff
path: root/mi
diff options
context:
space:
mode:
Diffstat (limited to 'mi')
-rw-r--r--mi/flatten.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/mi/flatten.c b/mi/flatten.c
index 37b59e5..aba73cd 100644
--- a/mi/flatten.c
+++ b/mi/flatten.c
@@ -277,6 +277,33 @@ flattencond(Flattenctx *s, Node *n, Node *ltrue, Node *lfalse)
}
}
+static Node*
+flattentern(Flattenctx *s, Node *n)
+{
+ Node *l1, *l2, *l3;
+ Node *res, *t;
+
+ l1 = genlbl(n->loc);
+ l2 = genlbl(n->loc);
+ l3 = genlbl(n->loc);
+
+ res = temp(s, n);
+ flattencond(s, n->expr.args[0], l1, l2);
+
+ append(s, l1);
+ t = assign(s, res, rval(s, n->expr.args[1]));
+ append(s, t);
+ jmp(s, l3);
+
+ append(s, l2);
+ t = assign(s, res, rval(s, n->expr.args[2]));
+ append(s, t);
+
+ append(s, l3);
+
+ return res;
+}
+
/* flatten
* a || b
* to
@@ -588,6 +615,9 @@ rval(Flattenctx *s, Node *n)
if (exitscope(s, NULL, Zloc, Xret))
append(s, mkexpr(n->loc, Oret, s->tret, NULL));
break;
+ case Otern:
+ r = flattentern(s, n);
+ break;
case Oasn:
r = assign(s, args[0], args[1]);
break;